@transitrix/diagrams 1.5.0 → 1.7.6
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/capability-map/CapabilityCardNode.d.ts +19 -0
- package/dist/capability-map/CapabilityCardNode.js +66 -0
- package/dist/capability-map/CapabilityMapView.d.ts +59 -0
- package/dist/capability-map/CapabilityMapView.js +204 -0
- package/dist/capability-map/CapabilityRootNode.d.ts +12 -0
- package/dist/capability-map/CapabilityRootNode.js +23 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.d.ts +1 -0
- package/dist/capability-map/__tests__/CapabilityMapView.test.js +217 -0
- package/dist/capability-map/__tests__/address.test.d.ts +1 -0
- package/dist/capability-map/__tests__/address.test.js +49 -0
- package/dist/capability-map/__tests__/dsm-layout.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-layout.test.js +46 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-mutations.test.js +125 -0
- package/dist/capability-map/__tests__/dsm-validate.test.d.ts +1 -0
- package/dist/capability-map/__tests__/dsm-validate.test.js +56 -0
- package/dist/capability-map/address.d.ts +12 -0
- package/dist/capability-map/address.js +48 -0
- package/dist/capability-map/dsm-layout.d.ts +9 -0
- package/dist/capability-map/dsm-layout.js +125 -0
- package/dist/capability-map/dsm-mutations.d.ts +28 -0
- package/dist/capability-map/dsm-mutations.js +196 -0
- package/dist/capability-map/dsm-schema.d.ts +71 -0
- package/dist/capability-map/dsm-schema.js +14 -0
- package/dist/capability-map/dsm-theme.d.ts +20 -0
- package/dist/capability-map/dsm-theme.js +36 -0
- package/dist/capability-map/dsm-validate.d.ts +2 -0
- package/dist/capability-map/dsm-validate.js +93 -0
- package/dist/capability-map/index.d.ts +9 -0
- package/dist/capability-map/index.js +6 -0
- package/dist/codex/__tests__/example.test.d.ts +1 -0
- package/dist/codex/__tests__/example.test.js +33 -0
- package/dist/codex/__tests__/validate.test.d.ts +1 -0
- package/dist/codex/__tests__/validate.test.js +68 -0
- package/dist/codex/index.d.ts +4 -0
- package/dist/codex/index.js +2 -0
- package/dist/codex/types.d.ts +7 -0
- package/dist/codex/types.js +8 -0
- package/dist/codex/validate.d.ts +11 -0
- package/dist/codex/validate.js +103 -0
- package/dist/compliance/__tests__/canon-catalog.test.d.ts +1 -0
- package/dist/compliance/__tests__/canon-catalog.test.js +60 -0
- package/dist/compliance/__tests__/trace.test.d.ts +1 -0
- package/dist/compliance/__tests__/trace.test.js +144 -0
- package/dist/compliance/__tests__/view-resolution.test.d.ts +1 -0
- package/dist/compliance/__tests__/view-resolution.test.js +59 -0
- package/dist/compliance/canon-catalog.d.ts +19 -0
- package/dist/compliance/canon-catalog.js +59 -0
- package/dist/compliance/classify.js +7 -1
- package/dist/compliance/coverage-metric.d.ts +12 -0
- package/dist/compliance/coverage-metric.js +35 -0
- package/dist/compliance/impact.d.ts +7 -1
- package/dist/compliance/impact.js +53 -0
- package/dist/compliance/index.d.ts +8 -5
- package/dist/compliance/index.js +4 -2
- package/dist/compliance/reverse-index.js +4 -1
- package/dist/compliance/trace.d.ts +26 -0
- package/dist/compliance/trace.js +89 -0
- package/dist/compliance/types.d.ts +94 -1
- package/dist/constraint/__tests__/example.test.d.ts +1 -0
- package/dist/constraint/__tests__/example.test.js +14 -0
- package/dist/constraint/__tests__/validate.test.d.ts +1 -0
- package/dist/constraint/__tests__/validate.test.js +58 -0
- package/dist/constraint/index.d.ts +4 -0
- package/dist/constraint/index.js +2 -0
- package/dist/constraint/types.d.ts +4 -0
- package/dist/constraint/types.js +2 -0
- package/dist/constraint/validate.d.ts +7 -0
- package/dist/constraint/validate.js +115 -0
- package/dist/fgca/__tests__/parse-canonical.test.js +31 -0
- package/dist/fgca/parse-canonical.d.ts +1 -1
- package/dist/fgca/parse-canonical.js +18 -4
- package/dist/goals/GoalNode.d.ts +19 -0
- package/dist/goals/GoalNode.js +96 -0
- package/dist/goals/GoalTreeView.d.ts +59 -0
- package/dist/goals/GoalTreeView.js +245 -0
- package/dist/goals/__tests__/GoalTreeView.test.d.ts +1 -0
- package/dist/goals/__tests__/GoalTreeView.test.js +337 -0
- package/dist/goals/__tests__/mutations.test.js +39 -0
- package/dist/goals/__tests__/parse-canonical.test.js +2 -0
- package/dist/goals/index.d.ts +3 -0
- package/dist/goals/index.js +1 -0
- package/dist/goals/layout.js +2 -1
- package/dist/goals/mutations.js +6 -6
- package/dist/goals/parse-canonical.d.ts +5 -0
- package/dist/goals/parse-canonical.js +5 -0
- package/dist/goals/theme.d.ts +22 -0
- package/dist/goals/theme.js +32 -0
- package/dist/goals/types.d.ts +2 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/repo-validate/types.js +2 -3
- package/dist/webview/__tests__/render-goals.test.js +17 -3
- package/dist/webview/render-goals.js +2 -1
- package/package.json +4 -1
- package/src/capability-map/CapabilityCardNode.tsx +146 -0
- package/src/capability-map/CapabilityMapView.tsx +331 -0
- package/src/capability-map/CapabilityRootNode.tsx +38 -0
- package/src/capability-map/__tests__/CapabilityMapView.test.tsx +232 -0
- package/src/capability-map/__tests__/address.test.ts +59 -0
- package/src/capability-map/__tests__/dsm-layout.test.ts +52 -0
- package/src/capability-map/__tests__/dsm-mutations.test.ts +141 -0
- package/src/capability-map/__tests__/dsm-validate.test.ts +65 -0
- package/src/capability-map/address.ts +48 -0
- package/src/capability-map/dsm-layout.ts +142 -0
- package/src/capability-map/dsm-mutations.ts +208 -0
- package/src/capability-map/dsm-schema.ts +80 -0
- package/src/capability-map/dsm-theme.ts +53 -0
- package/src/capability-map/dsm-validate.ts +103 -0
- package/src/capability-map/index.ts +35 -0
- package/src/codex/__tests__/example.test.ts +40 -0
- package/src/codex/__tests__/validate.test.ts +84 -0
- package/src/codex/index.ts +4 -0
- package/src/codex/types.ts +13 -0
- package/src/codex/validate.ts +125 -0
- package/src/compliance/__tests__/canon-catalog.test.ts +68 -0
- package/src/compliance/__tests__/trace.test.ts +157 -0
- package/src/compliance/__tests__/view-resolution.test.ts +80 -0
- package/src/compliance/canon-catalog.ts +76 -0
- package/src/compliance/classify.ts +7 -1
- package/src/compliance/coverage-metric.ts +50 -0
- package/src/compliance/impact.ts +67 -1
- package/src/compliance/index.ts +16 -1
- package/src/compliance/reverse-index.ts +3 -1
- package/src/compliance/trace.ts +118 -0
- package/src/compliance/types.ts +101 -1
- package/src/constraint/__tests__/example.test.ts +19 -0
- package/src/constraint/__tests__/validate.test.ts +68 -0
- package/src/constraint/index.ts +4 -0
- package/src/constraint/types.ts +5 -0
- package/src/constraint/validate.ts +131 -0
- package/src/fgca/__tests__/parse-canonical.test.ts +34 -0
- package/src/fgca/parse-canonical.ts +17 -4
- package/src/goals/GoalNode.tsx +219 -0
- package/src/goals/GoalTreeView.tsx +384 -0
- package/src/goals/__tests__/GoalTreeView.test.tsx +361 -0
- package/src/goals/__tests__/mutations.test.ts +42 -0
- package/src/goals/__tests__/parse-canonical.test.ts +2 -0
- package/src/goals/index.ts +4 -0
- package/src/goals/layout.ts +2 -1
- package/src/goals/mutations.ts +6 -6
- package/src/goals/parse-canonical.ts +6 -0
- package/src/goals/theme.ts +54 -0
- package/src/goals/types.ts +2 -0
- package/src/index.ts +29 -1
- package/src/repo-validate/types.ts +2 -3
- package/src/webview/__tests__/render-goals.test.ts +17 -3
- package/src/webview/render-goals.ts +2 -1
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
import React, { useCallback, useMemo, useState, useEffect } from 'react';
|
|
2
|
+
import ReactFlow, {
|
|
3
|
+
Controls,
|
|
4
|
+
MiniMap,
|
|
5
|
+
Background,
|
|
6
|
+
ConnectionLineType,
|
|
7
|
+
useNodesState,
|
|
8
|
+
useEdgesState,
|
|
9
|
+
type Node,
|
|
10
|
+
type Edge,
|
|
11
|
+
type NodeMouseHandler,
|
|
12
|
+
type NodeDragHandler,
|
|
13
|
+
} from 'reactflow';
|
|
14
|
+
import 'reactflow/dist/style.css';
|
|
15
|
+
import type { Factor, Goal, GoalTree, GoalTreeLayout, LayoutOptions } from './types.js';
|
|
16
|
+
import { layoutGoalTree } from './layout.js';
|
|
17
|
+
import { reparent, addChild, deleteWithDescendants, moveToBacklog, restoreFromBacklog } from './mutations.js';
|
|
18
|
+
import type { ThemeTokens } from './theme.js';
|
|
19
|
+
import { resolveTheme } from './theme.js';
|
|
20
|
+
import GoalNode, { type GoalNodeData } from './GoalNode.js';
|
|
21
|
+
|
|
22
|
+
export type { ThemeTokens } from './theme.js';
|
|
23
|
+
|
|
24
|
+
export interface GoalTreeViewProps {
|
|
25
|
+
tree: GoalTree;
|
|
26
|
+
layout?: GoalTreeLayout;
|
|
27
|
+
layoutOptions?: LayoutOptions;
|
|
28
|
+
theme?: ThemeTokens;
|
|
29
|
+
readOnly?: boolean;
|
|
30
|
+
showBacklog?: boolean;
|
|
31
|
+
defaultBacklogOpen?: boolean;
|
|
32
|
+
showMiniMap?: boolean;
|
|
33
|
+
onChange?: (event: GoalTreeChange) => void;
|
|
34
|
+
onEditRequest?: (goal: Goal) => void;
|
|
35
|
+
onFactorClick?: (factor: Factor) => void;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type GoalTreeChange =
|
|
39
|
+
| { kind: 'reparent'; sourceId: number; targetId: number; result: GoalTree }
|
|
40
|
+
| { kind: 'addChild'; parentId: number; newGoal: Goal; result: GoalTree }
|
|
41
|
+
| { kind: 'delete'; id: number; result: GoalTree }
|
|
42
|
+
| { kind: 'moveToBacklog'; id: number; result: GoalTree }
|
|
43
|
+
| { kind: 'restoreFromBacklog'; id: number; newParentId: number; result: GoalTree };
|
|
44
|
+
|
|
45
|
+
const BACKLOG_DRAG_MIME = 'application/x-transitrix-goal-id';
|
|
46
|
+
const nodeTypes = { goalNode: GoalNode };
|
|
47
|
+
|
|
48
|
+
/** Where a card was dropped, as classified from the pointer position at drag-stop. */
|
|
49
|
+
export type DropTarget = { kind: 'node'; id: number } | { kind: 'backlog' } | null;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Pure decision: given where a dragged card was dropped, compute the mutation
|
|
53
|
+
* and the GoalTreeChange to report (or null for a no-op drop). Kept separate
|
|
54
|
+
* from the DOM/pointer-event glue in onNodeDragStop so the mutation-selection
|
|
55
|
+
* logic — which card wins reparent vs moveToBacklog vs a refused mutation —
|
|
56
|
+
* is unit-testable without needing a real drag gesture through reactflow's
|
|
57
|
+
* internal, DOM-measurement-gated dragging.
|
|
58
|
+
*/
|
|
59
|
+
export function computeDragOutcome(tree: GoalTree, sourceId: number, dropTarget: DropTarget): GoalTreeChange | null {
|
|
60
|
+
if (!dropTarget) return null;
|
|
61
|
+
if (dropTarget.kind === 'backlog') {
|
|
62
|
+
const mutation = moveToBacklog(tree, sourceId);
|
|
63
|
+
if (!mutation.ok || !mutation.result) return null;
|
|
64
|
+
return { kind: 'moveToBacklog', id: sourceId, result: mutation.result };
|
|
65
|
+
}
|
|
66
|
+
if (dropTarget.id === sourceId) return null;
|
|
67
|
+
const mutation = reparent(tree, sourceId, dropTarget.id);
|
|
68
|
+
if (!mutation.ok || !mutation.result) return null;
|
|
69
|
+
return { kind: 'reparent', sourceId, targetId: dropTarget.id, result: mutation.result };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Goals reachable from a root (level 0 or parent_id 0) via valid parent_id chains. */
|
|
73
|
+
function partitionCanvasAndBacklog(goals: Goal[]): { canvas: Goal[]; backlog: Goal[] } {
|
|
74
|
+
const children = new Map<number, Goal[]>();
|
|
75
|
+
for (const g of goals) {
|
|
76
|
+
if (!children.has(g.parent_id)) children.set(g.parent_id, []);
|
|
77
|
+
children.get(g.parent_id)!.push(g);
|
|
78
|
+
}
|
|
79
|
+
const roots = goals.filter((g) => g.level === 0 || g.parent_id === 0);
|
|
80
|
+
const reachable = new Set<number>();
|
|
81
|
+
const stack = [...roots.map((r) => r.id)];
|
|
82
|
+
while (stack.length > 0) {
|
|
83
|
+
const id = stack.pop()!;
|
|
84
|
+
if (reachable.has(id)) continue;
|
|
85
|
+
reachable.add(id);
|
|
86
|
+
for (const child of children.get(id) ?? []) stack.push(child.id);
|
|
87
|
+
}
|
|
88
|
+
const canvas: Goal[] = [];
|
|
89
|
+
const backlog: Goal[] = [];
|
|
90
|
+
for (const g of goals) {
|
|
91
|
+
if (reachable.has(g.id)) canvas.push(g);
|
|
92
|
+
else backlog.push(g); // unreachable from any root — broken/orphaned parent chain
|
|
93
|
+
}
|
|
94
|
+
return { canvas, backlog };
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function GoalTreeViewInner({
|
|
98
|
+
tree,
|
|
99
|
+
layout: layoutProp,
|
|
100
|
+
layoutOptions,
|
|
101
|
+
theme: themeProp,
|
|
102
|
+
readOnly = false,
|
|
103
|
+
showBacklog = false,
|
|
104
|
+
defaultBacklogOpen = true,
|
|
105
|
+
showMiniMap = false,
|
|
106
|
+
onChange,
|
|
107
|
+
onEditRequest,
|
|
108
|
+
onFactorClick,
|
|
109
|
+
}: GoalTreeViewProps): React.ReactElement {
|
|
110
|
+
const theme = useMemo(() => resolveTheme(themeProp), [themeProp]);
|
|
111
|
+
const [collapsedIds, setCollapsedIds] = useState<Set<number>>(new Set());
|
|
112
|
+
const [hoveredId, setHoveredId] = useState<number | null>(null);
|
|
113
|
+
const [isBacklogOpen, setIsBacklogOpen] = useState(defaultBacklogOpen);
|
|
114
|
+
|
|
115
|
+
const { canvas: canvasGoals, backlog: backlogGoals } = useMemo(
|
|
116
|
+
() => partitionCanvasAndBacklog(tree.goals),
|
|
117
|
+
[tree.goals],
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const layout = useMemo<GoalTreeLayout>(() => {
|
|
121
|
+
if (layoutProp) return layoutProp;
|
|
122
|
+
const hideCollapsed = [...(layoutOptions?.hideCollapsed ?? []), ...collapsedIds];
|
|
123
|
+
return layoutGoalTree(
|
|
124
|
+
{ goal_types: tree.goal_types, goals: canvasGoals },
|
|
125
|
+
{ ...layoutOptions, hideCollapsed },
|
|
126
|
+
);
|
|
127
|
+
}, [layoutProp, layoutOptions, collapsedIds, tree.goal_types, canvasGoals]);
|
|
128
|
+
|
|
129
|
+
const onAddChild = useCallback(
|
|
130
|
+
(parentId: number, parentLevel: number) => {
|
|
131
|
+
if (readOnly) return;
|
|
132
|
+
const before = new Set(tree.goals.map((g) => g.id));
|
|
133
|
+
const mutation = addChild(tree, parentId, { name: 'New goal', type: '', level: parentLevel + 1, parent_id: parentId });
|
|
134
|
+
if (!mutation.ok || !mutation.result) return;
|
|
135
|
+
const newGoal = mutation.result.goals.find((g) => !before.has(g.id));
|
|
136
|
+
if (!newGoal) return;
|
|
137
|
+
onChange?.({ kind: 'addChild', parentId, newGoal, result: mutation.result });
|
|
138
|
+
},
|
|
139
|
+
[tree, readOnly, onChange],
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const onDeleteNode = useCallback(
|
|
143
|
+
(id: number) => {
|
|
144
|
+
if (readOnly) return;
|
|
145
|
+
const mutation = deleteWithDescendants(tree, id);
|
|
146
|
+
if (!mutation.ok || !mutation.result) return;
|
|
147
|
+
onChange?.({ kind: 'delete', id, result: mutation.result });
|
|
148
|
+
},
|
|
149
|
+
[tree, readOnly, onChange],
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const onRestoreFromBacklog = useCallback(
|
|
153
|
+
(id: number, newParentId: number) => {
|
|
154
|
+
if (readOnly) return;
|
|
155
|
+
const mutation = restoreFromBacklog(tree, id, newParentId);
|
|
156
|
+
if (!mutation.ok || !mutation.result) return;
|
|
157
|
+
onChange?.({ kind: 'restoreFromBacklog', id, newParentId, result: mutation.result });
|
|
158
|
+
},
|
|
159
|
+
[tree, readOnly, onChange],
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
const onToggleCollapse = useCallback((id: number) => {
|
|
163
|
+
setCollapsedIds((prev) => {
|
|
164
|
+
const next = new Set(prev);
|
|
165
|
+
if (next.has(id)) next.delete(id);
|
|
166
|
+
else next.add(id);
|
|
167
|
+
return next;
|
|
168
|
+
});
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
const buildNodes = useCallback((): Node<GoalNodeData>[] => {
|
|
172
|
+
return layout.nodes.map((n) => ({
|
|
173
|
+
id: String(n.id),
|
|
174
|
+
type: 'goalNode',
|
|
175
|
+
position: { x: n.x, y: n.y },
|
|
176
|
+
draggable: !readOnly,
|
|
177
|
+
data: {
|
|
178
|
+
goal: n.data,
|
|
179
|
+
theme,
|
|
180
|
+
readOnly,
|
|
181
|
+
isDropTarget: hoveredId === n.id,
|
|
182
|
+
hasHiddenChildren: n.hasHiddenChildren,
|
|
183
|
+
isCollapsed: collapsedIds.has(n.id),
|
|
184
|
+
onAddChild,
|
|
185
|
+
onDelete: onDeleteNode,
|
|
186
|
+
onToggleCollapse,
|
|
187
|
+
onFactorClick,
|
|
188
|
+
},
|
|
189
|
+
}));
|
|
190
|
+
}, [layout.nodes, theme, readOnly, hoveredId, collapsedIds, onAddChild, onDeleteNode, onToggleCollapse, onFactorClick]);
|
|
191
|
+
|
|
192
|
+
const buildEdges = useCallback((): Edge[] => {
|
|
193
|
+
return layout.edges.map((e) => ({
|
|
194
|
+
id: `e${e.source}-${e.target}`,
|
|
195
|
+
source: String(e.source),
|
|
196
|
+
target: String(e.target),
|
|
197
|
+
type: 'default',
|
|
198
|
+
style: { stroke: theme.edgeColor, strokeWidth: theme.edgeWidth },
|
|
199
|
+
}));
|
|
200
|
+
}, [layout.edges, theme]);
|
|
201
|
+
|
|
202
|
+
const [nodes, setNodes, onNodesChange] = useNodesState<GoalNodeData>(buildNodes());
|
|
203
|
+
const [edges, setEdges, onEdgesChange] = useEdgesState(buildEdges());
|
|
204
|
+
|
|
205
|
+
// Re-sync whenever the underlying layout/theme/interaction state changes —
|
|
206
|
+
// tree/layout are host-controlled props, not owned by this component.
|
|
207
|
+
useEffect(() => {
|
|
208
|
+
setNodes(buildNodes());
|
|
209
|
+
setEdges(buildEdges());
|
|
210
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
211
|
+
}, [layout, theme, readOnly, hoveredId, collapsedIds]);
|
|
212
|
+
|
|
213
|
+
const checkIntersection = useCallback(
|
|
214
|
+
(a: Node<GoalNodeData>, b: Node<GoalNodeData>): boolean => {
|
|
215
|
+
const midX = a.position.x + 125;
|
|
216
|
+
const midY = a.position.y + 40;
|
|
217
|
+
return midX > b.position.x && midX < b.position.x + 250 && midY > b.position.y && midY < b.position.y + 80;
|
|
218
|
+
},
|
|
219
|
+
[],
|
|
220
|
+
);
|
|
221
|
+
|
|
222
|
+
const onNodeDrag: NodeDragHandler = useCallback(
|
|
223
|
+
(_event, node) => {
|
|
224
|
+
if (readOnly) return;
|
|
225
|
+
const hit = nodes.find((n) => n.id !== node.id && checkIntersection(node as Node<GoalNodeData>, n));
|
|
226
|
+
setHoveredId(hit ? Number(hit.id) : null);
|
|
227
|
+
},
|
|
228
|
+
[readOnly, nodes, checkIntersection],
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
const onNodeDragStop: NodeDragHandler = useCallback(
|
|
232
|
+
(event, node) => {
|
|
233
|
+
if (readOnly) {
|
|
234
|
+
setHoveredId(null);
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const sourceId = Number(node.id);
|
|
238
|
+
const mouseEvent = event as unknown as MouseEvent;
|
|
239
|
+
const dropEl = typeof document !== 'undefined' && 'clientX' in mouseEvent
|
|
240
|
+
? document.elementFromPoint(mouseEvent.clientX, mouseEvent.clientY)
|
|
241
|
+
: null;
|
|
242
|
+
const dropTarget: DropTarget = dropEl?.closest('[data-goaltree-backlog-zone]')
|
|
243
|
+
? { kind: 'backlog' }
|
|
244
|
+
: hoveredId != null ? { kind: 'node', id: hoveredId } : null;
|
|
245
|
+
const change = computeDragOutcome(tree, sourceId, dropTarget);
|
|
246
|
+
if (change) onChange?.(change);
|
|
247
|
+
setHoveredId(null);
|
|
248
|
+
},
|
|
249
|
+
[readOnly, hoveredId, tree, onChange],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const onNodeDoubleClick: NodeMouseHandler = useCallback(
|
|
253
|
+
(_event, node) => {
|
|
254
|
+
const goal = tree.goals.find((g) => g.id === Number(node.id));
|
|
255
|
+
if (goal) onEditRequest?.(goal);
|
|
256
|
+
},
|
|
257
|
+
[tree.goals, onEditRequest],
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
const onBacklogItemDragStart = useCallback((event: React.DragEvent, goalId: number) => {
|
|
261
|
+
event.dataTransfer.setData(BACKLOG_DRAG_MIME, String(goalId));
|
|
262
|
+
event.dataTransfer.effectAllowed = 'move';
|
|
263
|
+
}, []);
|
|
264
|
+
|
|
265
|
+
const onCanvasDragOver = useCallback(
|
|
266
|
+
(event: React.DragEvent) => {
|
|
267
|
+
if (readOnly) return;
|
|
268
|
+
event.preventDefault();
|
|
269
|
+
},
|
|
270
|
+
[readOnly],
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
const onCanvasDrop = useCallback(
|
|
274
|
+
(event: React.DragEvent) => {
|
|
275
|
+
if (readOnly) return;
|
|
276
|
+
event.preventDefault();
|
|
277
|
+
const idStr = event.dataTransfer.getData(BACKLOG_DRAG_MIME);
|
|
278
|
+
if (!idStr) return;
|
|
279
|
+
const goalId = Number(idStr);
|
|
280
|
+
const targetEl = document.elementFromPoint(event.clientX, event.clientY);
|
|
281
|
+
const nodeEl = targetEl?.closest('.react-flow__node');
|
|
282
|
+
const targetIdAttr = nodeEl?.getAttribute('data-id');
|
|
283
|
+
if (targetIdAttr == null) return;
|
|
284
|
+
onRestoreFromBacklog(goalId, Number(targetIdAttr));
|
|
285
|
+
},
|
|
286
|
+
[readOnly, onRestoreFromBacklog],
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
const showBacklogPanel = showBacklog && backlogGoals.length > 0;
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<div style={{ display: 'flex', width: '100%', height: '100%' }}>
|
|
293
|
+
{showBacklogPanel && (
|
|
294
|
+
<div
|
|
295
|
+
{...(isBacklogOpen ? { 'data-goaltree-backlog-zone': true } : {})}
|
|
296
|
+
style={{
|
|
297
|
+
width: isBacklogOpen ? 220 : 28,
|
|
298
|
+
flexShrink: 0,
|
|
299
|
+
borderRight: '1px solid #e2e8f0',
|
|
300
|
+
background: '#f8fafc',
|
|
301
|
+
display: 'flex',
|
|
302
|
+
flexDirection: 'column',
|
|
303
|
+
position: 'relative',
|
|
304
|
+
}}
|
|
305
|
+
>
|
|
306
|
+
<button
|
|
307
|
+
type="button"
|
|
308
|
+
aria-label={isBacklogOpen ? 'Collapse backlog' : 'Expand backlog'}
|
|
309
|
+
title={isBacklogOpen ? 'Collapse backlog' : 'Expand backlog'}
|
|
310
|
+
onClick={() => setIsBacklogOpen((v) => !v)}
|
|
311
|
+
style={{
|
|
312
|
+
alignSelf: 'flex-end',
|
|
313
|
+
margin: '6px 6px 0 6px',
|
|
314
|
+
width: 16,
|
|
315
|
+
height: 16,
|
|
316
|
+
border: '1px solid #cbd5e1',
|
|
317
|
+
borderRadius: 4,
|
|
318
|
+
background: '#ffffff',
|
|
319
|
+
color: '#64748b',
|
|
320
|
+
fontSize: 10,
|
|
321
|
+
lineHeight: '14px',
|
|
322
|
+
padding: 0,
|
|
323
|
+
cursor: 'pointer',
|
|
324
|
+
flexShrink: 0,
|
|
325
|
+
}}
|
|
326
|
+
>
|
|
327
|
+
{isBacklogOpen ? '◀' : '▶'}
|
|
328
|
+
</button>
|
|
329
|
+
{isBacklogOpen && (
|
|
330
|
+
<div style={{ padding: '4px 10px 10px', overflowY: 'auto', flex: 1 }}>
|
|
331
|
+
<div style={{ fontWeight: 700, fontSize: 12, color: '#334155', marginBottom: 8 }}>Backlog</div>
|
|
332
|
+
{backlogGoals.map((goal) => (
|
|
333
|
+
<div
|
|
334
|
+
key={goal.id}
|
|
335
|
+
draggable={!readOnly}
|
|
336
|
+
onDragStart={(e) => onBacklogItemDragStart(e, goal.id)}
|
|
337
|
+
onDoubleClick={() => onEditRequest?.(goal)}
|
|
338
|
+
title="Drag onto a canvas card to set its parent"
|
|
339
|
+
style={{
|
|
340
|
+
padding: 8,
|
|
341
|
+
marginBottom: 6,
|
|
342
|
+
background: '#ffffff',
|
|
343
|
+
border: '1px solid #cbd5e1',
|
|
344
|
+
borderRadius: 6,
|
|
345
|
+
fontSize: 11,
|
|
346
|
+
cursor: readOnly ? 'default' : 'grab',
|
|
347
|
+
}}
|
|
348
|
+
>
|
|
349
|
+
<div style={{ fontWeight: 600 }}>{goal.name}</div>
|
|
350
|
+
<div style={{ color: '#64748b' }}>Level: {goal.level}</div>
|
|
351
|
+
</div>
|
|
352
|
+
))}
|
|
353
|
+
</div>
|
|
354
|
+
)}
|
|
355
|
+
</div>
|
|
356
|
+
)}
|
|
357
|
+
|
|
358
|
+
<div style={{ flex: 1, position: 'relative' }} onDragOver={onCanvasDragOver} onDrop={onCanvasDrop}>
|
|
359
|
+
<ReactFlow
|
|
360
|
+
nodes={nodes}
|
|
361
|
+
edges={edges}
|
|
362
|
+
onNodesChange={readOnly ? undefined : onNodesChange}
|
|
363
|
+
onEdgesChange={readOnly ? undefined : onEdgesChange}
|
|
364
|
+
nodeTypes={nodeTypes}
|
|
365
|
+
nodesDraggable={!readOnly}
|
|
366
|
+
nodesConnectable={false}
|
|
367
|
+
onNodeDrag={onNodeDrag}
|
|
368
|
+
onNodeDragStop={onNodeDragStop}
|
|
369
|
+
onNodeDoubleClick={onNodeDoubleClick}
|
|
370
|
+
connectionLineType={ConnectionLineType.Bezier}
|
|
371
|
+
fitView
|
|
372
|
+
>
|
|
373
|
+
<Background />
|
|
374
|
+
<Controls />
|
|
375
|
+
{showMiniMap && <MiniMap pannable zoomable />}
|
|
376
|
+
</ReactFlow>
|
|
377
|
+
</div>
|
|
378
|
+
</div>
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
export function GoalTreeView(props: GoalTreeViewProps): React.ReactElement {
|
|
383
|
+
return <GoalTreeViewInner {...props} />;
|
|
384
|
+
}
|