@conscience-technology/ovenn 0.7.3 → 0.7.5
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/assets/components/AIMessage/AIMessage.module.css +10 -0
- package/assets/components/AIMessage/AIMessage.tsx +6 -2
- package/assets/components/Breadcrumb/Breadcrumb.module.css +82 -23
- package/assets/components/Breadcrumb/Breadcrumb.tsx +44 -26
- package/assets/components/Breadcrumb/index.ts +1 -0
- package/assets/components/Button/Button.module.css +2 -4
- package/assets/components/Callout/Callout.module.css +44 -18
- package/assets/components/Callout/Callout.tsx +9 -4
- package/assets/components/Callout/index.ts +1 -1
- package/assets/components/Canvas/Canvas.module.css +13 -0
- package/assets/components/Canvas/Canvas.tsx +378 -94
- package/assets/components/Canvas/clipboard.ts +5 -1
- package/assets/components/Canvas/collision.ts +5 -1
- package/assets/components/Canvas/graph.ts +14 -5
- package/assets/components/Canvas/history.ts +11 -4
- package/assets/components/Canvas/index.ts +2 -1
- package/assets/components/Canvas/types.ts +36 -1
- package/assets/components/CanvasEdge/tokens.css +14 -1
- package/assets/components/CanvasNode/tokens.css +13 -10
- package/assets/components/ChatInput/ChatInput.tsx +1 -1
- package/assets/components/ColorField/ColorField.module.css +6 -1
- package/assets/components/ColorPicker/ColorPicker.module.css +3 -0
- package/assets/components/CommandPalette/CommandPalette.module.css +115 -1
- package/assets/components/CommandPalette/CommandPalette.tsx +206 -21
- package/assets/components/CommandPalette/index.ts +1 -0
- package/assets/components/DatePicker/DatePicker.module.css +3 -2
- package/assets/components/Drawer/Drawer.module.css +30 -0
- package/assets/components/Drawer/Drawer.tsx +75 -16
- package/assets/components/Drawer/index.ts +1 -0
- package/assets/components/Icon/Icon.tsx +3 -0
- package/assets/components/Input/Input.module.css +4 -4
- package/assets/components/Select/Select.module.css +6 -2
- package/assets/components/SocialLoginButton/SocialLoginButton.module.css +198 -0
- package/assets/components/SocialLoginButton/SocialLoginButton.tsx +86 -0
- package/assets/components/SocialLoginButton/assets/amazon.svg +1 -0
- package/assets/components/SocialLoginButton/assets/apple.svg +3 -0
- package/assets/components/SocialLoginButton/assets/discord.svg +3 -0
- package/assets/components/SocialLoginButton/assets/facebook-white.png +0 -0
- package/assets/components/SocialLoginButton/assets/facebook.png +0 -0
- package/assets/components/SocialLoginButton/assets/github.svg +3 -0
- package/assets/components/SocialLoginButton/assets/google-mark.png +0 -0
- package/assets/components/SocialLoginButton/assets/kakao.svg +3 -0
- package/assets/components/SocialLoginButton/assets/line-icon.png +0 -0
- package/assets/components/SocialLoginButton/assets/line-white.png +0 -0
- package/assets/components/SocialLoginButton/assets/linkedin-white.png +0 -0
- package/assets/components/SocialLoginButton/assets/linkedin.png +0 -0
- package/assets/components/SocialLoginButton/assets/microsoft.svg +6 -0
- package/assets/components/SocialLoginButton/assets/naver.png +0 -0
- package/assets/components/SocialLoginButton/assets/slack.svg +17 -0
- package/assets/components/SocialLoginButton/assets/spotify.svg +3 -0
- package/assets/components/SocialLoginButton/assets/twitch.svg +21 -0
- package/assets/components/SocialLoginButton/assets/wechat.png +0 -0
- package/assets/components/SocialLoginButton/assets/x.svg +3 -0
- package/assets/components/SocialLoginButton/index.ts +2 -0
- package/assets/components/SocialLoginButton/provider-tokens.css +30 -0
- package/assets/components/SocialLoginButton/providers.ts +23 -0
- package/assets/components/TimePicker/TimePicker.module.css +3 -2
- package/assets/components/_data.ts +1 -1
- package/assets/components/_utils.css +2 -2
- package/assets/components/component-registry.json +30 -1
- package/assets/components/index.ts +1 -0
- package/assets/components/tokens.css +14 -15
- package/assets/prompts/ASSEMBLY.md +2 -0
- package/assets/prompts/CATALOG.md +1 -0
- package/assets/prompts/PRINCIPLES.md +1 -1
- package/assets/prompts/RULES.md +31 -0
- package/assets/prompts/axes/material.md +4 -4
- package/assets/prompts/axes/palette.md +1 -1
- package/assets/prompts/axes/shape.md +2 -2
- package/assets/prompts/axes/voice.md +2 -2
- package/assets/prompts/components/_variants.md +3 -3
- package/assets/prompts/components/accordion.md +1 -1
- package/assets/prompts/components/ai-message.md +6 -2
- package/assets/prompts/components/app-frame.md +2 -2
- package/assets/prompts/components/avatar.md +2 -2
- package/assets/prompts/components/badge.md +1 -1
- package/assets/prompts/components/breadcrumb.md +11 -5
- package/assets/prompts/components/button.md +2 -2
- package/assets/prompts/components/calendar.md +1 -1
- package/assets/prompts/components/callout.md +8 -4
- package/assets/prompts/components/canvas-edge.md +1 -1
- package/assets/prompts/components/canvas-node.md +2 -2
- package/assets/prompts/components/canvas.md +24 -8
- package/assets/prompts/components/chart-radial.md +1 -1
- package/assets/prompts/components/chart.md +1 -1
- package/assets/prompts/components/chat-reactions.md +1 -1
- package/assets/prompts/components/checkbox-card.md +3 -3
- package/assets/prompts/components/checkbox.md +1 -1
- package/assets/prompts/components/chip.md +4 -4
- package/assets/prompts/components/code-block.md +1 -1
- package/assets/prompts/components/combobox.md +3 -3
- package/assets/prompts/components/command-palette.md +52 -44
- package/assets/prompts/components/comment.md +2 -2
- package/assets/prompts/components/control-group.md +1 -1
- package/assets/prompts/components/data-table.md +1 -1
- package/assets/prompts/components/disclosure.md +1 -1
- package/assets/prompts/components/drawer.md +15 -1
- package/assets/prompts/components/dropdown-menu.md +1 -1
- package/assets/prompts/components/event-chip.md +2 -2
- package/assets/prompts/components/file-icon.md +1 -1
- package/assets/prompts/components/file-upload.md +1 -1
- package/assets/prompts/components/icon-button.md +1 -1
- package/assets/prompts/components/input.md +3 -3
- package/assets/prompts/components/list-item.md +1 -1
- package/assets/prompts/components/menu-item.md +2 -2
- package/assets/prompts/components/metric-card.md +1 -1
- package/assets/prompts/components/mini-calendar.md +1 -1
- package/assets/prompts/components/page-header.md +1 -1
- package/assets/prompts/components/segmented-chart.md +1 -1
- package/assets/prompts/components/sidebar.md +3 -3
- package/assets/prompts/components/skeleton.md +3 -3
- package/assets/prompts/components/social-login-button.md +117 -0
- package/assets/prompts/components/tab-strip.md +1 -1
- package/assets/prompts/components/table-cell.md +1 -1
- package/assets/prompts/components/table-header.md +1 -1
- package/assets/prompts/components/table-row-edit.md +3 -3
- package/assets/prompts/components/table-row.md +1 -1
- package/assets/prompts/components/table-toolbar.md +1 -1
- package/assets/prompts/components/timeline-view.md +2 -2
- package/assets/prompts/components/toast.md +1 -1
- package/assets/prompts/components/tooltip.md +3 -3
- package/assets/prompts/components/tree-nav.md +2 -2
- package/assets/prompts/design-examples/ai-chat-full-page.png +0 -0
- package/assets/prompts/design-examples/catalog.json +9 -9
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.module.css +37 -1
- package/assets/prompts/design-examples/sources/ai-chat-full-page/ChatExperience.tsx +113 -18
- package/assets/prompts/design-examples/sources/ai-chat-full-page/FullPageChat.tsx +2 -2
- package/assets/prompts/design-examples/sources/ai-chat-full-page/REFERENCE.md +3 -1
- package/assets/prompts/design-examples/sources/ai-chat-full-page/useChatDemo.ts +99 -51
- package/assets/prompts/primitives/scroll.md +1 -1
- package/assets/prompts/tokens/color.md +4 -5
- package/assets/prompts/tokens/material.md +5 -2
- package/assets/prompts/tokens/radius.md +1 -1
- package/assets/prompts/use-cases/chat-chat-input.md +382 -74
- package/assets/prompts/use-cases/data-list-item.md +38 -431
- package/assets/prompts/use-cases/feedback-drawer.md +112 -33
- package/assets/prompts/use-cases/overlay-command-palette.md +2004 -0
- package/assets/prompts/use-cases/structure-canvas.md +1016 -0
- package/assets/skills/ovenn-validate/SKILL.md +1 -1
- package/assets/skills/ovenn-validate/scripts/lib/component-usage.js +27 -5
- package/assets/skills/ovenn-validate/scripts/rules/hard-rules.mjs +174 -0
- package/assets/skills/ovenn-validate/scripts/rules/hard-rules.test.mjs +57 -0
- package/assets/skills/ovenn-validate/scripts/validate.mjs +2 -0
- package/package.json +1 -1
- package/src/commands/info.js +5 -4
- package/src/commands/update.js +5 -1
- package/src/utils/agents.js +28 -17
- package/src/utils/client-bridges.js +4 -2
- package/src/utils/component-usage.js +27 -5
- package/src/utils/patch.js +2 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { useCallback, useMemo, useEffect, useId, useLayoutEffect, useRef, useState, type ClipboardEvent, type CSSProperties, type HTMLAttributes, type KeyboardEvent, type PointerEvent } from "react";
|
|
3
|
+
import { useCallback, useMemo, useEffect, useId, useLayoutEffect, useRef, useState, type ClipboardEvent, type CSSProperties, type HTMLAttributes, type KeyboardEvent, type PointerEvent, type ReactNode } from "react";
|
|
4
4
|
import { Icon } from "../Icon";
|
|
5
5
|
import { CanvasNode, type CanvasNodePortSide } from "../CanvasNode";
|
|
6
6
|
import { CanvasEdge, type CanvasEdgeObstacle, type CanvasEdgeEndpoint, type CanvasEdgeLineStyle } from "../CanvasEdge";
|
|
@@ -9,18 +9,19 @@ import { Toolbar, type ToolbarOrientation } from "../Toolbar";
|
|
|
9
9
|
import { IconButton } from "../IconButton";
|
|
10
10
|
import { canvasNodeSelectionIds, canvasEdgeSelectionIds, makeCanvasSelection, canvasPathIntersectsRect, canvasSelectionRect, canvasNodesInRect, sameCanvasSelection, type CanvasSelectionRect } from "./selection";
|
|
11
11
|
import { alignCanvasNodes, type CanvasAlignmentGuide, type CanvasAlignmentConfig } from "./alignment";
|
|
12
|
-
import { CanvasHistory, canvasGraphSignature, snapshotCanvasGraph, restoreCanvasGraph, type
|
|
12
|
+
import { CanvasHistory, canvasGraphSignature, snapshotCanvasGraph, restoreCanvasGraph, type CanvasSnapshot } from "./history";
|
|
13
13
|
import { useCanvasSettlement } from "./useCanvasSettlement";
|
|
14
|
-
import { constrainCanvasMovement, findCanvasPlacement } from "./collision";
|
|
14
|
+
import { constrainCanvasMovement, findCanvasPlacement, isCanvasPlacementFree } from "./collision";
|
|
15
15
|
import { snapshotCanvasSelection, storeCanvasClipboard, readCanvasClipboard } from "./clipboard";
|
|
16
|
-
import { canConnectCanvas, samePort } from "./graph";
|
|
16
|
+
import { canConnectCanvas, canUseCanvasPort, samePort } from "./graph";
|
|
17
17
|
import { resolveCanvasCornerRadius, type CanvasCornerRadii } from "./edgeOptions";
|
|
18
|
-
import type { CanvasBackground, CanvasEdgeCornerRadius,
|
|
18
|
+
import type { CanvasBackground, CanvasConnection, CanvasConnectionDropNode, CanvasConnectionDropRequest, CanvasEdgeCornerRadius, CanvasGraph, CanvasItem, CanvasLabels, CanvasLink, CanvasOverlayContext, CanvasPort, CanvasSelection } from "./types";
|
|
19
19
|
import "./tokens.css";
|
|
20
20
|
import styles from "./Canvas.module.css";
|
|
21
21
|
|
|
22
22
|
type Point = { x: number; y: number };
|
|
23
23
|
type Viewport = Point & { zoom: number };
|
|
24
|
+
type PinchEvent = Event & { scale: number; clientX?: number; clientY?: number };
|
|
24
25
|
type Metrics = { width: number; height: number; body: CanvasEdgeObstacle; captions: CanvasEdgeObstacle[]; ports: Partial<Record<CanvasNodePortSide, Point>> };
|
|
25
26
|
type GesturePointer = Pick<globalThis.PointerEvent, "pointerId" | "clientX" | "clientY">;
|
|
26
27
|
type Gesture = { pointerId: number; start: Point; last?: Point; moved: boolean } & (
|
|
@@ -29,18 +30,60 @@ type Gesture = { pointerId: number; start: Point; last?: Point; moved: boolean }
|
|
|
29
30
|
const english: CanvasLabels = {
|
|
30
31
|
canvas: "Canvas", controls: "View controls", zoomIn: "Zoom in", zoomOut: "Zoom out", fit: "Fit to view",
|
|
31
32
|
zoom: "Zoom",
|
|
32
|
-
instructions: "Drag nodes to move. Drag
|
|
33
|
+
instructions: "Drag nodes to move. Drag from a handle and release on a node or its handle to connect. With the keyboard, press Enter or Space on each handle. Arrow keys move a focused node; Shift moves faster. Escape cancels. Delete removes selection. Cmd/Ctrl+Z undoes edits; add Shift to redo. Drag the background to select nodes and connections. Hold Shift to add to selection.",
|
|
33
34
|
connecting: "Choose another node’s handle to connect. Escape cancels.", connected: "Connection added.", cancelled: "Connection cancelled.",
|
|
35
|
+
createFromPort: "Press Shift+Enter on an output handle to add a connected node.",
|
|
34
36
|
port: (title, side) => `${title}, ${side} connection handle`,
|
|
35
37
|
};
|
|
38
|
+
const portDirection = { left: { x: -1, y: 0 }, right: { x: 1, y: 0 }, top: { x: 0, y: -1 }, bottom: { x: 0, y: 1 } };
|
|
39
|
+
|
|
40
|
+
function zoomViewport(viewport: Viewport, value: number, anchor: Point): Viewport {
|
|
41
|
+
const zoom = Math.max(.25, Math.min(2, value));
|
|
42
|
+
if (zoom === viewport.zoom) return viewport;
|
|
43
|
+
const ratio = zoom / viewport.zoom;
|
|
44
|
+
return { x: anchor.x - (anchor.x - viewport.x) * ratio, y: anchor.y - (anchor.y - viewport.y) * ratio, zoom };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function estimateDropFootprint(node: Omit<CanvasItem, "id" | "position">): CanvasEdgeObstacle[] {
|
|
48
|
+
const card = !node.shape || node.shape === "card";
|
|
49
|
+
const width = card ? 176 : 64;
|
|
50
|
+
const status = node.statusLabel || (node.status !== "idle" ? node.status : undefined);
|
|
51
|
+
const lines = (text: string | undefined, columns: number) => text ? Math.ceil(text.length / columns) : 0;
|
|
52
|
+
if (card) {
|
|
53
|
+
const height = Math.max(64, 28 + 22 * lines(node.title, 9) + 20 * lines(status || node.description, 10));
|
|
54
|
+
return [{ x: 0, y: 0, width, height }];
|
|
55
|
+
}
|
|
56
|
+
const body = { x: 0, y: 0, width, height: 64 };
|
|
57
|
+
const hasVisual = !!(node.media ?? node.icon) || node.status === "loading" || node.status === "success" || node.status === "error";
|
|
58
|
+
const captionLines = (hasVisual ? lines(node.title, 7) : 0) + lines(node.description, 8) + lines(status, 8);
|
|
59
|
+
return captionLines ? [body, { x: (width - 104) / 2, y: body.height + 6, width: 104, height: 22 * captionLines + 6 }] : [body];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function dropPlacement(node: Omit<CanvasItem, "id" | "position">, targetSide: CanvasNodePortSide, point: Point) {
|
|
63
|
+
const direction = portDirection[targetSide];
|
|
64
|
+
if (!direction) return null;
|
|
65
|
+
const footprint = estimateDropFootprint(node);
|
|
66
|
+
const { width, height } = footprint[0];
|
|
67
|
+
const position = {
|
|
68
|
+
x: point.x - width * (1 + direction.x) / 2,
|
|
69
|
+
y: point.y - height * (1 + direction.y) / 2,
|
|
70
|
+
};
|
|
71
|
+
const rects = footprint.map(rect => ({ ...rect, x: rect.x + position.x, y: rect.y + position.y }));
|
|
72
|
+
return { position, rects };
|
|
73
|
+
}
|
|
74
|
+
|
|
36
75
|
export interface CanvasProps extends Omit<HTMLAttributes<HTMLDivElement>, "children" | "onChange" | "onSelect"> {
|
|
37
76
|
nodes: readonly CanvasItem[];
|
|
38
77
|
edges: readonly CanvasLink[];
|
|
39
78
|
onNodesChange?: (nodes: CanvasItem[]) => void;
|
|
40
79
|
onEdgesChange?: (edges: CanvasLink[]) => void;
|
|
80
|
+
/** Publishes both arrays together. Takes precedence over the split callbacks. */
|
|
81
|
+
onGraphChange?: (graph: CanvasGraph) => void;
|
|
82
|
+
onConnectDrop?: (request: CanvasConnectionDropRequest) => void;
|
|
83
|
+
renderOverlay?: (context: CanvasOverlayContext) => ReactNode;
|
|
41
84
|
selection?: CanvasSelection;
|
|
42
85
|
onSelectionChange?: (selection: CanvasSelection) => void;
|
|
43
|
-
isValidConnection?: (connection: CanvasConnection) => boolean;
|
|
86
|
+
isValidConnection?: (connection: CanvasConnection, graph: CanvasGraph) => boolean;
|
|
44
87
|
/** Three Shape-aware presets. Omitted values follow the nearest Shape scope. */
|
|
45
88
|
edgeCornerRadius?: CanvasEdgeCornerRadius;
|
|
46
89
|
lineStyle?: CanvasEdgeLineStyle;
|
|
@@ -54,14 +97,27 @@ export interface CanvasProps extends Omit<HTMLAttributes<HTMLDivElement>, "child
|
|
|
54
97
|
controls?: boolean;
|
|
55
98
|
/** Direction of the view toolbar; defaults to horizontal. */
|
|
56
99
|
controlsOrientation?: ToolbarOrientation;
|
|
100
|
+
/** Minimum screen-space room on each side of the fitted graph, including outside overlays. */
|
|
101
|
+
fitInlineInset?: number;
|
|
102
|
+
/** Disable manual panning and zooming, and keep the committed graph fitted. */
|
|
103
|
+
viewportLocked?: boolean;
|
|
104
|
+
/** Use the theme foreground for neutral node outlines and connections. */
|
|
105
|
+
highContrast?: boolean;
|
|
57
106
|
labels?: Partial<CanvasLabels>;
|
|
58
107
|
}
|
|
59
108
|
|
|
60
109
|
/** A controlled graph surface composed from CanvasNode and CanvasEdge. */
|
|
61
|
-
export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection: controlledSelection, onSelectionChange,
|
|
62
|
-
isValidConnection, edgeCornerRadius, lineStyle = "solid", readOnly = false, grid = true, background, backgroundScale = .9, defaultBackground, controls = true, controlsOrientation = "horizontal",
|
|
63
|
-
labels, className, onKeyDown, ...rest }: CanvasProps) {
|
|
64
|
-
const text = {
|
|
110
|
+
export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, onGraphChange, onConnectDrop, renderOverlay, selection: controlledSelection, onSelectionChange,
|
|
111
|
+
isValidConnection, edgeCornerRadius, lineStyle = "solid", readOnly = false, grid = true, background, backgroundScale = .9, defaultBackground, controls: showViewControls = true, controlsOrientation = "horizontal",
|
|
112
|
+
fitInlineInset = 0, viewportLocked = false, highContrast = false, labels, className, onKeyDown, ...rest }: CanvasProps) {
|
|
113
|
+
const text = {
|
|
114
|
+
...english,
|
|
115
|
+
instructions: viewportLocked ? english.instructions : `${english.instructions} Hold Space while dragging, or use the middle mouse button, to pan.`,
|
|
116
|
+
...labels,
|
|
117
|
+
};
|
|
118
|
+
const controls = showViewControls && !viewportLocked;
|
|
119
|
+
const canEditNodes = !!(onGraphChange || onNodesChange);
|
|
120
|
+
const canEditEdges = !!(onGraphChange || onEdgesChange);
|
|
65
121
|
const helpId = useId();
|
|
66
122
|
const captionMaskId = useId();
|
|
67
123
|
const [surfaceSize, setSurfaceSize] = useState({ width: 1, height: 1 });
|
|
@@ -81,6 +137,16 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
81
137
|
const [panReady, setPanReady] = useState(false);
|
|
82
138
|
const [marquee, setMarquee] = useState<CanvasSelectionRect | null>(null);
|
|
83
139
|
const fitted = useRef(false);
|
|
140
|
+
const lockedFitKey = useRef<string | null>(null);
|
|
141
|
+
const lockedFitDeferred = useRef(false);
|
|
142
|
+
const [fitRevision, setFitRevision] = useState(0);
|
|
143
|
+
const clearGesture = useCallback(() => {
|
|
144
|
+
gesture.current = null;
|
|
145
|
+
if (lockedFitDeferred.current) {
|
|
146
|
+
lockedFitDeferred.current = false;
|
|
147
|
+
setFitRevision(revision => revision + 1);
|
|
148
|
+
}
|
|
149
|
+
}, []);
|
|
84
150
|
const [compactControls, setCompactControls] = useState(false);
|
|
85
151
|
const [initialBackground] = useState<CanvasBackground | undefined>(defaultBackground);
|
|
86
152
|
const resolvedBackground = background ?? initialBackground ?? (grid ? "dots" : "none");
|
|
@@ -104,6 +170,17 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
104
170
|
const [panning, setPanning] = useState(false);
|
|
105
171
|
const [announcement, setAnnouncement] = useState("");
|
|
106
172
|
const history = useRef(new CanvasHistory());
|
|
173
|
+
const activeDrop = useRef<{ source: CanvasPort; controller: AbortController } | null>(null);
|
|
174
|
+
const invalidateDrop = useCallback(() => {
|
|
175
|
+
const request = activeDrop.current;
|
|
176
|
+
activeDrop.current = null;
|
|
177
|
+
request?.controller.abort();
|
|
178
|
+
}, []);
|
|
179
|
+
useLayoutEffect(() => invalidateDrop, [invalidateDrop]);
|
|
180
|
+
const dropActions = useRef<{
|
|
181
|
+
prepare: (source: CanvasPort, point: Point, draft: CanvasConnectionDropNode) => { node: CanvasItem; connection: CanvasConnection } | null;
|
|
182
|
+
publish: (node: CanvasItem, connection: CanvasConnection) => void;
|
|
183
|
+
} | null>(null);
|
|
107
184
|
const graph = useRef<CanvasGraph>({ nodes, edges });
|
|
108
185
|
const ownGraphs = useRef(new Set<string>());
|
|
109
186
|
const dragHistory = useRef<{ before: CanvasSnapshot; selection: CanvasSelection } | null>(null);
|
|
@@ -114,11 +191,11 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
114
191
|
graph.current = actual; ownGraphs.current.clear(); history.current.clear(); dragHistory.current = null;
|
|
115
192
|
const current = gesture.current;
|
|
116
193
|
if (current?.type === "node") {
|
|
117
|
-
|
|
194
|
+
clearGesture(); setDragging(null); clearGuides();
|
|
118
195
|
if (root.current?.hasPointerCapture(current.pointerId)) root.current.releasePointerCapture(current.pointerId);
|
|
119
196
|
}
|
|
120
197
|
}
|
|
121
|
-
}, [nodes, edges, clearGuides]);
|
|
198
|
+
}, [nodes, edges, clearGuides, clearGesture]);
|
|
122
199
|
const publishGraph = (next: CanvasGraph) => {
|
|
123
200
|
const previous = graph.current;
|
|
124
201
|
const nodeChanged = canvasGraphSignature({ nodes: previous.nodes, edges: [] }) !== canvasGraphSignature({ nodes: next.nodes, edges: [] });
|
|
@@ -127,8 +204,11 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
127
204
|
for (const value of [previous, { nodes: next.nodes, edges: previous.edges }, { nodes: previous.nodes, edges: next.edges }, next]) ownGraphs.current.add(canvasGraphSignature(value));
|
|
128
205
|
while (ownGraphs.current.size > 128) ownGraphs.current.delete(ownGraphs.current.values().next().value!);
|
|
129
206
|
graph.current = next;
|
|
130
|
-
if (
|
|
131
|
-
|
|
207
|
+
if (onGraphChange) onGraphChange({ nodes: [...next.nodes], edges: [...next.edges] });
|
|
208
|
+
else {
|
|
209
|
+
if (nodeChanged) onNodesChange?.([...next.nodes]);
|
|
210
|
+
if (edgeChanged) onEdgesChange?.([...next.edges]);
|
|
211
|
+
}
|
|
132
212
|
};
|
|
133
213
|
const publishNodes = (next: readonly CanvasItem[]) => publishGraph({ nodes: next, edges: graph.current.edges });
|
|
134
214
|
const selectedNodeIds = new Set(canvasNodeSelectionIds(selected));
|
|
@@ -147,7 +227,7 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
147
227
|
};
|
|
148
228
|
useEffect(() => {
|
|
149
229
|
const down = (event: globalThis.KeyboardEvent) => {
|
|
150
|
-
if (event.code !== "Space" || event.ctrlKey || event.metaKey || event.altKey || (event.target instanceof Element && event.target.closest("input, textarea, select, [contenteditable='true'], [role='textbox'], [role='slider'], [data-canvas-controls]"))) return;
|
|
230
|
+
if (viewportLocked || event.code !== "Space" || event.ctrlKey || event.metaKey || event.altKey || (event.target instanceof Element && event.target.closest("input, textarea, select, [contenteditable='true'], [role='textbox'], [role='slider'], [data-canvas-controls], [data-canvas-overlay]"))) return;
|
|
151
231
|
spacePressed.current = true; setPanReady(true);
|
|
152
232
|
const element = root.current;
|
|
153
233
|
if (element && (element.contains(document.activeElement) || element.matches(":hover")) && !(event.target instanceof Element && event.target.closest("button, a, [role='button']"))) event.preventDefault();
|
|
@@ -160,7 +240,7 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
160
240
|
const blur = () => { spacePressed.current = false; spaceUsedForPan.current = false; setPanReady(false); cancelRef.current(); };
|
|
161
241
|
window.addEventListener("keydown", down, true); window.addEventListener("keyup", up, true); window.addEventListener("blur", blur);
|
|
162
242
|
return () => { window.removeEventListener("keydown", down, true); window.removeEventListener("keyup", up, true); window.removeEventListener("blur", blur); };
|
|
163
|
-
}, []);
|
|
243
|
+
}, [viewportLocked]);
|
|
164
244
|
useEffect(() => {
|
|
165
245
|
const up = (event: globalThis.PointerEvent) => {
|
|
166
246
|
if ((gesture.current?.type === "node" || gesture.current?.type === "connect") && !root.current?.hasPointerCapture(event.pointerId)) releaseRef.current(event);
|
|
@@ -259,14 +339,15 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
259
339
|
const topInset = 32;
|
|
260
340
|
const bottomInset = controls ? 72 : 32;
|
|
261
341
|
const workHeight = Math.max(1, height - topInset - bottomInset);
|
|
262
|
-
const
|
|
342
|
+
const requestedInset = Number.isFinite(fitInlineInset) ? Math.min(fitInlineInset, width / 4) : 0;
|
|
343
|
+
const leftInset = Math.max(padding / 2, requestedInset);
|
|
263
344
|
const rightInset = controls && controlsOrientation === "vertical"
|
|
264
345
|
? Math.max(leftInset, (root.current.querySelector<HTMLElement>("[data-canvas-controls='view']")?.offsetWidth ?? 48) + 32)
|
|
265
346
|
: leftInset;
|
|
266
347
|
const workWidth = Math.max(1, width - leftInset - rightInset);
|
|
267
|
-
const zoom = Math.max(initial ? .85 : .25, Math.min(1, workWidth / Math.max(1, right - left), workHeight / Math.max(1, bottom - top)));
|
|
348
|
+
const zoom = Math.max(viewportLocked ? 0 : initial ? .85 : .25, Math.min(1, workWidth / Math.max(1, right - left), workHeight / Math.max(1, bottom - top)));
|
|
268
349
|
setViewport({ x: leftInset + (workWidth - (right - left) * zoom) / 2 - left * zoom, y: topInset + (workHeight - (bottom - top) * zoom) / 2 - top * zoom, zoom });
|
|
269
|
-
}, [nodes, metrics, controls, controlsOrientation]);
|
|
350
|
+
}, [nodes, metrics, controls, controlsOrientation, fitInlineInset, viewportLocked]);
|
|
270
351
|
const nodeSignature = nodes.map(n => `${n.id}:${n.shape}:${n.title}:${n.description}:${n.status}:${(n.ports ?? ["left", "right"]).join()}`).join("|");
|
|
271
352
|
useLayoutEffect(() => {
|
|
272
353
|
const measure = () => {
|
|
@@ -297,60 +378,218 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
297
378
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
298
379
|
}, [nodeSignature, viewport.zoom]);
|
|
299
380
|
useLayoutEffect(() => {
|
|
300
|
-
if (!nodes.length ||
|
|
301
|
-
|
|
302
|
-
|
|
381
|
+
if (!nodes.length || nodes.some(n => !metrics[n.id])) return;
|
|
382
|
+
if (viewportLocked) {
|
|
383
|
+
if (gesture.current) {
|
|
384
|
+
lockedFitDeferred.current = true;
|
|
385
|
+
return;
|
|
386
|
+
}
|
|
387
|
+
const bounds = nodes.map(node => [node.position, Math.round(metrics[node.id].width), Math.round(metrics[node.id].height)]);
|
|
388
|
+
const key = JSON.stringify([surfaceSize, fitInlineInset, nodeSignature, bounds, edges.map(edge => [edge.id, edge.source, edge.target])]);
|
|
389
|
+
if (key === lockedFitKey.current) return;
|
|
390
|
+
lockedFitKey.current = key;
|
|
391
|
+
fit();
|
|
392
|
+
} else {
|
|
393
|
+
lockedFitKey.current = null;
|
|
394
|
+
lockedFitDeferred.current = false;
|
|
395
|
+
if (!fitted.current) {
|
|
396
|
+
fitted.current = true;
|
|
397
|
+
fit(true);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
}, [nodes, edges, metrics, fit, viewportLocked, surfaceSize, fitInlineInset, nodeSignature, fitRevision]);
|
|
303
401
|
useLayoutEffect(() => {
|
|
304
402
|
const element = root.current;
|
|
305
|
-
if (!element)
|
|
403
|
+
if (!element || viewportLocked) {
|
|
404
|
+
if (gesture.current?.type === "pan") cancelRef.current();
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
let pinchScale: number | null = null;
|
|
409
|
+
const zoomBy = (factor: number, clientX?: number, clientY?: number) => {
|
|
410
|
+
const bounds = element.getBoundingClientRect();
|
|
411
|
+
const anchor = {
|
|
412
|
+
x: clientX === undefined ? bounds.width / 2 : clientX - bounds.left,
|
|
413
|
+
y: clientY === undefined ? bounds.height / 2 : clientY - bounds.top,
|
|
414
|
+
};
|
|
415
|
+
setViewport(v => zoomViewport(v, v.zoom * factor, anchor));
|
|
416
|
+
};
|
|
306
417
|
const wheel = (event: WheelEvent) => {
|
|
307
|
-
if (
|
|
418
|
+
if (event.defaultPrevented) return;
|
|
308
419
|
event.preventDefault();
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
420
|
+
if (gesture.current || pinchScale !== null) return;
|
|
421
|
+
|
|
422
|
+
const mode = event.deltaMode;
|
|
423
|
+
const linePixels = 16;
|
|
424
|
+
const dx = event.deltaX * (mode === WheelEvent.DOM_DELTA_PAGE ? element.clientWidth : mode === WheelEvent.DOM_DELTA_LINE ? linePixels : 1);
|
|
425
|
+
const dy = event.deltaY * (mode === WheelEvent.DOM_DELTA_PAGE ? element.clientHeight : mode === WheelEvent.DOM_DELTA_LINE ? linePixels : 1);
|
|
426
|
+
if (event.ctrlKey || event.metaKey) {
|
|
427
|
+
zoomBy(Math.exp(-dy * .01), event.clientX, event.clientY);
|
|
428
|
+
} else if (dx || dy) {
|
|
429
|
+
setViewport(v => ({ ...v, x: v.x - dx, y: v.y - dy }));
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
|
|
433
|
+
// Safari can report pinch as a cumulative GestureEvent scale instead of a modified wheel.
|
|
434
|
+
const pinchStart = (event: Event) => {
|
|
435
|
+
if (event.defaultPrevented) return;
|
|
436
|
+
event.preventDefault();
|
|
437
|
+
pinchScale = 1;
|
|
438
|
+
};
|
|
439
|
+
const pinchChange = (event: Event) => {
|
|
440
|
+
if (pinchScale === null) return;
|
|
441
|
+
event.preventDefault();
|
|
442
|
+
const { scale, clientX, clientY } = event as PinchEvent;
|
|
443
|
+
if (!Number.isFinite(scale) || scale <= 0) return;
|
|
444
|
+
const factor = scale / pinchScale;
|
|
445
|
+
pinchScale = scale;
|
|
446
|
+
if (!gesture.current) zoomBy(factor, clientX, clientY);
|
|
315
447
|
};
|
|
448
|
+
const pinchEnd = () => { pinchScale = null; };
|
|
449
|
+
|
|
316
450
|
element.addEventListener("wheel", wheel, { passive: false });
|
|
317
|
-
|
|
318
|
-
|
|
451
|
+
element.addEventListener("gesturestart", pinchStart);
|
|
452
|
+
element.addEventListener("gesturechange", pinchChange);
|
|
453
|
+
element.addEventListener("gestureend", pinchEnd);
|
|
454
|
+
return () => {
|
|
455
|
+
element.removeEventListener("wheel", wheel);
|
|
456
|
+
element.removeEventListener("gesturestart", pinchStart);
|
|
457
|
+
element.removeEventListener("gesturechange", pinchChange);
|
|
458
|
+
element.removeEventListener("gestureend", pinchEnd);
|
|
459
|
+
};
|
|
460
|
+
}, [viewportLocked]);
|
|
319
461
|
useEffect(() => {
|
|
320
462
|
const current = gesture.current;
|
|
321
|
-
const lockedNode = current?.type === "node" && (readOnly || !
|
|
322
|
-
const lockedConnection =
|
|
463
|
+
const lockedNode = current?.type === "node" && (readOnly || !canEditNodes || !nodes.some(n => n.id === current.id && !n.disabled));
|
|
464
|
+
const lockedConnection = pending && (readOnly || !canEditEdges || !canUseCanvasPort(nodes, edges, pending, "source"));
|
|
323
465
|
if (lockedNode || lockedConnection) {
|
|
324
|
-
|
|
325
|
-
if (root.current?.hasPointerCapture(current.pointerId)) root.current.releasePointerCapture(current.pointerId);
|
|
466
|
+
clearGesture();
|
|
467
|
+
if (current && root.current?.hasPointerCapture(current.pointerId)) root.current.releasePointerCapture(current.pointerId);
|
|
326
468
|
}
|
|
327
|
-
if (
|
|
328
|
-
|
|
469
|
+
if (lockedNode) { dragHistory.current = null; setDragging(null); clearGuides(); }
|
|
470
|
+
if (lockedConnection) {
|
|
471
|
+
draftId.current = null; setPending(null); setCandidate(null);
|
|
329
472
|
}
|
|
330
|
-
}, [pending, readOnly,
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
473
|
+
}, [pending, readOnly, canEditEdges, canEditNodes, nodes, edges, clearGuides, clearGesture]);
|
|
474
|
+
useLayoutEffect(() => {
|
|
475
|
+
const request = activeDrop.current;
|
|
476
|
+
if (request && (readOnly || !onConnectDrop || !canEditNodes || !canEditEdges || !canUseCanvasPort(nodes, edges, request.source, "source"))) invalidateDrop();
|
|
477
|
+
}, [nodes, edges, readOnly, onConnectDrop, canEditNodes, canEditEdges, invalidateDrop]);
|
|
478
|
+
|
|
479
|
+
const valid = (connection: CanvasConnection, current = graph.current) =>
|
|
480
|
+
canConnectCanvas(current.nodes, current.edges, connection) && (isValidConnection?.(connection, current) ?? true);
|
|
481
|
+
// Pointer capture retargets the event to the canvas instead of the surface under the pointer.
|
|
482
|
+
const hitAt = ({ clientX, clientY }: GesturePointer) => root.current?.ownerDocument.elementFromPoint(clientX, clientY) ?? null;
|
|
483
|
+
const nearest = (point: Point, source: CanvasPort, hit: Element | null): CanvasPort | null => {
|
|
484
|
+
if (!hit || !root.current?.contains(hit) || hit.closest("[data-canvas-controls], [data-canvas-overlay]")) return null;
|
|
485
|
+
const handle = hit.closest<HTMLElement>("[data-canvas-port]");
|
|
486
|
+
if (handle && root.current?.contains(handle)) {
|
|
487
|
+
const target = { nodeId: handle.dataset.nodeId!, side: handle.dataset.canvasPort as CanvasNodePortSide };
|
|
488
|
+
return valid({ source, target }) ? target : null;
|
|
489
|
+
}
|
|
490
|
+
const hitId = hit.closest<HTMLElement>("[data-canvas-item]")?.dataset.canvasItem;
|
|
491
|
+
const overBody = hitId !== undefined && nodeElements.current.get(hitId)?.firstElementChild?.contains(hit);
|
|
492
|
+
let best: CanvasPort | null = null, distance = overBody ? Infinity : 20 / Math.max(1, viewport.zoom);
|
|
493
|
+
for (const node of nodes) {
|
|
494
|
+
if (overBody && node.id !== hitId) continue;
|
|
495
|
+
for (const side of node.ports ?? ["left", "right"] as const) {
|
|
496
|
+
const port = { nodeId: node.id, side }, at = endpoint(port);
|
|
497
|
+
if (!at || !valid({ source, target: port })) continue;
|
|
498
|
+
const d = Math.hypot(point.x - at.x, point.y - at.y);
|
|
499
|
+
if (d < distance) { distance = d; best = port; }
|
|
500
|
+
}
|
|
339
501
|
}
|
|
340
502
|
return best;
|
|
341
503
|
};
|
|
342
504
|
const clearConnection = (cancelled = false) => { draftId.current = null; setPending(null); setCandidate(null); if (cancelled) setAnnouncement(text.cancelled); };
|
|
505
|
+
const startConnection = (port: CanvasPort) => {
|
|
506
|
+
invalidateDrop();
|
|
507
|
+
draftId.current = `edge-${crypto.randomUUID()}`;
|
|
508
|
+
setPending(port);
|
|
509
|
+
setCandidate(null);
|
|
510
|
+
const at = endpoint(port);
|
|
511
|
+
if (at) setPointer(at);
|
|
512
|
+
};
|
|
343
513
|
const connect = (source: CanvasPort, target: CanvasPort) => {
|
|
344
|
-
if (readOnly || !
|
|
514
|
+
if (readOnly || !canEditEdges || !valid({ source, target })) return false;
|
|
345
515
|
const id = draftId.current ?? `edge-${crypto.randomUUID()}`;
|
|
346
516
|
const before = snapshotCanvasGraph(graph.current, selected), selection: CanvasSelection = { type: "edge", id };
|
|
347
517
|
publishGraph({ nodes: graph.current.nodes, edges: [...graph.current.edges, { id, source, target }] });
|
|
348
518
|
history.current.record(before, snapshotCanvasGraph(graph.current, selection));
|
|
349
519
|
select(selection); clearConnection(); setAnnouncement(text.connected); return true;
|
|
350
520
|
};
|
|
521
|
+
const isEmptyDrop = (point: Point) => ![...obstacleBounds.values()].some(({ body, captions }) =>
|
|
522
|
+
[body, ...captions].some(rect => point.x >= rect.x && point.x <= rect.x + rect.width && point.y >= rect.y && point.y <= rect.y + rect.height));
|
|
523
|
+
|
|
524
|
+
const prepareDrop = (source: CanvasPort, point: Point, { node: fields, targetSide }: CanvasConnectionDropNode) => {
|
|
525
|
+
const current = graph.current;
|
|
526
|
+
if (readOnly || !onConnectDrop || !canEditNodes || !canEditEdges || !fields.id ||
|
|
527
|
+
current.nodes.some(node => node.id === fields.id)) return null;
|
|
528
|
+
const placement = dropPlacement(fields, targetSide, point);
|
|
529
|
+
if (!placement) return null;
|
|
530
|
+
const correction = findCanvasPlacement(placement.rects, current.nodes.flatMap(item => collisionRects(item)), nodeGap);
|
|
531
|
+
const node = { ...fields, position: { x: placement.position.x + correction.x, y: placement.position.y + correction.y } };
|
|
532
|
+
const connection = { source, target: { nodeId: node.id, side: targetSide } };
|
|
533
|
+
return valid(connection, { nodes: [...current.nodes, node], edges: current.edges }) ? { node, connection } : null;
|
|
534
|
+
};
|
|
535
|
+
dropActions.current = {
|
|
536
|
+
prepare: prepareDrop,
|
|
537
|
+
publish: (node, connection) => {
|
|
538
|
+
const before = snapshotCanvasGraph(graph.current, selected);
|
|
539
|
+
const selection: CanvasSelection = { type: "node", id: node.id };
|
|
540
|
+
const edge = { id: `edge-${crypto.randomUUID()}`, ...connection };
|
|
541
|
+
publishGraph({ nodes: [...graph.current.nodes, node], edges: [...graph.current.edges, edge] });
|
|
542
|
+
history.current.record(before, snapshotCanvasGraph(graph.current, selection));
|
|
543
|
+
select(selection);
|
|
544
|
+
keepNodesVisible([node]);
|
|
545
|
+
const element = root.current;
|
|
546
|
+
if (element?.contains(element.ownerDocument.activeElement)) element.focus({ preventScroll: true });
|
|
547
|
+
setAnnouncement(text.connected);
|
|
548
|
+
},
|
|
549
|
+
};
|
|
550
|
+
const openDrop = (source: CanvasPort, point: Point, clientPosition: Point): boolean => {
|
|
551
|
+
if (!onConnectDrop || readOnly || !canEditNodes || !canEditEdges ||
|
|
552
|
+
!canUseCanvasPort(graph.current.nodes, graph.current.edges, source, "source")) return false;
|
|
553
|
+
invalidateDrop();
|
|
554
|
+
const controller = new AbortController();
|
|
555
|
+
activeDrop.current = { source, controller };
|
|
556
|
+
const prepare = (draft: CanvasConnectionDropNode) =>
|
|
557
|
+
activeDrop.current?.controller === controller ? dropActions.current?.prepare(source, point, draft) : null;
|
|
558
|
+
onConnectDrop({
|
|
559
|
+
source: { ...source }, position: { ...point }, clientPosition,
|
|
560
|
+
signal: controller.signal,
|
|
561
|
+
canCommit: draft => !!prepare(draft),
|
|
562
|
+
commit: draft => {
|
|
563
|
+
const actions = dropActions.current;
|
|
564
|
+
const next = prepare(draft);
|
|
565
|
+
if (!next || !actions || activeDrop.current?.controller !== controller) return false;
|
|
566
|
+
activeDrop.current = null;
|
|
567
|
+
try { actions.publish(next.node, next.connection); }
|
|
568
|
+
finally { controller.abort(); }
|
|
569
|
+
return true;
|
|
570
|
+
},
|
|
571
|
+
dismiss: () => { if (activeDrop.current?.controller === controller) invalidateDrop(); },
|
|
572
|
+
});
|
|
573
|
+
return true;
|
|
574
|
+
};
|
|
575
|
+
const connectionDropPoint = (source: CanvasPort) => {
|
|
576
|
+
const from = endpoint(source);
|
|
577
|
+
if (!from) return null;
|
|
578
|
+
const direction = portDirection[source.side];
|
|
579
|
+
const distance = Math.max(from.bounds?.width ?? 0, from.bounds?.height ?? 0, nodeGap) + nodeGap;
|
|
580
|
+
return { x: from.x + direction.x * distance, y: from.y + direction.y * distance };
|
|
581
|
+
};
|
|
582
|
+
const requestConnectionDrop = (source: CanvasPort) => {
|
|
583
|
+
const point = connectionDropPoint(source), bounds = root.current?.getBoundingClientRect();
|
|
584
|
+
if (!point || !bounds || gesture.current) return false;
|
|
585
|
+
if (!openDrop(source, point, { x: bounds.left + viewport.x + point.x * viewport.zoom, y: bounds.top + viewport.y + point.y * viewport.zoom })) return false;
|
|
586
|
+
clearConnection();
|
|
587
|
+
return true;
|
|
588
|
+
};
|
|
351
589
|
const cancelGesture = (rollback = true) => {
|
|
590
|
+
invalidateDrop();
|
|
352
591
|
const current = gesture.current;
|
|
353
|
-
|
|
592
|
+
clearGesture();
|
|
354
593
|
if (current?.type === "node" && (current.moved || current.needsSettlement)) {
|
|
355
594
|
if (rollback) {
|
|
356
595
|
const origins = current.restoreOrigins ?? current.origins;
|
|
@@ -363,7 +602,6 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
363
602
|
if (current?.type === "node" && rollback) dragHistory.current = null;
|
|
364
603
|
if (current?.type === "marquee") select(current.previous, true);
|
|
365
604
|
if (current?.type === "pan" && rollback) setViewport(current.origin);
|
|
366
|
-
gesture.current = null;
|
|
367
605
|
if (current && root.current?.hasPointerCapture(current.pointerId)) root.current.releasePointerCapture(current.pointerId);
|
|
368
606
|
setDragging(null); setPanning(false); setMarquee(null); clearGuides(); clearConnection(!!pending);
|
|
369
607
|
};
|
|
@@ -383,11 +621,10 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
383
621
|
};
|
|
384
622
|
const portDown = (event: PointerEvent<HTMLButtonElement>, port: CanvasPort) => {
|
|
385
623
|
if (!event.isPrimary || event.button !== 0 || gesture.current) return;
|
|
386
|
-
event.preventDefault(); event.stopPropagation(); event.currentTarget.focus();
|
|
387
|
-
if (
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
capture(event, { type: "connect", pointerId: event.pointerId, start: { x: event.clientX, y: event.clientY }, moved: false, source });
|
|
624
|
+
event.preventDefault(); event.stopPropagation(); event.currentTarget.focus({ preventScroll: true });
|
|
625
|
+
if (!canUseCanvasPort(graph.current.nodes, graph.current.edges, port, "source")) return;
|
|
626
|
+
startConnection(port);
|
|
627
|
+
capture(event, { type: "connect", pointerId: event.pointerId, start: { x: event.clientX, y: event.clientY }, moved: false, source: port });
|
|
391
628
|
};
|
|
392
629
|
const nodeDown = (event: PointerEvent, node: CanvasItem) => {
|
|
393
630
|
if (!event.isPrimary || event.button !== 0 || gesture.current || node.disabled || (event.target as Element).closest("[data-canvas-port]")) return;
|
|
@@ -397,7 +634,7 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
397
634
|
if (event.shiftKey) { selectNode(node.id, true); return; }
|
|
398
635
|
const group = ids.includes(node.id) ? ids : [node.id];
|
|
399
636
|
if (!ids.includes(node.id)) select({ type: "node", id: node.id });
|
|
400
|
-
if (readOnly || !
|
|
637
|
+
if (readOnly || !canEditNodes) return;
|
|
401
638
|
dragHistory.current = { before: snapshotCanvasGraph(graph.current, selected), selection: makeCanvasSelection(group, ids.includes(node.id) ? canvasEdgeSelectionIds(selected) : []) };
|
|
402
639
|
const interrupted = group.some(id => settlement.positions[id]) ? settlement.stop(group) : null;
|
|
403
640
|
const originals: Record<string, Point> = Object.assign(Object.create(null), Object.fromEntries(nodes.filter(n => group.includes(n.id) && !n.disabled).map(n => [n.id, n.position])));
|
|
@@ -422,7 +659,7 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
422
659
|
setMarquee(rect);
|
|
423
660
|
};
|
|
424
661
|
const moveNodes = (id: string, origins: Record<string, Point>, desired: Point, phase: "preview" | "drop" | "step" = "step") => {
|
|
425
|
-
if (readOnly || !
|
|
662
|
+
if (readOnly || !canEditNodes || !nodes.some(node => node.id === id && !node.disabled)) return;
|
|
426
663
|
const before = phase === "step" ? snapshotCanvasGraph(graph.current, selected) : null;
|
|
427
664
|
const moving = nodes.filter(node => origins[node.id] && !node.disabled);
|
|
428
665
|
const movingIds = new Set(moving.map(node => node.id));
|
|
@@ -456,15 +693,14 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
456
693
|
const trackPointer = (event: GesturePointer) => {
|
|
457
694
|
if (![event.clientX, event.clientY].every(Number.isFinite)) return;
|
|
458
695
|
const current = gesture.current;
|
|
696
|
+
if (!current || current.pointerId !== event.pointerId) return;
|
|
459
697
|
const point = position(event);
|
|
460
|
-
if (!current) { if (pending) { setPointer(point); setCandidate(nearest(point, pending)); } return; }
|
|
461
|
-
if (current.pointerId !== event.pointerId) return;
|
|
462
698
|
current.last = { x: event.clientX, y: event.clientY };
|
|
463
|
-
if (current.type === "node" && (readOnly || !
|
|
464
|
-
if (current.type === "connect" && (readOnly || !
|
|
699
|
+
if (current.type === "node" && (readOnly || !canEditNodes || !nodes.some(n => n.id === current.id && !n.disabled))) return;
|
|
700
|
+
if (current.type === "connect" && (readOnly || !canEditEdges)) return;
|
|
465
701
|
const dx = event.clientX - current.start.x, dy = event.clientY - current.start.y;
|
|
466
702
|
current.moved ||= Math.hypot(dx, dy) > 3;
|
|
467
|
-
if (current.type === "connect") { setPointer(point); setCandidate(nearest(point, current.source)); }
|
|
703
|
+
if (current.type === "connect") { setPointer(point); setCandidate(nearest(point, current.source, hitAt(event))); }
|
|
468
704
|
if (!current.moved) return;
|
|
469
705
|
if (current.type === "node") {
|
|
470
706
|
setDragging(current.id); suppressClick.current = true;
|
|
@@ -482,7 +718,7 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
482
718
|
// Commit the final position/selection from pointerup for every gesture.
|
|
483
719
|
const dx = event.clientX - current.start.x, dy = event.clientY - current.start.y;
|
|
484
720
|
current.moved ||= Math.hypot(dx, dy) > 3;
|
|
485
|
-
|
|
721
|
+
clearGesture(); setDragging(null); setPanning(false); setMarquee(null);
|
|
486
722
|
if (current.type === "marquee") {
|
|
487
723
|
if (current.moved) { suppressClick.current = true; updateMarquee(current, position(event), true); }
|
|
488
724
|
else if (!current.additive) select(null, true);
|
|
@@ -496,23 +732,29 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
496
732
|
if (current.moved) setViewport({ ...current.origin, x: current.origin.x + dx, y: current.origin.y + dy });
|
|
497
733
|
else if (current.clearOnClick) select(null);
|
|
498
734
|
}
|
|
499
|
-
if (current.type === "connect") {
|
|
500
|
-
const target = nearest(position(event), current.source);
|
|
501
|
-
if (target) connect(current.source, target);
|
|
502
|
-
else if (current.moved) clearConnection(true);
|
|
503
|
-
if (current.moved) { suppressClick.current = true; root.current?.focus({ preventScroll: true }); }
|
|
504
|
-
}
|
|
505
735
|
clearGuides();
|
|
506
736
|
if (root.current?.hasPointerCapture(event.pointerId)) root.current.releasePointerCapture(event.pointerId);
|
|
737
|
+
if (current.type === "connect") {
|
|
738
|
+
if (!current.moved) { clearConnection(); return; }
|
|
739
|
+
suppressClick.current = true;
|
|
740
|
+
root.current?.focus({ preventScroll: true });
|
|
741
|
+
const point = position(event), hit = hitAt(event);
|
|
742
|
+
const target = nearest(point, current.source, hit);
|
|
743
|
+
if (target && connect(current.source, target)) return;
|
|
744
|
+
clearConnection();
|
|
745
|
+
if (onConnectDrop && !target && hit === root.current && isEmptyDrop(point) &&
|
|
746
|
+
openDrop(current.source, point, { x: event.clientX, y: event.clientY })) return;
|
|
747
|
+
setAnnouncement(text.cancelled);
|
|
748
|
+
}
|
|
507
749
|
};
|
|
508
750
|
releaseRef.current = release;
|
|
509
751
|
const remove = () => {
|
|
510
752
|
if (readOnly || !selected) return;
|
|
511
753
|
const nodeIds = canvasNodeSelectionIds(selected);
|
|
512
|
-
if (nodeIds.length && (!
|
|
754
|
+
if (nodeIds.length && (!canEditNodes || !canEditEdges)) return;
|
|
513
755
|
const ids = new Set(nodeIds.filter(id => !nodes.find(n => n.id === id)?.disabled));
|
|
514
756
|
const edgeIds = new Set(canvasEdgeSelectionIds(selected).filter(id => !edges.find(edge => edge.id === id)?.disabled));
|
|
515
|
-
if (!
|
|
757
|
+
if (!canEditEdges) return;
|
|
516
758
|
const before = snapshotCanvasGraph(graph.current, selected);
|
|
517
759
|
publishGraph({ nodes: ids.size ? nodes.filter(node => !ids.has(node.id)) : graph.current.nodes,
|
|
518
760
|
edges: edges.filter(edge => !edgeIds.has(edge.id) && !ids.has(edge.source.nodeId) && !ids.has(edge.target.nodeId)) });
|
|
@@ -533,21 +775,31 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
533
775
|
};
|
|
534
776
|
const paste = (event: ClipboardEvent<HTMLDivElement>) => {
|
|
535
777
|
rest.onPaste?.(event);
|
|
536
|
-
if (event.defaultPrevented || !clipboardTarget(event) || gesture.current || readOnly || !
|
|
778
|
+
if (event.defaultPrevented || !clipboardTarget(event) || gesture.current || readOnly || !canEditNodes || !canEditEdges) return;
|
|
537
779
|
const snapshot = readCanvasClipboard(event.clipboardData.getData("text/plain"));
|
|
538
780
|
if (!snapshot) return;
|
|
539
781
|
event.preventDefault(); event.stopPropagation(); clearConnection();
|
|
540
782
|
const displacement = findCanvasPlacement(snapshot.nodes.flatMap(node => snapshot.footprints?.[node.id]?.length ? snapshot.footprints[node.id] : collisionRects(node)),
|
|
541
783
|
nodes.flatMap(node => collisionRects(node)), nodeGap);
|
|
542
784
|
const pastedNodes = snapshot.nodes.map(node => ({ ...node, position: { x: node.position.x + displacement.x, y: node.position.y + displacement.y } }));
|
|
785
|
+
const next: CanvasGraph = { nodes: [...graph.current.nodes, ...pastedNodes], edges: [...graph.current.edges] };
|
|
786
|
+
const nextEdges = [...next.edges];
|
|
787
|
+
for (const edge of snapshot.edges) {
|
|
788
|
+
if (!valid(edge, { nodes: next.nodes, edges: nextEdges })) return;
|
|
789
|
+
nextEdges.push(edge);
|
|
790
|
+
}
|
|
543
791
|
const before = snapshotCanvasGraph(graph.current, selected);
|
|
544
792
|
const selection = makeCanvasSelection(snapshot.nodes.map(node => node.id), snapshot.edges.map(edge => edge.id));
|
|
545
|
-
publishGraph({ nodes:
|
|
793
|
+
publishGraph({ nodes: next.nodes, edges: nextEdges });
|
|
546
794
|
history.current.record(before, snapshotCanvasGraph(graph.current, selection));
|
|
547
795
|
select(selection);
|
|
796
|
+
keepNodesVisible(pastedNodes);
|
|
797
|
+
};
|
|
798
|
+
function keepNodesVisible(items: readonly CanvasItem[]) {
|
|
799
|
+
if (viewportLocked) return;
|
|
548
800
|
const element = root.current;
|
|
549
|
-
if (element) {
|
|
550
|
-
const bounds =
|
|
801
|
+
if (element && items.length) {
|
|
802
|
+
const bounds = items.flatMap(node => collisionRects(node));
|
|
551
803
|
const visible = bounds.some(body => body.x * viewport.zoom + viewport.x < element.clientWidth && (body.x + body.width) * viewport.zoom + viewport.x > 0
|
|
552
804
|
&& body.y * viewport.zoom + viewport.y < element.clientHeight && (body.y + body.height) * viewport.zoom + viewport.y > 0);
|
|
553
805
|
if (!visible) {
|
|
@@ -556,16 +808,16 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
556
808
|
setViewport({ ...viewport, x: element.clientWidth / 2 - (left + right) / 2 * viewport.zoom, y: element.clientHeight / 2 - (top + bottom) / 2 * viewport.zoom });
|
|
557
809
|
}
|
|
558
810
|
}
|
|
559
|
-
}
|
|
811
|
+
}
|
|
560
812
|
const travelHistory = (redo: boolean) => {
|
|
561
813
|
if (readOnly) return;
|
|
562
|
-
if (gesture.current || pending) { cancelGesture(); return; }
|
|
814
|
+
if (gesture.current || pending || activeDrop.current) { cancelGesture(); return; }
|
|
563
815
|
const snapshot = history.current.peek(redo);
|
|
564
816
|
if (!snapshot) return;
|
|
565
817
|
const restored = restoreCanvasGraph(snapshot, graph.current);
|
|
566
818
|
const nodeChange = canvasGraphSignature({ nodes: restored.nodes, edges: [] }) !== canvasGraphSignature({ nodes: graph.current.nodes, edges: [] });
|
|
567
819
|
const edgeChange = canvasGraphSignature({ nodes: [], edges: restored.edges }) !== canvasGraphSignature({ nodes: [], edges: graph.current.edges });
|
|
568
|
-
if (nodeChange && !
|
|
820
|
+
if (nodeChange && !canEditNodes || edgeChange && !canEditEdges) return;
|
|
569
821
|
history.current.take(redo); settlement.stop(); clearGuides(); clearConnection(); suppressClick.current = true;
|
|
570
822
|
publishGraph(restored); select(restored.selection, true);
|
|
571
823
|
};
|
|
@@ -577,13 +829,13 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
577
829
|
event.preventDefault(); event.stopPropagation(); travelHistory(event.shiftKey); return;
|
|
578
830
|
}
|
|
579
831
|
if (event.key === "Escape") { event.preventDefault(); cancelGesture(); return; }
|
|
580
|
-
if ((event.target as Element).closest("[data-canvas-controls], [data-canvas-port]")) return;
|
|
832
|
+
if ((event.target as Element).closest("[data-canvas-controls], [data-canvas-port], [data-canvas-overlay]")) return;
|
|
581
833
|
if (event.key === "Delete" || event.key === "Backspace") { event.preventDefault(); remove(); return; }
|
|
582
834
|
const element = (event.target as Element).closest<HTMLElement>("[data-canvas-item]");
|
|
583
835
|
const node = nodes.find(n => n.id === element?.dataset.canvasItem);
|
|
584
836
|
if (!node || node.disabled) return;
|
|
585
837
|
if (event.shiftKey && (event.key === "Enter" || event.key === " ")) { event.preventDefault(); event.stopPropagation(); selectNode(node.id, true); return; }
|
|
586
|
-
if (readOnly || !
|
|
838
|
+
if (readOnly || !canEditNodes) return;
|
|
587
839
|
const delta: Record<string, Point> = { ArrowLeft: { x: -1, y: 0 }, ArrowRight: { x: 1, y: 0 }, ArrowUp: { x: 0, y: -1 }, ArrowDown: { x: 0, y: 1 } };
|
|
588
840
|
if (!delta[event.key]) return;
|
|
589
841
|
event.preventDefault(); const step = event.shiftKey ? 24 : 8;
|
|
@@ -595,17 +847,15 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
595
847
|
const setZoom = (value: number) => {
|
|
596
848
|
if (!root.current || gesture.current) return;
|
|
597
849
|
const { width, height } = root.current.getBoundingClientRect();
|
|
598
|
-
setViewport(v => {
|
|
599
|
-
const next = Math.max(.25, Math.min(2, value));
|
|
600
|
-
return { x: width / 2 - (width / 2 - v.x) * next / v.zoom, y: height / 2 - (height / 2 - v.y) * next / v.zoom, zoom: next };
|
|
601
|
-
});
|
|
850
|
+
setViewport(v => zoomViewport(v, value, { x: width / 2, y: height / 2 }));
|
|
602
851
|
};
|
|
603
852
|
const zoomInButton = <IconButton icon={<Icon name="plus" />} aria-label={text.zoomIn} title={text.zoomIn} onClick={() => setZoom(viewport.zoom * 1.2)} disabled={viewport.zoom >= 2} />;
|
|
604
853
|
const zoomOutButton = <IconButton icon={<Icon name="minus" />} aria-label={text.zoomOut} title={text.zoomOut} onClick={() => setZoom(viewport.zoom / 1.2)} disabled={viewport.zoom <= .25} />;
|
|
605
854
|
const from = pending && endpoint(pending);
|
|
606
855
|
const to = candidate && endpoint(candidate);
|
|
607
856
|
return <div {...rest} ref={root} data-slot="canvas" data-background={resolvedBackground} data-panning={panning || undefined}
|
|
608
|
-
data-
|
|
857
|
+
data-viewport-locked={viewportLocked || undefined} data-read-only={readOnly || undefined} data-high-contrast={highContrast || undefined}
|
|
858
|
+
data-connecting={!!pending || undefined} data-pan-ready={!viewportLocked && panReady || undefined} data-selecting={!!marquee || undefined} className={[styles.root, className].filter(Boolean).join(" ")}
|
|
609
859
|
role="region" aria-label={rest["aria-label"] ?? text.canvas} aria-describedby={[rest["aria-describedby"], helpId].filter(Boolean).join(" ")} tabIndex={0}
|
|
610
860
|
onKeyDown={keyDown} onCopy={copy} onPaste={paste}
|
|
611
861
|
onClickCapture={event => { if (suppressClick.current && event.detail > 0) { event.preventDefault(); event.stopPropagation(); suppressClick.current = false; return; } rest.onClickCapture?.(event); }}
|
|
@@ -613,7 +863,9 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
613
863
|
rest.onPointerDownCapture?.(event);
|
|
614
864
|
if (event.defaultPrevented || !event.currentTarget.contains(event.target as Node) || !event.isPrimary || gesture.current) return;
|
|
615
865
|
suppressClick.current = false;
|
|
616
|
-
|
|
866
|
+
invalidateDrop();
|
|
867
|
+
if (viewportLocked) return;
|
|
868
|
+
if ((event.target as Element).closest("[data-canvas-controls], [data-canvas-overlay]")) return;
|
|
617
869
|
if (event.button !== 1 && !(event.button === 0 && spacePressed.current)) return;
|
|
618
870
|
event.preventDefault(); event.stopPropagation(); root.current?.focus({ preventScroll: true }); clearConnection(!!pending);
|
|
619
871
|
suppressClick.current = true; spaceUsedForPan.current ||= spacePressed.current;
|
|
@@ -624,13 +876,20 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
624
876
|
onDragStartCapture={event => { rest.onDragStartCapture?.(event); event.preventDefault(); }}
|
|
625
877
|
onPointerDown={event => {
|
|
626
878
|
if (!event.currentTarget.contains(event.target as Node)) return;
|
|
627
|
-
if (!event.isPrimary || (event.button !== 0 && event.button !== 1) || gesture.current || (event.target as Element).closest("button, [data-slot='canvas-edge'], [data-canvas-item]")) return;
|
|
879
|
+
if (!event.isPrimary || (event.button !== 0 && (viewportLocked || event.button !== 1)) || gesture.current || (event.target as Element).closest("button, [data-slot='canvas-edge'], [data-canvas-item], [data-canvas-overlay]")) return;
|
|
880
|
+
if (viewportLocked && event.pointerType === "touch") {
|
|
881
|
+
clearConnection(!!pending);
|
|
882
|
+
select(null);
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
628
885
|
event.preventDefault(); root.current?.focus({ preventScroll: true }); clearConnection(!!pending);
|
|
629
886
|
if (event.pointerType === "touch") capture(event, { type: "pan", pointerId: event.pointerId, moved: false, start: { x: event.clientX, y: event.clientY }, origin: viewport, clearOnClick: true });
|
|
630
887
|
else capture(event, { type: "marquee", pointerId: event.pointerId, moved: false, start: { x: event.clientX, y: event.clientY }, anchor: position(event), previous: selected, additive: event.shiftKey });
|
|
631
888
|
}}
|
|
632
889
|
style={{ ...rest.style, "--canvas-zoom": viewport.zoom, "--canvas-background-scale": patternScale, "--canvas-grid-x": `${viewport.x}px`, "--canvas-grid-y": `${viewport.y}px` } as CSSProperties}>
|
|
633
|
-
<p id={helpId} className={styles.srOnly}>{text.instructions}
|
|
890
|
+
<p id={helpId} className={styles.srOnly}>{text.instructions}
|
|
891
|
+
{onConnectDrop && !readOnly && canEditNodes && canEditEdges && ` ${text.createFromPort}`}
|
|
892
|
+
</p>
|
|
634
893
|
<span className={styles.srOnly} role="status" aria-live="polite">{announcement}</span>
|
|
635
894
|
<div className={styles.world} style={{ transform: `translate(${viewport.x}px, ${viewport.y}px) scale(${viewport.zoom})` }}>
|
|
636
895
|
<svg className={styles.edges} aria-label={text.canvas}>
|
|
@@ -654,29 +913,54 @@ export function Canvas({ nodes, edges, onNodesChange, onEdgesChange, selection:
|
|
|
654
913
|
from ? <CanvasEdge key={draftId.current ?? "canvas-preview"} source={from} target={to ?? { ...pointer, side: ({ left: "right", right: "left", top: "bottom", bottom: "top" } as const)[from.side] }} obstacles={connectionObstacles(pending?.nodeId, candidate?.nodeId)} cornerRadius={defaultCornerRadius} variant="orthogonal" lineStyle={lineStyle} preview /> : null]}
|
|
655
914
|
</g>
|
|
656
915
|
</svg>
|
|
657
|
-
{visualNodes.map(
|
|
916
|
+
{visualNodes.map(item => {
|
|
917
|
+
const { id, position: at, kind: _kind, portRules: _portRules, ...node } = item;
|
|
658
918
|
const ports = [...new Set(node.ports ?? ["left", "right"] as const)];
|
|
659
919
|
const connected = ports.filter(side => edges.some(e => samePort(e.source, { nodeId: id, side }) || samePort(e.target, { nodeId: id, side })));
|
|
660
920
|
return <div key={id} data-canvas-item={id} data-settling={!!settlement.positions[id] || undefined} data-dragging={!!dragging && selectedNodeIds.has(id) || undefined} className={styles.node}
|
|
661
|
-
style={{ left: at.x, top: at.y }} onPointerDown={e => nodeDown(e,
|
|
921
|
+
style={{ left: at.x, top: at.y }} onPointerDown={e => nodeDown(e, item)}
|
|
662
922
|
onPointerEnter={() => setHoveredNode(id)} onPointerLeave={() => setHoveredNode(null)}
|
|
663
923
|
onFocusCapture={() => setFocusedNode(id)} onBlurCapture={e => { if (!e.currentTarget.contains(e.relatedTarget as Node)) setFocusedNode(null); }}
|
|
664
924
|
>
|
|
665
925
|
<CanvasNode {...node} ref={element => { if (element) nodeElements.current.set(id, element); else nodeElements.current.delete(id); }}
|
|
666
926
|
connectedPorts={connected} portsVisible={!!pending || hoveredNode === id || focusedNode === id}
|
|
667
927
|
selected={selectedNodeIds.has(id)} onSelect={() => { clearConnection(); selectNode(id); }} />
|
|
668
|
-
{!readOnly &&
|
|
928
|
+
{!readOnly && canEditEdges && !node.disabled && ports.map(side => {
|
|
669
929
|
const port = { nodeId: id, side }, offset = metrics[id]?.ports[side];
|
|
670
930
|
if (!offset) return null;
|
|
931
|
+
const canAdd = onConnectDrop && canEditNodes && canUseCanvasPort(nodes, edges, port, "source");
|
|
671
932
|
return <Button key={side} variant="ghost" data-canvas-port={side} data-node-id={id} className={styles.port}
|
|
672
933
|
style={{ left: offset.x, top: offset.y }} aria-label={text.port(node.title, side)} aria-pressed={!!pending && samePort(pending, port)}
|
|
934
|
+
aria-keyshortcuts={canAdd ? "Shift+Enter" : undefined}
|
|
673
935
|
data-target={candidate && samePort(candidate, port) || undefined} onPointerDown={e => portDown(e, port)}
|
|
674
|
-
|
|
675
|
-
|
|
936
|
+
onKeyDown={e => {
|
|
937
|
+
if (e.shiftKey && e.key === "Enter" && requestConnectionDrop(port)) e.preventDefault();
|
|
938
|
+
}}
|
|
939
|
+
onClick={e => {
|
|
940
|
+
if (e.detail !== 0 || gesture.current) return;
|
|
941
|
+
if (pending) { if (!connect(pending, port) && samePort(pending, port)) clearConnection(true); }
|
|
942
|
+
else if (canUseCanvasPort(graph.current.nodes, graph.current.edges, port, "source")) {
|
|
943
|
+
startConnection(port); setAnnouncement(text.connecting);
|
|
944
|
+
}
|
|
945
|
+
}} />;
|
|
676
946
|
})}
|
|
677
947
|
</div>;
|
|
678
948
|
})}
|
|
679
949
|
</div>
|
|
950
|
+
{renderOverlay && <div className={styles.overlay} data-canvas-overlay>
|
|
951
|
+
{renderOverlay({
|
|
952
|
+
portPosition: port => {
|
|
953
|
+
const at = endpoint(port);
|
|
954
|
+
return at ? { x: viewport.x + at.x * viewport.zoom, y: viewport.y + at.y * viewport.zoom } : null;
|
|
955
|
+
},
|
|
956
|
+
canPlaceConnectionDrop: (source, node, targetSide) => {
|
|
957
|
+
const point = connectionDropPoint(source);
|
|
958
|
+
const placement = point && dropPlacement(node, targetSide, point);
|
|
959
|
+
return !!placement && isCanvasPlacementFree(placement.rects, visualNodes.flatMap(item => collisionRects(item)), nodeGap);
|
|
960
|
+
},
|
|
961
|
+
hoveredNodeId: hoveredNode, focusedNodeId: focusedNode, selection: selected, requestConnectionDrop,
|
|
962
|
+
})}
|
|
963
|
+
</div>}
|
|
680
964
|
{guides.length > 0 && <svg className={styles.guides} data-canvas-guides aria-hidden="true" focusable="false">
|
|
681
965
|
{guides.map(guide => <line key={guide.axis} data-axis={guide.axis}
|
|
682
966
|
x1={(guide.axis === "x" ? guide.at : guide.from) * viewport.zoom + viewport.x}
|