feat: replace static rFunds diagram with interactive flow canvas

Transform the Diagram tab from a read-only SVG into a full interactive
canvas with draggable nodes, zoom/pan, Sankey-width edges with +/-
allocation controls, slide-in editor panel, live simulation, node CRUD,
keyboard shortcuts, and lz-string URL sharing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jeff Emmett 2026-03-02 13:16:55 -08:00
parent b252004f48
commit f0d27bde16
6 changed files with 1032 additions and 220 deletions

File diff suppressed because it is too large Load Diff

View File

@ -140,7 +140,134 @@
.funds-status--seeking { color: #0ea5e9; }
.funds-status--critical { color: #ef4444; }
/* ── Diagram tab ────────────────────────────────────── */
/* ── Interactive canvas (Diagram tab) ───────────────── */
.funds-canvas-container {
position: relative; height: 70vh; min-height: 400px;
background: #0f172a; border-radius: 12px; border: 1px solid #334155;
overflow: hidden; user-select: none;
}
.funds-canvas-svg {
width: 100%; height: 100%; display: block;
cursor: grab;
}
.funds-canvas-svg.panning { cursor: grabbing; }
.funds-canvas-svg.dragging { cursor: move; }
/* Toolbar — top-right overlay */
.funds-canvas-toolbar {
position: absolute; top: 10px; right: 10px; z-index: 10;
display: flex; gap: 4px; flex-wrap: wrap; align-items: center;
}
.funds-canvas-btn {
padding: 5px 10px; border: 1px solid #475569; border-radius: 6px;
background: #1e293b; color: #e2e8f0; font-size: 11px; font-weight: 500;
cursor: pointer; white-space: nowrap; transition: background 0.15s, border-color 0.15s;
}
.funds-canvas-btn:hover { background: #334155; border-color: #64748b; }
.funds-canvas-btn--source { border-color: #10b981; color: #6ee7b7; }
.funds-canvas-btn--source:hover { background: #064e3b; }
.funds-canvas-btn--funnel { border-color: #3b82f6; color: #93c5fd; }
.funds-canvas-btn--funnel:hover { background: #1e3a5f; }
.funds-canvas-btn--outcome { border-color: #ec4899; color: #f9a8d4; }
.funds-canvas-btn--outcome:hover { background: #4a1942; }
.funds-canvas-btn--active { background: #4f46e5; border-color: #6366f1; color: #fff; }
.funds-canvas-sep {
width: 1px; height: 20px; background: #334155; margin: 0 4px;
}
/* SVG node styles */
.flow-node { cursor: pointer; }
.flow-node:hover .node-bg { filter: brightness(1.15); }
.flow-node.selected .node-bg { stroke: #6366f1; stroke-width: 3; }
.node-glow { filter: drop-shadow(0 0 6px rgba(251,191,36,0.5)); }
/* Editor panel — right side slide-in */
.funds-editor-panel {
position: absolute; top: 0; right: 0; bottom: 0; width: 320px; z-index: 20;
background: #1e293b; border-left: 1px solid #334155;
transform: translateX(100%); transition: transform 0.25s ease;
overflow-y: auto; padding: 16px;
display: flex; flex-direction: column; gap: 12px;
}
.funds-editor-panel.open { transform: translateX(0); }
.editor-header {
display: flex; align-items: center; justify-content: space-between;
}
.editor-title { font-size: 14px; font-weight: 600; color: #e2e8f0; }
.editor-close {
background: none; border: none; color: #94a3b8; font-size: 18px; cursor: pointer; padding: 2px 6px;
}
.editor-close:hover { color: #e2e8f0; }
.editor-field { display: flex; flex-direction: column; gap: 4px; }
.editor-label { font-size: 11px; color: #94a3b8; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.editor-input {
padding: 6px 10px; border: 1px solid #334155; border-radius: 6px;
background: #0f172a; color: #e2e8f0; font-size: 13px;
}
.editor-input:focus { outline: none; border-color: #6366f1; }
.editor-select {
padding: 6px 10px; border: 1px solid #334155; border-radius: 6px;
background: #0f172a; color: #e2e8f0; font-size: 13px;
}
.editor-alloc-row {
display: flex; align-items: center; gap: 6px; font-size: 12px; color: #94a3b8;
}
.editor-alloc-row .editor-input { width: 60px; text-align: right; }
.editor-alloc-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
.editor-section {
padding-top: 8px; border-top: 1px solid #334155;
}
.editor-section-title { font-size: 12px; font-weight: 600; color: #64748b; margin-bottom: 6px; }
.editor-btn {
padding: 6px 14px; border: 1px solid #475569; border-radius: 6px;
background: #334155; color: #e2e8f0; font-size: 12px; cursor: pointer;
transition: background 0.15s;
}
.editor-btn:hover { background: #475569; }
.editor-btn--danger { border-color: #ef4444; color: #fca5a5; }
.editor-btn--danger:hover { background: #7f1d1d; }
/* Edge +/- controls */
.edge-controls {
display: flex; align-items: center; gap: 2px; font-size: 11px;
}
.edge-btn {
width: 18px; height: 18px; border: 1px solid #475569; border-radius: 4px;
background: #1e293b; color: #e2e8f0; font-size: 12px; cursor: pointer;
display: flex; align-items: center; justify-content: center; padding: 0;
}
.edge-btn:hover { background: #334155; }
.edge-pct { color: #e2e8f0; font-weight: 600; min-width: 30px; text-align: center; }
/* Legend — bottom-left */
.funds-canvas-legend {
position: absolute; bottom: 10px; left: 10px; z-index: 10;
display: flex; flex-wrap: wrap; gap: 12px;
font-size: 11px; color: #94a3b8; background: rgba(15,23,42,0.85);
padding: 6px 10px; border-radius: 8px;
}
.funds-canvas-legend-item { display: flex; align-items: center; gap: 4px; }
.funds-canvas-legend-dot { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }
/* Zoom controls — bottom-right */
.funds-canvas-zoom {
position: absolute; bottom: 10px; right: 10px; z-index: 10;
display: flex; gap: 4px;
}
/* Sufficiency badge — top-left */
.funds-canvas-badge {
position: absolute; top: 10px; left: 10px; z-index: 10;
background: rgba(15,23,42,0.85); border-radius: 10px; padding: 8px 14px;
display: flex; align-items: center; gap: 8px;
}
.funds-canvas-badge__score { font-size: 20px; font-weight: 700; }
.funds-canvas-badge__label { font-size: 10px; color: #94a3b8; text-transform: uppercase; letter-spacing: 0.05em; }
/* Legacy diagram (kept for compat) */
.funds-diagram { overflow-x: auto; }
.funds-diagram svg { display: block; margin: 0 auto; }
.funds-diagram__legend {
@ -177,4 +304,9 @@
.funds-features__grid { grid-template-columns: 1fr; }
.funds-cards { grid-template-columns: 1fr; }
.funds-tabs { flex-wrap: wrap; }
.funds-canvas-container { height: 50vh; min-height: 300px; }
.funds-canvas-toolbar { flex-wrap: wrap; gap: 3px; top: 6px; right: 6px; }
.funds-canvas-btn { padding: 4px 7px; font-size: 10px; }
.funds-editor-panel { width: 100%; }
.funds-canvas-legend { font-size: 10px; gap: 8px; }
}

View File

@ -21,7 +21,7 @@ export function mapFlowToNodes(apiData: any): FlowNode[] {
data: {
label: src.label || src.name || "Source",
flowRate: src.flowRate ?? src.amount ?? 0,
sourceType: src.sourceType || "recurring",
sourceType: src.sourceType || "card",
targetAllocations: (src.targetAllocations || src.allocations || []).map((a: any, i: number) => ({
targetId: a.targetId,
percentage: a.percentage,

View File

@ -2,7 +2,7 @@
* Demo presets ported from rfunds-online/lib/presets.ts.
*/
import type { FlowNode, FunnelNodeData, OutcomeNodeData, SourceNodeData } from "./types";
import type { FlowNode, FunnelNodeData, OutcomeNodeData, OutcomePhase, SourceNodeData } from "./types";
export const SPENDING_COLORS = ["#3b82f6", "#8b5cf6", "#ec4899", "#06b6d4", "#10b981", "#6366f1"];
export const OVERFLOW_COLORS = ["#f59e0b", "#ef4444", "#f97316", "#eab308", "#dc2626", "#ea580c"];
@ -11,7 +11,7 @@ export const demoNodes: FlowNode[] = [
{
id: "revenue", type: "source", position: { x: 660, y: -200 },
data: {
label: "Revenue Stream", flowRate: 5000, sourceType: "recurring",
label: "Revenue Stream", flowRate: 5000, sourceType: "card",
targetAllocations: [{ targetId: "treasury", percentage: 100, color: "#10b981" }],
} as SourceNodeData,
},
@ -67,7 +67,24 @@ export const demoNodes: FlowNode[] = [
} as FunnelNodeData,
},
{ id: "pg-infra", type: "outcome", position: { x: -50, y: 900 },
data: { label: "Infrastructure", description: "Core infrastructure development", fundingReceived: 22000, fundingTarget: 30000, status: "in-progress" } as OutcomeNodeData },
data: {
label: "Infrastructure", description: "Core infrastructure development",
fundingReceived: 22000, fundingTarget: 30000, status: "in-progress",
phases: [
{ name: "Foundation", fundingThreshold: 10000, tasks: [
{ label: "Server provisioning", completed: true },
{ label: "CI/CD pipeline", completed: true },
] },
{ name: "Scaling", fundingThreshold: 20000, tasks: [
{ label: "Load balancer setup", completed: true },
{ label: "Database replication", completed: false },
] },
{ name: "Hardening", fundingThreshold: 30000, tasks: [
{ label: "Security audit", completed: false },
{ label: "Disaster recovery", completed: false },
] },
],
} as OutcomeNodeData },
{ id: "pg-education", type: "outcome", position: { x: 180, y: 900 },
data: { label: "Education", description: "Developer education programs", fundingReceived: 12000, fundingTarget: 20000, status: "in-progress" } as OutcomeNodeData },
{ id: "pg-tooling", type: "outcome", position: { x: 410, y: 900 },

View File

@ -51,12 +51,24 @@ export interface FunnelNodeData {
[key: string]: unknown;
}
export interface PhaseTask {
label: string;
completed: boolean;
}
export interface OutcomePhase {
name: string;
fundingThreshold: number;
tasks: PhaseTask[];
}
export interface OutcomeNodeData {
label: string;
description?: string;
fundingReceived: number;
fundingTarget: number;
status: "not-started" | "in-progress" | "completed" | "blocked";
phases?: OutcomePhase[];
source?: IntegrationSource;
[key: string]: unknown;
}
@ -64,8 +76,11 @@ export interface OutcomeNodeData {
export interface SourceNodeData {
label: string;
flowRate: number;
sourceType: "recurring" | "one-time" | "treasury";
sourceType: "card" | "safe_wallet" | "ridentity" | "unconfigured";
targetAllocations: SourceAllocation[];
walletAddress?: string;
chainId?: number;
safeAddress?: string;
[key: string]: unknown;
}

View File

@ -189,6 +189,7 @@ routes.delete("/api/space-flows/:flowId", async (c) => {
// ─── Page routes ────────────────────────────────────────
const fundsScripts = `
<script src="https://cdn.jsdelivr.net/npm/lz-string@1.5.0/libs/lz-string.min.js"></script>
<script type="module" src="/modules/rfunds/folk-funds-app.js"></script>
<script type="module" src="/modules/rfunds/folk-budget-river.js"></script>`;