@purview-dev/pm-docs-site 0.1.0-pre.1 → 0.1.0-pre.3

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.
Files changed (84) hide show
  1. package/README.md +130 -18
  2. package/dist/cli.d.ts +2 -0
  3. package/dist/cli.js +91 -0
  4. package/dist/dev-env.d.ts +2 -0
  5. package/dist/dev-env.js +13 -0
  6. package/dist/fs-allow.d.ts +2 -0
  7. package/dist/fs-allow.js +11 -0
  8. package/dist/index.d.ts +7 -0
  9. package/dist/index.js +152 -0
  10. package/dist/options.d.ts +5 -0
  11. package/dist/options.js +46 -0
  12. package/dist/repo-docs.d.ts +33 -0
  13. package/dist/repo-docs.js +94 -0
  14. package/dist/schema-version.d.ts +27 -0
  15. package/dist/schema-version.js +48 -0
  16. package/dist/sidebar.d.ts +10 -0
  17. package/dist/sidebar.js +32 -0
  18. package/dist/site-options.d.ts +9 -0
  19. package/dist/site-options.js +44 -0
  20. package/dist/types.d.ts +47 -0
  21. package/dist/types.js +4 -0
  22. package/lib/{repo-docs.mjs → repo-docs.ts} +22 -46
  23. package/lib/schema-version.ts +59 -0
  24. package/{index.d.ts → lib/types.ts} +5 -6
  25. package/package.json +19 -9
  26. package/src/components/FeatureSummary.astro +30 -9
  27. package/src/components/FeatureTable.astro +1 -1
  28. package/src/components/ItemDetail.astro +1 -1
  29. package/src/components/ItemDialog.astro +12 -8
  30. package/src/components/PlanInteractions.astro +15 -3
  31. package/src/components/RefLink.astro +7 -4
  32. package/src/components/board/Board.tsx +252 -0
  33. package/src/components/board/KanbanItemCard.tsx +131 -0
  34. package/src/components/board/LinkRuns.tsx +21 -0
  35. package/src/components/board/TaskKanbanCard.tsx +83 -0
  36. package/src/components/board/useBoardUrlState.ts +41 -0
  37. package/src/components/decisions/Decisions.tsx +162 -0
  38. package/src/components/decisions/useDecisionsUrlState.ts +29 -0
  39. package/src/components/graph/Graph.tsx +290 -0
  40. package/src/components/graph/GraphNodes.tsx +120 -0
  41. package/src/components/graph/useGraphUrlState.ts +58 -0
  42. package/src/components/lib/KanbanItemCard.astro +7 -11
  43. package/src/components/lib/StatusTimelineFeed.astro +3 -2
  44. package/src/components/lib/TaskKanbanCard.astro +2 -1
  45. package/src/components/timeline/Timeline.tsx +192 -0
  46. package/src/components/timeline/useTimelineLayout.ts +39 -0
  47. package/src/content.config.ts +22 -6
  48. package/src/env.d.ts +2 -2
  49. package/src/lib/board-data.ts +84 -0
  50. package/src/lib/board.ts +209 -0
  51. package/src/lib/decisions.ts +100 -0
  52. package/src/lib/graph-layout.ts +270 -0
  53. package/src/lib/graph-state.ts +99 -0
  54. package/src/lib/graph.ts +194 -0
  55. package/src/lib/link-html.ts +39 -0
  56. package/src/lib/planning-types.ts +32 -3
  57. package/src/lib/planning.ts +94 -52
  58. package/src/lib/ref-boundary.ts +19 -0
  59. package/src/lib/references.ts +67 -8
  60. package/src/lib/timeline-state.ts +119 -0
  61. package/src/lib/timeline.ts +51 -0
  62. package/src/loaders/adrs.ts +43 -0
  63. package/src/loaders/repo-docs.ts +3 -3
  64. package/src/pages/404.astro +18 -0
  65. package/src/pages/index.astro +1 -1
  66. package/src/pages/plan/board.astro +14 -113
  67. package/src/pages/plan/log.astro +18 -1
  68. package/src/pages/plan/roadmap.astro +21 -3
  69. package/src/routes/plan/decisions/[id].astro +93 -0
  70. package/src/routes/plan/decisions.astro +52 -0
  71. package/src/routes/plan/graph.astro +80 -0
  72. package/src/routes/plan/milestones/index.astro +2 -2
  73. package/src/routes/plan/now.astro +2 -3
  74. package/src/scripts/plan.ts +32 -46
  75. package/src/styles/components.css +244 -13
  76. package/src/styles/graph.css +296 -0
  77. package/src/styles/kanban.css +277 -0
  78. package/src/styles/timeline.css +210 -0
  79. package/cli.mjs +0 -120
  80. package/index.mjs +0 -97
  81. package/lib/options.mjs +0 -67
  82. package/lib/schema-version.mjs +0 -29
  83. package/lib/sidebar.mjs +0 -47
  84. package/lib/site-options.mjs +0 -38
