@runfusion/fusion 0.22.0 → 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +30071 -20735
- package/dist/client/assets/AgentDetailView-BwJaLqZh.css +1 -0
- package/dist/client/assets/AgentDetailView-gy_5SUj2.js +18 -0
- package/dist/client/assets/AgentsView-BkB9FiMT.js +29 -0
- package/dist/client/assets/AgentsView-CV3vm7Qk.css +1 -0
- package/dist/client/assets/ChatView-B_-B8fqu.js +1 -0
- package/dist/client/assets/ChatView-DwJAd5G1.css +1 -0
- package/dist/client/assets/{DevServerView-l8RCyL2k.js → DevServerView-BkvtjZBa.js} +1 -1
- package/dist/client/assets/{DirectoryPicker-CS1dwqcC.js → DirectoryPicker-BK-KbnhP.js} +1 -1
- package/dist/client/assets/{DocumentsView-DmthQWDZ.js → DocumentsView-BEg1CQAk.js} +1 -1
- package/dist/client/assets/{DocumentsView-BrhyOdeE.css → DocumentsView-gv4zG3aT.css} +1 -1
- package/dist/client/assets/EvalsView-Berf9bQm.js +1 -0
- package/dist/client/assets/EvalsView-CUNJ1TLc.css +1 -0
- package/dist/client/assets/{agentSkills-DDHJnrkn.css → ExperimentalAgentOnboardingModal-B-APN_lM.css} +1 -1
- package/dist/client/assets/ExperimentalAgentOnboardingModal-jcInE50G.js +499 -0
- package/dist/client/assets/InsightsView-B0J4mhzV.css +1 -0
- package/dist/client/assets/InsightsView-BX5bSF1J.js +11 -0
- package/dist/client/assets/{MemoryView-CPwlKnUI.js → MemoryView-CKElJY_3.js} +2 -2
- package/dist/client/assets/NodesView-DLUOBLf6.js +14 -0
- package/dist/client/assets/NodesView-DT4pXowv.css +1 -0
- package/dist/client/assets/{PiExtensionsManager-j8rPXqmB.js → PiExtensionsManager-COlJf0Kx.js} +2 -2
- package/dist/client/assets/PluginManager-CfW55BF4.js +1 -0
- package/dist/client/assets/PluginManager-DtRQXia5.css +1 -0
- package/dist/client/assets/{ResearchView-D9DNJYDq.js → ResearchView-B256Lr8I.js} +1 -1
- package/dist/client/assets/SettingsModal-BeA_nQtW.js +31 -0
- package/dist/client/assets/SettingsModal-DzsLquBu.css +1 -0
- package/dist/client/assets/{SettingsModal-fxvTFLtR.js → SettingsModal-yRqM4DV8.js} +1 -1
- package/dist/client/assets/SetupWizardModal-uUZk3TKT.js +1 -0
- package/dist/client/assets/{SkillsView-Ddf0YL8z.js → SkillsView-CP8JX0P_.js} +1 -1
- package/dist/client/assets/TodoView-Cx9cVhq7.css +1 -0
- package/dist/client/assets/TodoView-DCRIkDZ-.js +6 -0
- package/dist/client/assets/createLucideIcon-BazL2hk5.js +21 -0
- package/dist/client/assets/dashboard-view-BkTMSZYn.css +1 -0
- package/dist/client/assets/dashboard-view-CyWN-d02.js +63 -0
- package/dist/client/assets/dashboard-view-lR7YYmSC.js +21 -0
- package/dist/client/assets/{folder-open-BiJpmnaT.js → folder-open-DHjELt8-.js} +1 -1
- package/dist/client/assets/index-CQyVRLOb.js +692 -0
- package/dist/client/assets/index-CxA2Nn0_.css +1 -0
- package/dist/client/assets/projectDetection-G3XuxD2X.js +1 -0
- package/dist/client/assets/{star-BwRZmiuZ.js → star-DYesq1AV.js} +1 -1
- package/dist/client/assets/{upload-D4NwZhPp.js → upload-DTWF3Db5.js} +1 -1
- package/dist/client/assets/{users-DNISDtI1.js → users--syrel4l.js} +1 -1
- package/dist/client/index.html +12 -20
- package/dist/client/theme-data.css +106 -0
- package/dist/client/version.json +1 -1
- package/dist/droid-cli/package.json +1 -1
- package/dist/extension.js +17072 -9627
- package/dist/pi-claude-cli/package.json +1 -1
- package/dist/plugins/fusion-plugin-cursor-runtime/bundled.js +218 -0
- package/dist/plugins/fusion-plugin-cursor-runtime/manifest.json +6 -0
- package/dist/plugins/fusion-plugin-cursor-runtime/package.json +11 -0
- package/dist/plugins/fusion-plugin-dependency-graph/manifest.json +1 -1
- package/dist/plugins/fusion-plugin-dependency-graph/package.json +6 -4
- package/dist/plugins/fusion-plugin-dependency-graph/src/DependencyGraph.css +58 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/DependencyGraph.tsx +301 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/GraphHighlight.css +27 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/GraphTaskNode.css +157 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/GraphTaskNode.tsx +126 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/GraphToolbar.css +35 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/GraphToolbar.tsx +36 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/DependencyGraph.highlighting.test.tsx +112 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/DependencyGraph.persistence.test.tsx +115 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/DependencyGraph.test.tsx +128 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/GraphTaskNode.drag.test.tsx +82 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/GraphTaskNode.test.tsx +307 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/GraphToolbar.test.tsx +60 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/edges.test.tsx +75 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/filtering.test.tsx +62 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/filters.test.ts +78 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/graphPositionStorage.test.ts +95 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/host-integration.test.ts +74 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/index.test.ts +58 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/interactions.test.tsx +121 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/layout.test.ts +70 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/persistence.test.tsx +89 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/useGraphData.test.ts +86 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/useGraphInteraction.test.ts +167 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/useGraphPositions.test.ts +66 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/useNodeDrag.test.ts +81 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/dashboard-interop.d.ts +35 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/dashboard-view.tsx +19 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/edges.tsx +70 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/filters.ts +8 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/hooks/__tests__/useDependencyChain.test.ts +53 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/hooks/useDependencyChain.ts +60 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/hooks/useGraphPositions.ts +45 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/hooks/useNodeDrag.ts +114 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/index.ts +1 -2
- package/dist/plugins/fusion-plugin-dependency-graph/src/layout.ts +91 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/styles/drag.css +15 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/types.ts +21 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/useGraphData.ts +17 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/useGraphInteraction.ts +292 -0
- package/dist/plugins/fusion-plugin-dependency-graph/src/utils/graphPositionStorage.ts +65 -0
- package/dist/plugins/fusion-plugin-droid-runtime/bundled.js +136680 -0
- package/dist/plugins/fusion-plugin-droid-runtime/manifest.json +13 -0
- package/dist/plugins/fusion-plugin-droid-runtime/mcp-schema-server.cjs +49 -0
- package/dist/plugins/fusion-plugin-droid-runtime/package.json +11 -0
- package/dist/plugins/fusion-plugin-hermes-runtime/bundled.js +176 -7
- package/dist/plugins/fusion-plugin-hermes-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-openclaw-runtime/bundled.js +93 -6
- package/dist/plugins/fusion-plugin-openclaw-runtime/mcp-schema-server.cjs +59 -0
- package/dist/plugins/fusion-plugin-openclaw-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-paperclip-runtime/package.json +1 -1
- package/dist/plugins/fusion-plugin-reports/manifest.json +33 -0
- package/dist/plugins/fusion-plugin-reports/package.json +26 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/manifest.test.ts +51 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/review-panel.test.ts +166 -0
- package/dist/plugins/fusion-plugin-reports/src/__tests__/settings.test.ts +157 -0
- package/dist/plugins/fusion-plugin-reports/src/index.ts +41 -0
- package/dist/plugins/fusion-plugin-reports/src/review-panel.ts +294 -0
- package/dist/plugins/fusion-plugin-reports/src/review-types.ts +75 -0
- package/dist/plugins/fusion-plugin-reports/src/settings.ts +105 -0
- package/dist/plugins/fusion-plugin-roadmap/manifest.json +16 -0
- package/dist/plugins/fusion-plugin-roadmap/package.json +48 -0
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/api-client.test.ts +101 -0
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/index.test.ts +92 -0
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/roadmap-routes.test.ts +48 -0
- package/dist/plugins/fusion-plugin-roadmap/src/__tests__/roadmap-suggestions.test.ts +31 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/RoadmapsView.css +1299 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/RoadmapsView.tsx +2559 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/__tests__/RoadmapsView.test.tsx +1144 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/__tests__/useRoadmaps.test.ts +1756 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/api.ts +70 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/test-setup.ts +7 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/types.ts +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useConfirm.ts +8 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useRoadmaps.ts +1188 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard/useViewportMode.ts +20 -0
- package/dist/plugins/fusion-plugin-roadmap/src/dashboard-view.tsx +6 -0
- package/dist/plugins/fusion-plugin-roadmap/src/index.ts +74 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-routes.ts +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-schema.ts +41 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-suggestions.d.ts +15 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-suggestions.ts +15 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.d.ts +283 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.d.ts.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.js +21 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.js.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/roadmap-types.ts +310 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.d.ts +5 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.d.ts.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.js +361 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.js.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-routes.ts +408 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.d.ts +68 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.d.ts.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.js +300 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.js.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/routes/roadmap-suggestions.ts +381 -0
- package/dist/plugins/fusion-plugin-roadmap/src/server/index.d.ts +3 -0
- package/dist/plugins/fusion-plugin-roadmap/src/server/index.ts +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-handoff.test.ts +445 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-ordering.test.ts +334 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/__tests__/roadmap-store.test.ts +1318 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-handoff.ts +163 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.d.ts +37 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.d.ts.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.js +188 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.js.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-ordering.ts +311 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.d.ts +299 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.d.ts.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.js +765 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.js.map +1 -0
- package/dist/plugins/fusion-plugin-roadmap/src/store/roadmap-store.ts +1001 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/manifest.json +8 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/package.json +34 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/__tests__/auth-state.test.ts +99 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/__tests__/connection.test.ts +145 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/__tests__/index.test.ts +216 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/__tests__/reply.test.ts +52 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/auth-state.ts +89 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/connection.ts +253 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/index.ts +262 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/qrcode.d.ts +1 -0
- package/dist/plugins/fusion-plugin-whatsapp-chat/src/reply.ts +37 -0
- package/package.json +2 -2
- package/skill/fusion/SKILL.md +2 -2
- package/skill/fusion/references/engine-tools.md +8 -2
- package/skill/fusion/references/extension-tools.md +39 -0
- package/skill/fusion/references/fusion-capabilities.md +3 -0
- package/dist/client/assets/AgentDetailView-BKKpbp1S.js +0 -18
- package/dist/client/assets/AgentDetailView-CeO_1MK7.css +0 -1
- package/dist/client/assets/AgentsView-BRXFmrcJ.js +0 -527
- package/dist/client/assets/AgentsView-Bs03ptrd.css +0 -1
- package/dist/client/assets/ChatView-D7L2e_qu.js +0 -1
- package/dist/client/assets/InsightsView-AWo5o_81.css +0 -1
- package/dist/client/assets/InsightsView-DvXpMKmH.js +0 -11
- package/dist/client/assets/NodesView-BLlfUfsy.js +0 -14
- package/dist/client/assets/NodesView-fXqDk9ur.css +0 -1
- package/dist/client/assets/PluginManager-DA_T0GHn.css +0 -1
- package/dist/client/assets/PluginManager-pW6RMz5z.js +0 -1
- package/dist/client/assets/RoadmapsView-Djc_X35v.js +0 -6
- package/dist/client/assets/SettingsModal-BWe0KrGY.css +0 -1
- package/dist/client/assets/SettingsModal-WGCF_pk8.js +0 -31
- package/dist/client/assets/SetupWizardModal-tG_MF_nA.js +0 -1
- package/dist/client/assets/agentSkills-EwIwBlG8.js +0 -1
- package/dist/client/assets/index-D6ebxTPF.css +0 -1
- package/dist/client/assets/index-DYDLmOcK.js +0 -694
- package/dist/plugins/fusion-plugin-dependency-graph/src/DependencyGraphView.css +0 -132
- package/dist/plugins/fusion-plugin-dependency-graph/src/DependencyGraphView.tsx +0 -428
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/DependencyGraphView.test.tsx +0 -261
- package/dist/plugins/fusion-plugin-dependency-graph/src/__tests__/storage.test.ts +0 -31
- package/dist/plugins/fusion-plugin-dependency-graph/src/storage.ts +0 -23
- /package/dist/client/assets/{RoadmapsView-DdGlfuu-.css → dashboard-view-DdGlfuu-.css} +0 -0
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useCallback, useEffect, useState } from "react";
|
|
2
|
+
import { clearPositions, loadPositions, savePositions, type NodePositions } from "../utils/graphPositionStorage";
|
|
3
|
+
|
|
4
|
+
function filterVisiblePositions(positions: NodePositions, visibleTaskIds: Set<string>): NodePositions {
|
|
5
|
+
const filtered: NodePositions = {};
|
|
6
|
+
for (const [taskId, position] of Object.entries(positions)) {
|
|
7
|
+
if (visibleTaskIds.has(taskId)) {
|
|
8
|
+
filtered[taskId] = position;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return filtered;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function useGraphPositions({
|
|
15
|
+
projectId,
|
|
16
|
+
visibleTaskIds,
|
|
17
|
+
}: {
|
|
18
|
+
projectId: string | undefined;
|
|
19
|
+
visibleTaskIds: Set<string>;
|
|
20
|
+
}): {
|
|
21
|
+
savedPositions: NodePositions | null;
|
|
22
|
+
persistPositions: (positions: NodePositions) => void;
|
|
23
|
+
clearSavedPositions: () => void;
|
|
24
|
+
} {
|
|
25
|
+
const [savedPositions, setSavedPositions] = useState<NodePositions | null>(null);
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
setSavedPositions(loadPositions(projectId));
|
|
29
|
+
}, [projectId]);
|
|
30
|
+
|
|
31
|
+
const persistPositions = useCallback(
|
|
32
|
+
(positions: NodePositions) => {
|
|
33
|
+
savePositions(positions, visibleTaskIds, projectId);
|
|
34
|
+
setSavedPositions(filterVisiblePositions(positions, visibleTaskIds));
|
|
35
|
+
},
|
|
36
|
+
[projectId, visibleTaskIds],
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
const clearSavedPositions = useCallback(() => {
|
|
40
|
+
clearPositions(projectId);
|
|
41
|
+
setSavedPositions(null);
|
|
42
|
+
}, [projectId]);
|
|
43
|
+
|
|
44
|
+
return { savedPositions, persistPositions, clearSavedPositions };
|
|
45
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { useCallback, useMemo, useRef, useState } from "react";
|
|
2
|
+
import type { MouseEvent as ReactMouseEvent, PointerEvent as ReactPointerEvent } from "react";
|
|
3
|
+
import type { GraphPosition } from "../types";
|
|
4
|
+
|
|
5
|
+
const DRAG_THRESHOLD_PX = 4;
|
|
6
|
+
|
|
7
|
+
interface UseNodeDragOptions {
|
|
8
|
+
taskId: string;
|
|
9
|
+
position: GraphPosition;
|
|
10
|
+
scale: number;
|
|
11
|
+
onPositionChange: (taskId: string, position: GraphPosition) => void;
|
|
12
|
+
onDragStateChange?: (isDragging: boolean) => void;
|
|
13
|
+
onDragEnd?: () => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PendingState {
|
|
17
|
+
pointerId: number;
|
|
18
|
+
startPointer: { x: number; y: number };
|
|
19
|
+
startPosition: GraphPosition;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function useNodeDrag({ taskId, position, scale, onPositionChange, onDragStateChange, onDragEnd }: UseNodeDragOptions) {
|
|
23
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
24
|
+
const pendingRef = useRef<PendingState | null>(null);
|
|
25
|
+
const positionRef = useRef(position);
|
|
26
|
+
const suppressClickRef = useRef(false);
|
|
27
|
+
|
|
28
|
+
positionRef.current = position;
|
|
29
|
+
|
|
30
|
+
const endDrag = useCallback((dragging: boolean) => {
|
|
31
|
+
pendingRef.current = null;
|
|
32
|
+
setIsDragging(false);
|
|
33
|
+
if (dragging) {
|
|
34
|
+
onDragStateChange?.(false);
|
|
35
|
+
onDragEnd?.();
|
|
36
|
+
suppressClickRef.current = true;
|
|
37
|
+
}
|
|
38
|
+
}, [onDragEnd, onDragStateChange]);
|
|
39
|
+
|
|
40
|
+
const onPointerDown = useCallback((event: ReactPointerEvent<HTMLElement>) => {
|
|
41
|
+
if (!event.isPrimary) return;
|
|
42
|
+
event.stopPropagation();
|
|
43
|
+
const currentTarget = event.currentTarget;
|
|
44
|
+
if (typeof currentTarget.setPointerCapture === "function") {
|
|
45
|
+
currentTarget.setPointerCapture(event.pointerId);
|
|
46
|
+
}
|
|
47
|
+
pendingRef.current = {
|
|
48
|
+
pointerId: event.pointerId,
|
|
49
|
+
startPointer: { x: event.clientX, y: event.clientY },
|
|
50
|
+
startPosition: positionRef.current,
|
|
51
|
+
};
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const onPointerMove = useCallback((event: ReactPointerEvent<HTMLElement>) => {
|
|
55
|
+
const pending = pendingRef.current;
|
|
56
|
+
if (!pending || pending.pointerId !== event.pointerId) return;
|
|
57
|
+
event.stopPropagation();
|
|
58
|
+
|
|
59
|
+
const deltaX = event.clientX - pending.startPointer.x;
|
|
60
|
+
const deltaY = event.clientY - pending.startPointer.y;
|
|
61
|
+
const distance = Math.hypot(deltaX, deltaY);
|
|
62
|
+
|
|
63
|
+
if (!isDragging && distance >= DRAG_THRESHOLD_PX) {
|
|
64
|
+
setIsDragging(true);
|
|
65
|
+
onDragStateChange?.(true);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (distance < DRAG_THRESHOLD_PX) return;
|
|
69
|
+
|
|
70
|
+
const safeScale = scale > 0 ? scale : 1;
|
|
71
|
+
onPositionChange(taskId, {
|
|
72
|
+
x: pending.startPosition.x + deltaX / safeScale,
|
|
73
|
+
y: pending.startPosition.y + deltaY / safeScale,
|
|
74
|
+
});
|
|
75
|
+
}, [isDragging, onDragStateChange, onPositionChange, scale, taskId]);
|
|
76
|
+
|
|
77
|
+
const onPointerUp = useCallback((event: ReactPointerEvent<HTMLElement>) => {
|
|
78
|
+
const pending = pendingRef.current;
|
|
79
|
+
if (!pending || pending.pointerId !== event.pointerId) return;
|
|
80
|
+
event.stopPropagation();
|
|
81
|
+
if (typeof event.currentTarget.hasPointerCapture === "function" && event.currentTarget.hasPointerCapture(event.pointerId) && typeof event.currentTarget.releasePointerCapture === "function") {
|
|
82
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
83
|
+
}
|
|
84
|
+
endDrag(isDragging);
|
|
85
|
+
}, [endDrag, isDragging]);
|
|
86
|
+
|
|
87
|
+
const onPointerCancel = useCallback((event: ReactPointerEvent<HTMLElement>) => {
|
|
88
|
+
const pending = pendingRef.current;
|
|
89
|
+
if (!pending || pending.pointerId !== event.pointerId) return;
|
|
90
|
+
event.stopPropagation();
|
|
91
|
+
if (typeof event.currentTarget.hasPointerCapture === "function" && event.currentTarget.hasPointerCapture(event.pointerId) && typeof event.currentTarget.releasePointerCapture === "function") {
|
|
92
|
+
event.currentTarget.releasePointerCapture(event.pointerId);
|
|
93
|
+
}
|
|
94
|
+
endDrag(isDragging);
|
|
95
|
+
}, [endDrag, isDragging]);
|
|
96
|
+
|
|
97
|
+
const onClickCapture = useCallback((event: ReactMouseEvent<HTMLElement>) => {
|
|
98
|
+
if (!suppressClickRef.current) return;
|
|
99
|
+
suppressClickRef.current = false;
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
event.stopPropagation();
|
|
102
|
+
}, []);
|
|
103
|
+
|
|
104
|
+
return useMemo(() => ({
|
|
105
|
+
isDragging,
|
|
106
|
+
onPointerDown,
|
|
107
|
+
onPointerMove,
|
|
108
|
+
onPointerUp,
|
|
109
|
+
onPointerCancel,
|
|
110
|
+
onClickCapture,
|
|
111
|
+
}), [isDragging, onClickCapture, onPointerCancel, onPointerDown, onPointerMove, onPointerUp]);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export const __internal = { DRAG_THRESHOLD_PX };
|
|
@@ -13,7 +13,7 @@ const plugin = definePlugin({
|
|
|
13
13
|
{
|
|
14
14
|
viewId: "graph",
|
|
15
15
|
label: "Graph",
|
|
16
|
-
componentPath: "./
|
|
16
|
+
componentPath: "./dashboard-view",
|
|
17
17
|
icon: "Network",
|
|
18
18
|
placement: "more",
|
|
19
19
|
order: 40,
|
|
@@ -22,4 +22,3 @@ const plugin = definePlugin({
|
|
|
22
22
|
});
|
|
23
23
|
|
|
24
24
|
export default plugin;
|
|
25
|
-
export { DependencyGraphView } from "./DependencyGraphView";
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { GraphData, GraphPosition } from "./types";
|
|
2
|
+
|
|
3
|
+
export interface LayoutOptions {
|
|
4
|
+
nodeWidth?: number;
|
|
5
|
+
nodeHeight?: number;
|
|
6
|
+
horizontalGap?: number;
|
|
7
|
+
verticalGap?: number;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const DEFAULT_LAYOUT_OPTIONS: Required<LayoutOptions> = {
|
|
11
|
+
nodeWidth: 280,
|
|
12
|
+
nodeHeight: 100,
|
|
13
|
+
horizontalGap: 40,
|
|
14
|
+
verticalGap: 80,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function computeAutoLayout(
|
|
18
|
+
graphData: GraphData,
|
|
19
|
+
options?: LayoutOptions,
|
|
20
|
+
): Map<string, GraphPosition> {
|
|
21
|
+
const settings = { ...DEFAULT_LAYOUT_OPTIONS, ...options };
|
|
22
|
+
const nodeIds = graphData.nodes.map((node) => node.task.id);
|
|
23
|
+
if (nodeIds.length === 0) return new Map();
|
|
24
|
+
|
|
25
|
+
const dependentsByDependency = new Map<string, string[]>();
|
|
26
|
+
const inDegree = new Map<string, number>();
|
|
27
|
+
|
|
28
|
+
for (const id of nodeIds) {
|
|
29
|
+
inDegree.set(id, 0);
|
|
30
|
+
dependentsByDependency.set(id, []);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
for (const edge of graphData.edges) {
|
|
34
|
+
if (!inDegree.has(edge.source) || !inDegree.has(edge.target)) continue;
|
|
35
|
+
dependentsByDependency.get(edge.target)?.push(edge.source);
|
|
36
|
+
inDegree.set(edge.source, (inDegree.get(edge.source) ?? 0) + 1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const queue = nodeIds.filter((id) => (inDegree.get(id) ?? 0) === 0);
|
|
40
|
+
const topologicalOrder: string[] = [];
|
|
41
|
+
|
|
42
|
+
while (queue.length > 0) {
|
|
43
|
+
const current = queue.shift()!;
|
|
44
|
+
topologicalOrder.push(current);
|
|
45
|
+
for (const dependent of dependentsByDependency.get(current) ?? []) {
|
|
46
|
+
const nextInDegree = (inDegree.get(dependent) ?? 0) - 1;
|
|
47
|
+
inDegree.set(dependent, nextInDegree);
|
|
48
|
+
if (nextInDegree === 0) queue.push(dependent);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (const id of nodeIds) {
|
|
53
|
+
if (!topologicalOrder.includes(id)) topologicalOrder.push(id);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const depthByNode = new Map<string, number>();
|
|
57
|
+
for (const id of topologicalOrder) {
|
|
58
|
+
const parents = graphData.edges.filter((edge) => edge.source === id).map((edge) => edge.target);
|
|
59
|
+
let depth = 0;
|
|
60
|
+
for (const parent of parents) {
|
|
61
|
+
depth = Math.max(depth, (depthByNode.get(parent) ?? 0) + 1);
|
|
62
|
+
}
|
|
63
|
+
depthByNode.set(id, depth);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const layers = new Map<number, string[]>();
|
|
67
|
+
for (const id of nodeIds) {
|
|
68
|
+
const depth = depthByNode.get(id) ?? 0;
|
|
69
|
+
const layer = layers.get(depth) ?? [];
|
|
70
|
+
layer.push(id);
|
|
71
|
+
layers.set(depth, layer);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const positions = new Map<string, GraphPosition>();
|
|
75
|
+
const sortedDepths = Array.from(layers.keys()).sort((a, b) => a - b);
|
|
76
|
+
|
|
77
|
+
for (const depth of sortedDepths) {
|
|
78
|
+
const layer = layers.get(depth) ?? [];
|
|
79
|
+
layer.sort();
|
|
80
|
+
const layerWidth = layer.length * settings.nodeWidth + Math.max(0, layer.length - 1) * settings.horizontalGap;
|
|
81
|
+
const startX = -layerWidth / 2;
|
|
82
|
+
|
|
83
|
+
layer.forEach((id, index) => {
|
|
84
|
+
const x = startX + index * (settings.nodeWidth + settings.horizontalGap);
|
|
85
|
+
const y = depth * (settings.nodeHeight + settings.verticalGap);
|
|
86
|
+
positions.set(id, { x, y });
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return positions;
|
|
91
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
.graph-node--draggable {
|
|
2
|
+
cursor: grab;
|
|
3
|
+
touch-action: none;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.graph-node--dragging {
|
|
7
|
+
z-index: 3;
|
|
8
|
+
cursor: grabbing;
|
|
9
|
+
box-shadow: var(--shadow-lg);
|
|
10
|
+
transform: scale(1.02);
|
|
11
|
+
transition:
|
|
12
|
+
transform var(--transition-fast),
|
|
13
|
+
box-shadow var(--transition-fast),
|
|
14
|
+
z-index var(--transition-fast);
|
|
15
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Task } from "@fusion/core";
|
|
2
|
+
|
|
3
|
+
export interface GraphPosition {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export interface GraphNode {
|
|
9
|
+
task: Task;
|
|
10
|
+
position?: GraphPosition;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface GraphEdge {
|
|
14
|
+
source: string;
|
|
15
|
+
target: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface GraphData {
|
|
19
|
+
nodes: GraphNode[];
|
|
20
|
+
edges: GraphEdge[];
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useMemo } from "react";
|
|
2
|
+
import type { Task } from "@fusion/core";
|
|
3
|
+
import type { GraphData, GraphNode } from "./types";
|
|
4
|
+
|
|
5
|
+
export function useGraphData(tasks: Task[]): GraphData {
|
|
6
|
+
return useMemo(() => {
|
|
7
|
+
const nodes: GraphNode[] = tasks.map((task) => ({ task }));
|
|
8
|
+
const taskIds = new Set(tasks.map((task) => task.id));
|
|
9
|
+
const edges = tasks.flatMap((task) =>
|
|
10
|
+
(task.dependencies ?? [])
|
|
11
|
+
.filter((dependencyId) => taskIds.has(dependencyId))
|
|
12
|
+
.map((dependencyId) => ({ source: task.id, target: dependencyId })),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
return { nodes, edges };
|
|
16
|
+
}, [tasks]);
|
|
17
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import type { KeyboardEvent as ReactKeyboardEvent } from "react";
|
|
3
|
+
import type { LayoutOptions } from "./layout";
|
|
4
|
+
import type { GraphPosition } from "./types";
|
|
5
|
+
|
|
6
|
+
const MIN_ZOOM = 0.1;
|
|
7
|
+
const MAX_ZOOM = 3;
|
|
8
|
+
const FIT_PADDING = 40;
|
|
9
|
+
const TRANSITION_TIMEOUT_MS = 200;
|
|
10
|
+
|
|
11
|
+
interface PointerPoint {
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface PinchState {
|
|
17
|
+
distance: number;
|
|
18
|
+
zoom: number;
|
|
19
|
+
pan: PointerPoint;
|
|
20
|
+
midpoint: PointerPoint;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function clamp(value: number, min: number, max: number): number {
|
|
24
|
+
return Math.min(max, Math.max(min, value));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isEditableTarget(target: EventTarget | null): boolean {
|
|
28
|
+
if (!(target instanceof HTMLElement)) return false;
|
|
29
|
+
const tagName = target.tagName.toLowerCase();
|
|
30
|
+
return target.isContentEditable || tagName === "input" || tagName === "textarea" || tagName === "select";
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export function useGraphInteraction() {
|
|
34
|
+
const [pan, setPan] = useState<PointerPoint>({ x: 0, y: 0 });
|
|
35
|
+
const [zoom, setZoom] = useState(1);
|
|
36
|
+
const [transitioning, setTransitioning] = useState(false);
|
|
37
|
+
|
|
38
|
+
const panRef = useRef(pan);
|
|
39
|
+
const zoomRef = useRef(zoom);
|
|
40
|
+
const transitionTimerRef = useRef<number | null>(null);
|
|
41
|
+
const dragStateRef = useRef<{ start: PointerPoint; panStart: PointerPoint } | null>(null);
|
|
42
|
+
const pointersRef = useRef<Map<number, PointerPoint>>(new Map());
|
|
43
|
+
const pinchRef = useRef<PinchState | null>(null);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
panRef.current = pan;
|
|
47
|
+
}, [pan]);
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
zoomRef.current = zoom;
|
|
51
|
+
}, [zoom]);
|
|
52
|
+
|
|
53
|
+
useEffect(() => () => {
|
|
54
|
+
if (transitionTimerRef.current !== null) {
|
|
55
|
+
window.clearTimeout(transitionTimerRef.current);
|
|
56
|
+
}
|
|
57
|
+
}, []);
|
|
58
|
+
|
|
59
|
+
const transform = useMemo(() => `translate(${pan.x}px, ${pan.y}px) scale(${zoom})`, [pan.x, pan.y, zoom]);
|
|
60
|
+
const zoomPercent = useMemo(() => Math.round(zoom * 100), [zoom]);
|
|
61
|
+
|
|
62
|
+
const setAnimate = useCallback((enabled: boolean) => {
|
|
63
|
+
if (!enabled) {
|
|
64
|
+
if (transitionTimerRef.current !== null) {
|
|
65
|
+
window.clearTimeout(transitionTimerRef.current);
|
|
66
|
+
transitionTimerRef.current = null;
|
|
67
|
+
}
|
|
68
|
+
setTransitioning(false);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
setTransitioning(true);
|
|
73
|
+
if (transitionTimerRef.current !== null) {
|
|
74
|
+
window.clearTimeout(transitionTimerRef.current);
|
|
75
|
+
}
|
|
76
|
+
transitionTimerRef.current = window.setTimeout(() => {
|
|
77
|
+
setTransitioning(false);
|
|
78
|
+
transitionTimerRef.current = null;
|
|
79
|
+
}, TRANSITION_TIMEOUT_MS);
|
|
80
|
+
}, []);
|
|
81
|
+
|
|
82
|
+
const clampPan = useCallback((nextPan: PointerPoint, viewportWidth: number, viewportHeight: number) => ({
|
|
83
|
+
x: clamp(nextPan.x, -viewportWidth, viewportWidth),
|
|
84
|
+
y: clamp(nextPan.y, -viewportHeight, viewportHeight),
|
|
85
|
+
}), []);
|
|
86
|
+
|
|
87
|
+
const zoomAtPoint = useCallback((
|
|
88
|
+
nextZoomRaw: number,
|
|
89
|
+
anchor: PointerPoint,
|
|
90
|
+
viewportWidth: number,
|
|
91
|
+
viewportHeight: number,
|
|
92
|
+
) => {
|
|
93
|
+
const currentZoom = zoomRef.current;
|
|
94
|
+
const currentPan = panRef.current;
|
|
95
|
+
const nextZoom = clamp(nextZoomRaw, MIN_ZOOM, MAX_ZOOM);
|
|
96
|
+
const scaleRatio = nextZoom / currentZoom;
|
|
97
|
+
|
|
98
|
+
const nextPan = clampPan({
|
|
99
|
+
x: anchor.x - (anchor.x - currentPan.x) * scaleRatio,
|
|
100
|
+
y: anchor.y - (anchor.y - currentPan.y) * scaleRatio,
|
|
101
|
+
}, viewportWidth, viewportHeight);
|
|
102
|
+
|
|
103
|
+
setZoom(nextZoom);
|
|
104
|
+
setPan(nextPan);
|
|
105
|
+
}, [clampPan]);
|
|
106
|
+
|
|
107
|
+
const zoomByFactor = useCallback((factor: number, viewportWidth: number, viewportHeight: number, anchor?: PointerPoint) => {
|
|
108
|
+
setAnimate(false);
|
|
109
|
+
const point = anchor ?? { x: viewportWidth / 2, y: viewportHeight / 2 };
|
|
110
|
+
zoomAtPoint(zoomRef.current * factor, point, viewportWidth, viewportHeight);
|
|
111
|
+
}, [setAnimate, zoomAtPoint]);
|
|
112
|
+
|
|
113
|
+
const zoomIn = useCallback((viewportWidth?: number, viewportHeight?: number) => {
|
|
114
|
+
if (viewportWidth && viewportHeight) {
|
|
115
|
+
zoomByFactor(1.2, viewportWidth, viewportHeight);
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
setZoom((current) => clamp(current + 0.1, MIN_ZOOM, MAX_ZOOM));
|
|
119
|
+
}, [zoomByFactor]);
|
|
120
|
+
|
|
121
|
+
const zoomOut = useCallback((viewportWidth?: number, viewportHeight?: number) => {
|
|
122
|
+
if (viewportWidth && viewportHeight) {
|
|
123
|
+
zoomByFactor(1 / 1.2, viewportWidth, viewportHeight);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
setZoom((current) => clamp(current - 0.1, MIN_ZOOM, MAX_ZOOM));
|
|
127
|
+
}, [zoomByFactor]);
|
|
128
|
+
|
|
129
|
+
const resetView = useCallback(() => {
|
|
130
|
+
setAnimate(true);
|
|
131
|
+
setPan({ x: 0, y: 0 });
|
|
132
|
+
setZoom(1);
|
|
133
|
+
}, [setAnimate]);
|
|
134
|
+
|
|
135
|
+
const fitToGraph = useCallback((
|
|
136
|
+
positions: Map<string, GraphPosition>,
|
|
137
|
+
viewportWidth: number,
|
|
138
|
+
viewportHeight: number,
|
|
139
|
+
layoutOptions?: LayoutOptions,
|
|
140
|
+
) => {
|
|
141
|
+
setAnimate(true);
|
|
142
|
+
if (positions.size === 0) {
|
|
143
|
+
setPan({ x: 0, y: 0 });
|
|
144
|
+
setZoom(1);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const nodeWidth = layoutOptions?.nodeWidth ?? 280;
|
|
149
|
+
const nodeHeight = layoutOptions?.nodeHeight ?? 100;
|
|
150
|
+
|
|
151
|
+
const entries = Array.from(positions.values());
|
|
152
|
+
const minX = Math.min(...entries.map((p) => p.x));
|
|
153
|
+
const minY = Math.min(...entries.map((p) => p.y));
|
|
154
|
+
const maxX = Math.max(...entries.map((p) => p.x + nodeWidth));
|
|
155
|
+
const maxY = Math.max(...entries.map((p) => p.y + nodeHeight));
|
|
156
|
+
|
|
157
|
+
const graphWidth = Math.max(1, maxX - minX);
|
|
158
|
+
const graphHeight = Math.max(1, maxY - minY);
|
|
159
|
+
const availableWidth = Math.max(1, viewportWidth - FIT_PADDING * 2);
|
|
160
|
+
const availableHeight = Math.max(1, viewportHeight - FIT_PADDING * 2);
|
|
161
|
+
const nextZoom = clamp(Math.min(availableWidth / graphWidth, availableHeight / graphHeight), MIN_ZOOM, MAX_ZOOM);
|
|
162
|
+
|
|
163
|
+
const panX = (viewportWidth - graphWidth * nextZoom) / 2 - minX * nextZoom;
|
|
164
|
+
const panY = (viewportHeight - graphHeight * nextZoom) / 2 - minY * nextZoom;
|
|
165
|
+
|
|
166
|
+
setZoom(nextZoom);
|
|
167
|
+
setPan(clampPan({ x: panX, y: panY }, viewportWidth, viewportHeight));
|
|
168
|
+
}, [clampPan, setAnimate]);
|
|
169
|
+
|
|
170
|
+
const onPointerDown = useCallback((pointerId: number, point: PointerPoint) => {
|
|
171
|
+
pointersRef.current.set(pointerId, point);
|
|
172
|
+
if (pointersRef.current.size === 2) {
|
|
173
|
+
const [a, b] = Array.from(pointersRef.current.values());
|
|
174
|
+
pinchRef.current = {
|
|
175
|
+
distance: Math.hypot(a.x - b.x, a.y - b.y),
|
|
176
|
+
zoom: zoomRef.current,
|
|
177
|
+
pan: panRef.current,
|
|
178
|
+
midpoint: { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 },
|
|
179
|
+
};
|
|
180
|
+
dragStateRef.current = null;
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
dragStateRef.current = { start: point, panStart: panRef.current };
|
|
184
|
+
}, []);
|
|
185
|
+
|
|
186
|
+
const onPointerMove = useCallback((pointerId: number, point: PointerPoint, viewportWidth: number, viewportHeight: number) => {
|
|
187
|
+
if (pointersRef.current.has(pointerId)) pointersRef.current.set(pointerId, point);
|
|
188
|
+
|
|
189
|
+
if (pointersRef.current.size >= 2 && pinchRef.current) {
|
|
190
|
+
setAnimate(false);
|
|
191
|
+
const [a, b] = Array.from(pointersRef.current.values());
|
|
192
|
+
const distance = Math.hypot(a.x - b.x, a.y - b.y);
|
|
193
|
+
const factor = distance / Math.max(1, pinchRef.current.distance);
|
|
194
|
+
const midpoint = { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
195
|
+
const nextZoom = clamp(pinchRef.current.zoom * factor, MIN_ZOOM, MAX_ZOOM);
|
|
196
|
+
const ratio = nextZoom / pinchRef.current.zoom;
|
|
197
|
+
const nextPan = clampPan({
|
|
198
|
+
x: midpoint.x - (pinchRef.current.midpoint.x - pinchRef.current.pan.x) * ratio,
|
|
199
|
+
y: midpoint.y - (pinchRef.current.midpoint.y - pinchRef.current.pan.y) * ratio,
|
|
200
|
+
}, viewportWidth, viewportHeight);
|
|
201
|
+
setZoom(nextZoom);
|
|
202
|
+
setPan(nextPan);
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const dragState = dragStateRef.current;
|
|
207
|
+
if (!dragState) return;
|
|
208
|
+
setAnimate(false);
|
|
209
|
+
const nextPan = {
|
|
210
|
+
x: dragState.panStart.x + (point.x - dragState.start.x),
|
|
211
|
+
y: dragState.panStart.y + (point.y - dragState.start.y),
|
|
212
|
+
};
|
|
213
|
+
setPan(clampPan(nextPan, viewportWidth, viewportHeight));
|
|
214
|
+
}, [clampPan, setAnimate]);
|
|
215
|
+
|
|
216
|
+
const onPointerUp = useCallback((pointerId: number) => {
|
|
217
|
+
pointersRef.current.delete(pointerId);
|
|
218
|
+
if (pointersRef.current.size < 2) pinchRef.current = null;
|
|
219
|
+
if (pointersRef.current.size === 0) dragStateRef.current = null;
|
|
220
|
+
}, []);
|
|
221
|
+
|
|
222
|
+
const onWheelZoom = useCallback((
|
|
223
|
+
deltaY: number,
|
|
224
|
+
point: PointerPoint,
|
|
225
|
+
viewportWidth: number,
|
|
226
|
+
viewportHeight: number,
|
|
227
|
+
) => {
|
|
228
|
+
const factor = deltaY < 0 ? 1.1 : 0.9;
|
|
229
|
+
setAnimate(false);
|
|
230
|
+
zoomAtPoint(zoomRef.current * factor, point, viewportWidth, viewportHeight);
|
|
231
|
+
}, [setAnimate, zoomAtPoint]);
|
|
232
|
+
|
|
233
|
+
const handleKeyDown = useCallback((
|
|
234
|
+
event: ReactKeyboardEvent,
|
|
235
|
+
viewportWidth: number,
|
|
236
|
+
viewportHeight: number,
|
|
237
|
+
positions: Map<string, GraphPosition>,
|
|
238
|
+
layoutOptions?: LayoutOptions,
|
|
239
|
+
) => {
|
|
240
|
+
if (isEditableTarget(event.target)) return;
|
|
241
|
+
|
|
242
|
+
const modifier = event.metaKey || event.ctrlKey;
|
|
243
|
+
if (event.key === "Escape") {
|
|
244
|
+
event.preventDefault();
|
|
245
|
+
resetView();
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!modifier) return;
|
|
250
|
+
|
|
251
|
+
if (event.key === "=" || event.key === "+") {
|
|
252
|
+
event.preventDefault();
|
|
253
|
+
zoomByFactor(1.2, viewportWidth, viewportHeight);
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (event.key === "-") {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
zoomByFactor(1 / 1.2, viewportWidth, viewportHeight);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (event.key === "0") {
|
|
264
|
+
event.preventDefault();
|
|
265
|
+
resetView();
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if ((event.key === "f" || event.key === "F") && event.shiftKey) {
|
|
270
|
+
event.preventDefault();
|
|
271
|
+
fitToGraph(positions, viewportWidth, viewportHeight, layoutOptions);
|
|
272
|
+
}
|
|
273
|
+
}, [fitToGraph, resetView, zoomByFactor]);
|
|
274
|
+
|
|
275
|
+
return {
|
|
276
|
+
pan,
|
|
277
|
+
zoom,
|
|
278
|
+
zoomPercent,
|
|
279
|
+
transform,
|
|
280
|
+
transitioning,
|
|
281
|
+
zoomIn,
|
|
282
|
+
zoomOut,
|
|
283
|
+
resetView,
|
|
284
|
+
fitToGraph,
|
|
285
|
+
setAnimate,
|
|
286
|
+
onPointerDown,
|
|
287
|
+
onPointerMove,
|
|
288
|
+
onPointerUp,
|
|
289
|
+
onWheelZoom,
|
|
290
|
+
handleKeyDown,
|
|
291
|
+
};
|
|
292
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getScopedItem, removeScopedItem, setScopedItem } from "@fusion/dashboard/app/utils/projectStorage";
|
|
2
|
+
|
|
3
|
+
export type NodePositions = Record<string, { x: number; y: number }>;
|
|
4
|
+
|
|
5
|
+
const STORAGE_KEY = "fusion-plugin-dependency-graph:positions";
|
|
6
|
+
|
|
7
|
+
function isPosition(value: unknown): value is { x: number; y: number } {
|
|
8
|
+
if (!value || typeof value !== "object") return false;
|
|
9
|
+
const candidate = value as { x?: unknown; y?: unknown };
|
|
10
|
+
return typeof candidate.x === "number" && Number.isFinite(candidate.x) && typeof candidate.y === "number" && Number.isFinite(candidate.y);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function loadPositions(projectId?: string): NodePositions {
|
|
14
|
+
const raw = getScopedItem(STORAGE_KEY, projectId);
|
|
15
|
+
if (!raw) return {};
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const parsed = JSON.parse(raw) as Record<string, unknown>;
|
|
19
|
+
if (!parsed || typeof parsed !== "object") return {};
|
|
20
|
+
|
|
21
|
+
const result: NodePositions = {};
|
|
22
|
+
for (const [taskId, value] of Object.entries(parsed)) {
|
|
23
|
+
if (isPosition(value)) {
|
|
24
|
+
result[taskId] = value;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return result;
|
|
29
|
+
} catch {
|
|
30
|
+
return {};
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function savePositions(positions: NodePositions, visibleTaskIds: Set<string>, projectId?: string): void {
|
|
35
|
+
const filtered: NodePositions = {};
|
|
36
|
+
for (const [taskId, position] of Object.entries(positions)) {
|
|
37
|
+
if (visibleTaskIds.has(taskId) && isPosition(position)) {
|
|
38
|
+
filtered[taskId] = position;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
setScopedItem(STORAGE_KEY, JSON.stringify(filtered), projectId);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function clearPositions(projectId?: string): void {
|
|
46
|
+
removeScopedItem(STORAGE_KEY, projectId);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function mergePositions(autoLayoutPositions: NodePositions, savedPositions: NodePositions, visibleTaskIds: Set<string>): NodePositions {
|
|
50
|
+
const merged: NodePositions = {};
|
|
51
|
+
|
|
52
|
+
for (const [taskId, position] of Object.entries(autoLayoutPositions)) {
|
|
53
|
+
if (visibleTaskIds.has(taskId) && isPosition(position)) {
|
|
54
|
+
merged[taskId] = position;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const [taskId, position] of Object.entries(savedPositions)) {
|
|
59
|
+
if (visibleTaskIds.has(taskId) && isPosition(position)) {
|
|
60
|
+
merged[taskId] = position;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return merged;
|
|
65
|
+
}
|