@@ -0,0 +1,83 @@
1
+ /**
2
+ * TaskKanbanCard — Agile task card with priority labels, progress completion bar, and due date.
3
+ *
4
+ * From the Astro Components Kit by Konstantin (https://astrocomponents.dev/docs/task-kanban-card/,
5
+ * https://github.com/konstantinWDK/astro-components), MIT License. Ported to React from its
6
+ * manual-install source (via ../lib/TaskKanbanCard.astro); the changes are that hard-coded
7
+ * dark-theme colours use Starlight theme variables, so the card reads in light and dark themes;
8
+ * the task can be a link, for the site's item popup and backlinks (href, itemId), and a task that
9
+ * is not a link links known IDs; the tag shows the item's size (S, M, L as the kit's low, med,
10
+ * high) and is omitted without one; a RAG dot sits beside it; the assignee chip is omitted for a card with no
11
+ * owner; and the card has no role. The task link carries
12
+ * `aria-haspopup="dialog"` when it is the popup trigger. Its styles are in
13
+ * src/styles/kanban.css.
14
+ */
15
+ import type { CardRag, LinkRun } from '../../lib/board';
16
+ import type { Size } from '../../lib/planning-types';
17
+ import LinkRuns from './LinkRuns';
18
+
19
+ interface Props {
20
+ task: string;
21
+ taskRuns: LinkRun[];
22
+ date: string;
23
+ /** Null with no owner: no chip, as the owner filter hides the card. */
24
+ assigneeInitials: string | null;
25
+ size: Size | null;
26
+ rag: CardRag;
27
+ progress: number;
28
+ href: string | null;
29
+ itemId: string | null;
30
+ }
31
+
32
+ const sizeVariant: Record<Size, 'low' | 'med' | 'high'> = { S: 'low', M: 'med', L: 'high' };
33
+
34
+ export default function TaskKanbanCard({ task, taskRuns, date, assigneeInitials, size, rag, progress, href, itemId }: Props) {
35
+ return (
36
+ <div className="task-card">
37
+ <div className="task-card__tags">
38
+ <span className="k-item__badges">
39
+ {size && (
40
+ <span className={`task-card__tag task-card__tag--${sizeVariant[size]}`} title={`Size ${size}`}>
41
+ <span className="task-card__tag-dot" aria-hidden="true"></span>
42
+ {size}
43
+ </span>
44
+ )}
45
+ {rag !== 'none' && <span className="k-item__rag" data-rag={rag} role="img" aria-label={`RAG ${rag}`}></span>}
46
+ </span>
47
+ <span className="task-card__pct">{progress}%</span>
48
+ </div>
49
+
50
+ <p className="task-card__desc">
51
+ {href ? (
52
+ <a className="plan-item-link" href={href} data-item={itemId ?? undefined} aria-haspopup={itemId ? 'dialog' : undefined}>
53
+ {task}
54
+ </a>
55
+ ) : (
56
+ <LinkRuns runs={taskRuns} />
57
+ )}
58
+ </p>
59
+
60
+ <div className="task-card__progress-wrap" role="progressbar" aria-valuenow={progress} aria-valuemin={0} aria-valuemax={100} aria-label="Task progress">
61
+ <div className="task-card__progress-bar" style={{ width: `${progress}%` }}></div>
62
+ </div>
63
+
64
+ <div className="task-card__footer">
65
+ <div className="task-card__date">
66
+ <svg className="task-card__date-icon" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" aria-hidden="true">
67
+ <rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect>
68
+ <line x1="16" y1="2" x2="16" y2="6"></line>
69
+ <line x1="8" y1="2" x2="8" y2="6"></line>
70
+ <line x1="3" y1="10" x2="21" y2="10"></line>
71
+ </svg>
72
+ <span>{date}</span>
73
+ </div>
74
+
75
+ {assigneeInitials && (
76
+ <div className="task-card__assignee" title={`Assigned to ${assigneeInitials}`}>
77
+ {assigneeInitials}
78
+ </div>
79
+ )}
80
+ </div>
81
+ </div>
82
+ );
83
+ }
@@ -0,0 +1,41 @@
1
+ // The Board's filter and group state, kept in the page URL. The server has no
2
+ // location, so the first render is always DEFAULT_STATE (hydration must match
3
+ // it); the query is read in an effect on mount. Every later change is written
4
+ // back with history.replaceState, in boardQuery's fixed key order. The pending
5
+ // mark (`data-board-pending` on <html>, set before paint by the inline script
6
+ // in PlanInteractions.astro when the URL has a board key) keeps the board
7
+ // hidden until the parsed state has rendered, so a filtered link never shows
8
+ // the unfiltered board first.
9
+ import { useEffect, useState } from 'react';
10
+ import type { Dispatch, SetStateAction } from 'react';
11
+
12
+ import { boardQuery, DEFAULT_STATE, parseBoardQuery } from '../../lib/board';
13
+ import type { BoardState } from '../../lib/board';
14
+
15
+ export function useBoardUrlState(milestoneIds: string[]): [BoardState, Dispatch<SetStateAction<BoardState>>, boolean] {
16
+ const [state, setState] = useState<BoardState>(DEFAULT_STATE);
17
+ // True once the URL's state is applied: the render after it shows the parsed state.
18
+ const [applied, setApplied] = useState(false);
19
+
20
+ useEffect(() => {
21
+ setState(parseBoardQuery(location.search, milestoneIds));
22
+ setApplied(true);
23
+ // Mount only: the milestone list is fixed at build time.
24
+ }, []);
25
+
26
+ useEffect(() => {
27
+ if (!applied) {
28
+ return;
29
+ }
30
+
31
+ // This effect runs after the render that committed the parsed state, so the board is already filtered when it shows.
32
+ delete document.documentElement.dataset.boardPending;
33
+ const url = location.pathname + boardQuery(state) + location.hash;
34
+
35
+ if (url !== location.pathname + location.search + location.hash) {
36
+ history.replaceState(null, '', url);
37
+ }
38
+ }, [state, applied]);
39
+
40
+ return [state, setState, applied];
41
+ }
@@ -0,0 +1,162 @@
1
+ // The Decisions view: every ADR as a row, with a text search, status and
2
+ // category chips (superseded off by default), and grouping by category or
3
+ // status. Rows that do not match are hidden, never left out, so the page's
4
+ // links stay the same in every state. The state lives in the URL
5
+ // (useDecisionsUrlState).
6
+ import { ADR_STATUSES, DEFAULT_DECISIONS_STATE, decisionsQuery, groupDecisions, matchesDecision, type DecisionsGroup } from '../../lib/decisions';
7
+ import type { AdrStatus } from '../../lib/planning-types';
8
+ import { useDecisionsUrlState } from './useDecisionsUrlState';
9
+
10
+ /** A link to a known page, or plain text when that page is not built. */
11
+ export interface NamedRef {
12
+ label: string;
13
+ href: string | null;
14
+ }
15
+
16
+ /** One ADR as the island shows it; `text` is adrSearchText, computed at build time. */
17
+ export interface DecisionRow {
18
+ id: string;
19
+ title: string;
20
+ status: AdrStatus | null;
21
+ category: string | null;
22
+ date: string | null;
23
+ href: string;
24
+ text: string;
25
+ item: NamedRef | null;
26
+ successor: NamedRef | null;
27
+ }
28
+
29
+ interface Props {
30
+ rows: DecisionRow[];
31
+ categories: string[];
32
+ }
33
+
34
+ const GROUPS: { value: DecisionsGroup; label: string }[] = [
35
+ { value: 'category', label: 'Category' },
36
+ { value: 'status', label: 'Status' },
37
+ { value: 'none', label: 'None' },
38
+ ];
39
+
40
+ function Ref({ named }: { named: NamedRef }) {
41
+ return named.href ? (
42
+ <a href={named.href} title={named.label}>
43
+ {named.label}
44
+ </a>
45
+ ) : (
46
+ <>{named.label}</>
47
+ );
48
+ }
49
+
50
+ const toggle = <T,>(list: T[], value: T) => (list.includes(value) ? list.filter((entry) => entry !== value) : [...list, value]);
51
+
52
+ export default function Decisions({ rows, categories }: Props) {
53
+ const [state, setState] = useDecisionsUrlState(categories);
54
+ const matches = (row: DecisionRow) => matchesDecision(row, state, row.text);
55
+ const groups = groupDecisions(rows, state.group);
56
+ const shown = rows.filter(matches).length;
57
+ const isDefault = decisionsQuery(state) === '';
58
+
59
+ return (
60
+ <div className="decisions">
61
+ <div className="decisions-controls">
62
+ <label className="decisions-search">
63
+ Search decisions
64
+ <input type="search" value={state.q} onChange={(event) => setState({ ...state, q: event.currentTarget.value })} />
65
+ </label>
66
+ <div role="group" aria-label="Status" className="decisions-chips">
67
+ {ADR_STATUSES.map((status) => (
68
+ <button
69
+ key={status}
70
+ type="button"
71
+ className="decisions-chip"
72
+ aria-pressed={state.status.includes(status)}
73
+ onClick={() => setState({ ...state, status: toggle(state.status, status) })}
74
+ >
75
+ {status}
76
+ </button>
77
+ ))}
78
+ </div>
79
+ {categories.length > 1 && (
80
+ <div role="group" aria-label="Category" className="decisions-chips">
81
+ {categories.map((category) => (
82
+ <button
83
+ key={category}
84
+ type="button"
85
+ className="decisions-chip"
86
+ aria-pressed={state.category.includes(category)}
87
+ onClick={() => setState({ ...state, category: toggle(state.category, category) })}
88
+ >
89
+ {category}
90
+ </button>
91
+ ))}
92
+ </div>
93
+ )}
94
+ <label className="decisions-group">
95
+ Group by
96
+ <select value={state.group} onChange={(event) => setState({ ...state, group: event.currentTarget.value as DecisionsGroup })}>
97
+ {GROUPS.map((group) => (
98
+ <option key={group.value} value={group.value}>
99
+ {group.label}
100
+ </option>
101
+ ))}
102
+ </select>
103
+ </label>
104
+ <button type="button" className="decisions-clear" disabled={isDefault} onClick={() => setState(DEFAULT_DECISIONS_STATE)}>
105
+ Clear
106
+ </button>
107
+ </div>
108
+
109
+ <p className="decisions-count" aria-live="polite">
110
+ {shown} of {rows.length} decisions
111
+ </p>
112
+
113
+ {groups.map((group) => {
114
+ const visible = group.adrs.filter(matches).length;
115
+
116
+ return (
117
+ <section key={group.key} hidden={visible === 0}>
118
+ {state.group !== 'none' && (
119
+ <h2>
120
+ {group.label} ({visible})
121
+ </h2>
122
+ )}
123
+ <ul className="decisions-list">
124
+ {group.adrs.map((row) => (
125
+ <li key={row.id} hidden={!matches(row)} data-adr={row.id}>
126
+ <a href={row.href}>
127
+ <strong>{row.id}</strong> {row.title}
128
+ </a>{' '}
129
+ <span className={`adr-status adr-status--${row.status ?? 'unknown'}`}>{row.status ?? 'unknown'}</span>
130
+ <span className="decisions-meta">
131
+ {[row.category, row.date].filter(Boolean).join(' · ')}
132
+ {row.item && (
133
+ <>
134
+ {' · '}
135
+ <Ref named={row.item} />
136
+ </>
137
+ )}
138
+ {row.successor && (
139
+ <>
140
+ {' · Superseded by '}
141
+ <Ref named={row.successor} />
142
+ </>
143
+ )}
144
+ </span>
145
+ </li>
146
+ ))}
147
+ </ul>
148
+ </section>
149
+ );
150
+ })}
151
+
152
+ {shown === 0 && (
153
+ <p className="decisions-empty">
154
+ No decisions match
155
+ {state.q ? ` "${state.q}"` : ''}
156
+ {` with status ${state.status.length ? state.status.join(', ') : 'none'}`}
157
+ {state.category.length ? ` in ${state.category.join(', ')}` : ''}.
158
+ </p>
159
+ )}
160
+ </div>
161
+ );
162
+ }
@@ -0,0 +1,29 @@
1
+ // The Decisions view's search, filters, and grouping, kept in the page URL. The
2
+ // server has no location, so the first render is DEFAULT_DECISIONS_STATE
3
+ // (hydration must match it); the query is read in an effect on mount, and
4
+ // every later change is written back with history.replaceState.
5
+ import { useEffect, useState } from 'react';
6
+ import type { Dispatch, SetStateAction } from 'react';
7
+
8
+ import { DEFAULT_DECISIONS_STATE, decisionsQuery, parseDecisionsQuery, type DecisionsState } from '../../lib/decisions';
9
+
10
+ export function useDecisionsUrlState(categories: string[]): [DecisionsState, Dispatch<SetStateAction<DecisionsState>>] {
11
+ const [state, setState] = useState<DecisionsState>(DEFAULT_DECISIONS_STATE);
12
+ const [applied, setApplied] = useState(false);
13
+
14
+ useEffect(() => {
15
+ setState(parseDecisionsQuery(location.search, categories));
16
+ setApplied(true);
17
+ // Mount only: the categories are fixed at build time.
18
+ }, []);
19
+
20
+ useEffect(() => {
21
+ if (!applied) return;
22
+
23
+ const url = location.pathname + decisionsQuery(state) + location.hash;
24
+
25
+ if (url !== location.pathname + location.search + location.hash) history.replaceState(null, '', url);
26
+ }, [state, applied]);
27
+
28
+ return [state, setState];
29
+ }
@@ -0,0 +1,290 @@
1
+ // The Graph island on the Graph page: open items, the done, dropped, and
2
+ // missing IDs they point at, and their Depends on and Revisits links, drawn
3
+ // with React Flow. Every position comes from the four build-time layouts
4
+ // (src/lib/graph-layout.ts, run in graph.astro's frontmatter); this file only
5
+ // picks one, so no layout code reaches the browser. It may only `import type`
6
+ // from graph-layout.ts, which imports dagre, and from graph.ts, which imports
7
+ // planning.ts (node:fs); its runtime helpers come from graph-state.ts.
8
+ //
9
+ // The server renders the default layout (lanes on, done chips on) fitted to a
10
+ // nominal canvas size, and hydration starts from the same nodes and the same
11
+ // transform (`defaultViewport`), so the two match; the island then fits the
12
+ // real canvas. The switches and the
13
+ // selection live in the URL (useGraphUrlState.ts). Clicking a node, or Enter
14
+ // on it, selects it and highlights its chain (chainOf); everything else gets
15
+ // `data-dimmed`. Clicking the selected node again, or an item's ID link,
16
+ // opens its feature page. Escape, or a click on the background or a lane,
17
+ // clears the selection. The wheel zooms only over the canvas, as React Flow
18
+ // does by default, so the page still scrolls past it.
19
+ import { getViewportForBounds, MarkerType, Position, ReactFlow, ReactFlowProvider, useReactFlow } from '@xyflow/react';
20
+ import type { Edge, NodeMouseHandler, Viewport } from '@xyflow/react';
21
+ import { useEffect, useMemo } from 'react';
22
+ import type { KeyboardEvent } from 'react';
23
+
24
+ import type { GraphEdge, GraphNode } from '../../lib/graph';
25
+ import { chainOf, layoutKey } from '../../lib/graph-state';
26
+ import type { GraphState } from '../../lib/graph-state';
27
+ import type { GraphLayout, LayoutKey } from '../../lib/graph-layout';
28
+ import { NODE_TYPES } from './GraphNodes';
29
+ import type { GraphFlowNode } from './GraphNodes';
30
+ import { DEFAULT_GRAPH_STATE, useGraphUrlState } from './useGraphUrlState';
31
+
32
+ interface Props {
33
+ nodes: GraphNode[];
34
+ edges: GraphEdge[];
35
+ layouts: Record<LayoutKey, GraphLayout>;
36
+ /** Milestone page by milestone ID (and `none`), for the lane labels and item meta lines; absent without a page. */
37
+ milestoneHrefs: Record<string, string>;
38
+ }
39
+
40
+ /** The canvas size the server render (and so the first client render) is fitted to. */
41
+ const SERVER_VIEW = { width: 960, height: 540 };
42
+ /** How far a lane band reaches past the outermost nodes on each side. */
43
+ const LANE_PAD = 16;
44
+ /** The lane and tray label band's height (graph-layout.ts LABEL_BAND). */
45
+ const LABEL_BAND = 32;
46
+ const ZOOM = { min: 0.25, max: 2 };
47
+ /** The space kept around the graph when it is fitted. */
48
+ const FIT = { padding: '16px' } as const;
49
+
50
+ /** Data attributes on a node's or edge's React Flow element: present when `true`, absent otherwise. */
51
+ function flag(on: boolean): string | undefined {
52
+ return on ? '' : undefined;
53
+ }
54
+
55
+ /** React Flow's `domAttributes` take no data attributes in their type; they are spread onto the element. */
56
+ function dataAttributes(attributes: Record<string, string | undefined>): Record<string, string> {
57
+ return Object.fromEntries(Object.entries(attributes).filter((entry): entry is [string, string] => entry[1] !== undefined));
58
+ }
59
+
60
+ /** The React Flow nodes for one layout: lane bands and the tray label first, then every boxed item and chip. */
61
+ function flowNodes(data: GraphNode[], layout: GraphLayout, state: GraphState, chain: Set<string> | null, milestoneHrefs: Record<string, string>): GraphFlowNode[] {
62
+ const backdrop: GraphFlowNode[] = layout.lanes.map((lane) => ({
63
+ id: `lane:${lane.key}`,
64
+ type: 'lane',
65
+ position: { x: -LANE_PAD, y: lane.y },
66
+ width: layout.width + LANE_PAD * 2,
67
+ height: lane.height,
68
+ zIndex: -1,
69
+ selectable: false,
70
+ focusable: false,
71
+ draggable: false,
72
+ data: { lane, href: milestoneHrefs[lane.key] ?? null },
73
+ }));
74
+
75
+ if (layout.tray) {
76
+ backdrop.push({
77
+ id: 'tray',
78
+ type: 'tray',
79
+ position: { x: 0, y: layout.tray.y },
80
+ width: layout.width,
81
+ height: LABEL_BAND,
82
+ zIndex: -1,
83
+ selectable: false,
84
+ focusable: false,
85
+ draggable: false,
86
+ data: {},
87
+ });
88
+ }
89
+
90
+ const boxed = data.flatMap((node): GraphFlowNode[] => {
91
+ const box = layout.boxes[node.id];
92
+
93
+ if (!box) return [];
94
+
95
+ const shared = {
96
+ id: node.id,
97
+ position: { x: box.x, y: box.y },
98
+ width: box.width,
99
+ height: box.height,
100
+ selected: state.focus === node.id,
101
+ draggable: false,
102
+ // The accessible name carries the full title, which the node truncates.
103
+ ariaLabel: node.title === null ? `${node.id} not found` : node.kind === 'item' ? `${node.id} ${node.title}` : `${node.id} ${node.title} (${node.kind})`,
104
+ // Fixed handles, so edges are placed without measuring the DOM (and on the server).
105
+ handles: [
106
+ { type: 'target' as const, position: Position.Left, x: 0, y: Math.round(box.height / 2), width: 1, height: 1 },
107
+ { type: 'source' as const, position: Position.Right, x: box.width - 1, y: Math.round(box.height / 2), width: 1, height: 1 },
108
+ ],
109
+ domAttributes: dataAttributes({
110
+ 'data-graph-node': node.id,
111
+ 'data-kind': node.kind,
112
+ 'data-selected': flag(state.focus === node.id),
113
+ 'data-dimmed': flag(chain !== null && !chain.has(node.id)),
114
+ }),
115
+ };
116
+
117
+ return [node.kind === 'item' ? { ...shared, type: 'item', data: { node, showDoneCount: !state.done, milestoneHref: node.milestone ? (milestoneHrefs[node.milestone] ?? null) : null } } : { ...shared, type: 'chip', data: { node } }];
118
+ });
119
+
120
+ return [...backdrop, ...boxed];
121
+ }
122
+
123
+ /** The React Flow edges drawn in one layout: both ends boxed. */
124
+ function flowEdges(edges: GraphEdge[], layout: GraphLayout, chain: Set<string> | null): Edge[] {
125
+ return edges
126
+ .filter((edge) => layout.boxes[edge.source] && layout.boxes[edge.target])
127
+ .map((edge) => ({
128
+ id: edge.id,
129
+ source: edge.source,
130
+ target: edge.target,
131
+ type: 'default',
132
+ className: ['plan-graph__edge', `plan-graph__edge--${edge.kind}`, edge.fromChip ? 'plan-graph__edge--muted' : ''].filter(Boolean).join(' '),
133
+ ...(edge.kind === 'revisits' ? { label: 'revisits' } : {}),
134
+ // A muted (from-chip) edge colours its own arrowhead; a full-contrast one is
135
+ // left uncoloured inline so the CSS rule on .react-flow__arrowhead polyline applies.
136
+ markerEnd: { type: MarkerType.ArrowClosed, width: 16, height: 16, ...(edge.fromChip ? { color: 'var(--sl-color-gray-5)' } : {}) },
137
+ selectable: false,
138
+ focusable: false,
139
+ domAttributes: dataAttributes({
140
+ 'data-graph-edge': edge.id,
141
+ 'data-kind': edge.kind,
142
+ 'data-dimmed': flag(chain !== null && !chain.has(edge.id)),
143
+ }),
144
+ }));
145
+ }
146
+
147
+ /**
148
+ * The default layout fitted to SERVER_VIEW: the transform the provider's `fitView` gives the server render.
149
+ * React Flow's pan and zoom start from `defaultViewport` on the client, so passing this keeps hydration on the
150
+ * server's frame until the island fits the real canvas.
151
+ */
152
+ function fittedViewport(list: GraphFlowNode[]): Viewport {
153
+ const left = Math.min(...list.map((node) => node.position.x));
154
+ const top = Math.min(...list.map((node) => node.position.y));
155
+ const right = Math.max(...list.map((node) => node.position.x + (node.width ?? 0)));
156
+ const bottom = Math.max(...list.map((node) => node.position.y + (node.height ?? 0)));
157
+
158
+ return getViewportForBounds({ x: left, y: top, width: right - left, height: bottom - top }, SERVER_VIEW.width, SERVER_VIEW.height, ZOOM.min, ZOOM.max, FIT.padding);
159
+ }
160
+
161
+ function GraphView({ nodes, edges, layouts, milestoneHrefs, initialViewport }: Props & { initialViewport: Viewport }) {
162
+ const [state, update, applied] = useGraphUrlState(layouts);
163
+ const { zoomIn, zoomOut, fitView } = useReactFlow();
164
+ const key = layoutKey(state);
165
+ const layout = layouts[key];
166
+ const chain = useMemo(() => (state.focus ? chainOf(edges, state.focus, layout) : null), [edges, state.focus, layout]);
167
+ const flowNodeList = useMemo(() => flowNodes(nodes, layout, state, chain, milestoneHrefs), [nodes, layout, state, chain, milestoneHrefs]);
168
+ const flowEdgeList = useMemo(() => flowEdges(edges, layout, chain), [edges, layout, chain]);
169
+ const hrefs = useMemo(() => new Map(nodes.map((node) => [node.id, node.href])), [nodes]);
170
+
171
+ // A new layout has new extents: fit it once its nodes are in the store.
172
+ useEffect(() => {
173
+ if (applied) void fitView(FIT);
174
+ }, [key, applied]);
175
+
176
+ const open = (id: string) => {
177
+ const href = hrefs.get(id);
178
+
179
+ if (href) location.assign(href);
180
+ };
181
+
182
+ const onNodeClick: NodeMouseHandler<GraphFlowNode> = (event, node) => {
183
+ if (node.type === 'lane' || node.type === 'tray') {
184
+ update({ focus: null });
185
+ return;
186
+ }
187
+
188
+ // A link inside the node follows itself (a chip's link only once it is selected).
189
+ if (event.target instanceof Element && event.target.closest('a')) {
190
+ if (state.focus !== node.id) update({ focus: node.id });
191
+ return;
192
+ }
193
+
194
+ if (state.focus === node.id) open(node.id);
195
+ else update({ focus: node.id });
196
+ };
197
+
198
+ const onKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
199
+ if (event.key === 'Escape') {
200
+ update({ focus: null });
201
+ return;
202
+ }
203
+
204
+ if (event.key !== 'Enter' || !(event.target instanceof HTMLElement)) return;
205
+
206
+ const id = event.target.dataset.graphNode;
207
+
208
+ if (!id) return;
209
+
210
+ event.preventDefault();
211
+ if (state.focus === id) open(id);
212
+ else update({ focus: id });
213
+ };
214
+
215
+ return (
216
+ <div className="plan-graph not-content" data-layout={key} data-pagefind-ignore onKeyDown={onKeyDown}>
217
+ <div className="plan-graph__toolbar" hidden={!applied}>
218
+ <div className="plan-graph__group" role="group" aria-label="View">
219
+ <button type="button" role="switch" aria-checked={state.lanes} onClick={() => update({ lanes: !state.lanes })}>
220
+ Milestone lanes
221
+ </button>
222
+ <button type="button" role="switch" aria-checked={state.done} onClick={() => update({ done: !state.done })}>
223
+ Show done prerequisites
224
+ </button>
225
+ </div>
226
+ <div className="plan-graph__group" role="group" aria-label="Zoom">
227
+ <button type="button" aria-label="Zoom out" onClick={() => void zoomOut()}>
228
+ −
229
+ </button>
230
+ <button type="button" aria-label="Zoom in" onClick={() => void zoomIn()}>
231
+ +
232
+ </button>
233
+ <button type="button" onClick={() => void fitView(FIT)}>
234
+ Fit
235
+ </button>
236
+ </div>
237
+ </div>
238
+
239
+ <div className="plan-graph__canvas">
240
+ <ReactFlow<GraphFlowNode, Edge>
241
+ nodes={flowNodeList}
242
+ edges={flowEdgeList}
243
+ nodeTypes={NODE_TYPES}
244
+ nodesDraggable={false}
245
+ nodesConnectable={false}
246
+ elementsSelectable
247
+ fitView
248
+ fitViewOptions={FIT}
249
+ defaultViewport={initialViewport}
250
+ minZoom={ZOOM.min}
251
+ maxZoom={ZOOM.max}
252
+ defaultMarkerColor={null}
253
+ deleteKeyCode={null}
254
+ selectionKeyCode={null}
255
+ multiSelectionKeyCode={null}
256
+ onNodeClick={onNodeClick}
257
+ onPaneClick={() => update({ focus: null })}
258
+ aria-label="Dependency graph"
259
+ />
260
+ </div>
261
+ </div>
262
+ );
263
+ }
264
+
265
+ /** The Graph island: `nodes` and `edges` once, the four build-time layouts they are placed by, and the milestone pages. */
266
+ export default function Graph({ nodes, edges, layouts, milestoneHrefs }: Props) {
267
+ // The provider's first state is the default layout fitted to SERVER_VIEW, on the server and on hydration alike.
268
+ const initial = useMemo(() => {
269
+ const layout = layouts[layoutKey(DEFAULT_GRAPH_STATE)];
270
+
271
+ const first = flowNodes(nodes, layout, DEFAULT_GRAPH_STATE, null, milestoneHrefs);
272
+
273
+ return { nodes: first, edges: flowEdges(edges, layout, null), viewport: fittedViewport(first) };
274
+ }, [nodes, edges, layouts, milestoneHrefs]);
275
+
276
+ return (
277
+ <ReactFlowProvider
278
+ initialNodes={initial.nodes}
279
+ initialEdges={initial.edges}
280
+ initialWidth={SERVER_VIEW.width}
281
+ initialHeight={SERVER_VIEW.height}
282
+ initialMinZoom={ZOOM.min}
283
+ initialMaxZoom={ZOOM.max}
284
+ initialFitViewOptions={FIT}
285
+ fitView
286
+ >
287
+ <GraphView nodes={nodes} edges={edges} layouts={layouts} milestoneHrefs={milestoneHrefs} initialViewport={initial.viewport} />
288
+ </ReactFlowProvider>
289
+ );
290
+ }