Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
let a drag anywhere the scene cards didn't claim pan the FableLoom graph
[._.]/ Adam Eivye463c68d75f8
diff --git a/client/src/components/fableloom/LoomCanvas.jsx b/client/src/components/fableloom/LoomCanvas.jsxindex 8e6091d0b2..be7024892d 100644--- a/client/src/components/fableloom/LoomCanvas.jsx+++ b/client/src/components/fableloom/LoomCanvas.jsx@@ -9,6 +9,9 @@* under); otherwise `pickLoomOrientation` keys off canvas width.* Click (or tap) selects a scene (selection lives in the URL — the parent* navigates); mouse-drag repositions a card and persists `pos` on release.+ * Dragging anywhere a card did NOT claim pans the view instead — a graph+ * larger than its pane was otherwise only reachable by scrollbar or trackpad.+ * On the stacked layout no card claims a drag, so the whole surface pans.* Touch never drags — it would fight scrolling, and desktop `pos` is the* wrong coordinate space for the stacked layout. Selecting a scene dims* every edge that doesn't touch it, and on the stacked layout a path strip@@ -19,6 +22,7 @@import { useEffect, useId, useMemo, useRef } from 'react';import { Flag, Play } from 'lucide-react';import useContainerWidth from '../../hooks/useContainerWidth';+import { isTapGesture } from '../../lib/graphPicking';import {layoutLoomGraph, LOOM_EDGE_LABEL_MAX, LOOM_ORIENTATION,} from '../../lib/loomLayout';@@ -26,6 +30,18 @@ import LoomSceneMedia from './LoomSceneMedia';const DRAG_THRESHOLD_PX = 4;+/**+ * Shared by both canvas gestures: how far the pointer has travelled since+ * pointerdown, or `null` while it is still close enough to read as a click.+ * Latches `moved` on the gesture once the threshold is cleared.+ */+const gestureDelta = (gesture, event) => {+ const point = { x: event.clientX, y: event.clientY };+ if (!gesture.moved && isTapGesture(gesture.start, point, DRAG_THRESHOLD_PX)) return null;+ gesture.moved = true;+ return { dx: point.x - gesture.start.x, dy: point.y - gesture.start.y };+};+const truncate = (text, max) => {const s = typeof text === 'string' ? text : '';return s.length > max ? `${s.slice(0, max - 1)}…` : s;@@ -48,6 +64,12 @@ export default function LoomCanvas({// once on release. Routing it through setState re-rendered every node card// (each with a foreignObject media surface) ~60×/s. Edges catch up on release.const dragRef = useRef(null);+ // A pan is the same story one level up: scrollLeft/scrollTop are mutated+ // directly per pointermove so no node re-renders while the view moves.+ const panRef = useRef(null);+ // Set by whichever gesture actually moved, read once by the surface's+ // click-capture handler — one mechanism for "this click was a drag".+ const draggedRef = useRef(false);const cardRefs = useRef(new Map());const mediaRefs = useRef(new Map());const [measureRef, measuredWidth] = useContainerWidth();@@ -78,30 +100,25 @@ export default function LoomCanvas({// desktop `pos`.if (event.pointerType !== 'mouse' || stacked) return;event.currentTarget.setPointerCapture(event.pointerId);- const start = positions[node.id] || { x: 0, y: 0 };+ const origin = positions[node.id] || { x: 0, y: 0 };dragRef.current = {id: node.id,cardEl: cardRefs.current.get(node.id),mediaEl: mediaRefs.current.get(node.id),- startX: event.clientX,- startY: event.clientY,- originX: start.x,- originY: start.y,- x: start.x,- y: start.y,+ start: { x: event.clientX, y: event.clientY },+ origin,+ x: origin.x,+ y: origin.y,moved: false,};};const handlePointerMove = (event) => {const drag = dragRef.current;- if (!drag) return;- const dx = event.clientX - drag.startX;- const dy = event.clientY - drag.startY;- if (!drag.moved && Math.abs(dx) < DRAG_THRESHOLD_PX && Math.abs(dy) < DRAG_THRESHOLD_PX) return;- drag.moved = true;- drag.x = Math.max(0, drag.originX + dx);- drag.y = Math.max(0, drag.originY + dy);+ const delta = drag && gestureDelta(drag, event);+ if (!delta) return;+ drag.x = Math.max(0, drag.origin.x + delta.dx);+ drag.y = Math.max(0, drag.origin.y + delta.dy);drag.cardEl?.setAttribute('transform', `translate(${drag.x}, ${drag.y})`);// Media foreignObjects are deliberately NOT children of the transformed// card group. Move their absolute coordinates in lockstep while dragging.@@ -112,23 +129,55 @@ export default function LoomCanvas({const handlePointerUp = () => {const drag = dragRef.current;dragRef.current = null;- if (!drag) return;- if (drag.moved) {- if (drag.cardEl) drag.cardEl.dataset.loomDragged = '1';- if (drag.mediaEl) drag.mediaEl.dataset.loomDragged = '1';- onMoveNode?.(drag.id, { x: Math.round(drag.x), y: Math.round(drag.y) });- }+ if (!drag?.moved) return;+ draggedRef.current = true;+ onMoveNode?.(drag.id, { x: Math.round(drag.x), y: Math.round(drag.y) });+ };++ const handleSurfacePointerDown = (event) => {+ // Cleared at the START of every gesture: a drag released outside the canvas+ // (or cancelled) never gets its click, and a stale flag would then swallow+ // the next genuine select.+ draggedRef.current = false;+ if (event.pointerType !== 'mouse' || event.button !== 0) return;+ // This runs after the card's own pointerdown, so `dragRef` already answers+ // "did a scene card claim this drag?" — ask it rather than re-deriving the+ // card handler's eligibility rules from the event target. On the stacked+ // layout cards never claim a drag, so a card is pannable surface there.+ if (dragRef.current) return;+ const surface = event.currentTarget;+ surface.setPointerCapture?.(event.pointerId);+ panRef.current = {+ start: { x: event.clientX, y: event.clientY },+ scrollLeft: surface.scrollLeft,+ scrollTop: surface.scrollTop,+ moved: false,+ };+ };++ const handleSurfacePointerMove = (event) => {+ const pan = panRef.current;+ const delta = pan && gestureDelta(pan, event);+ if (!delta) return;+ const surface = event.currentTarget;+ surface.scrollLeft = pan.scrollLeft - delta.dx;+ surface.scrollTop = pan.scrollTop - delta.dy;+ };++ const handleSurfacePointerUp = () => {+ const pan = panRef.current;+ panRef.current = null;+ if (pan?.moved) draggedRef.current = true;};- const handleNodeActivate = (event, nodeId) => {- // A completed mouse-drag fires click on the card too — ignore that one so- // repositioning doesn't also select (and so we don't persist stacked-layout- // coordinates as desktop `pos` via a follow-up navigate).- if (event?.currentTarget?.dataset?.loomDragged === '1') {- delete event.currentTarget.dataset.loomDragged;- return;- }- onSelectNode?.(nodeId);+ // Either drag still fires a click when it ends — on the card, on an edge, or+ // (once the pointer was captured) on the surface itself. One capture-phase+ // handler on the common ancestor swallows it wherever it lands, so a drag+ // never also selects.+ const handleSurfaceClickCapture = (event) => {+ if (!draggedRef.current) return;+ draggedRef.current = false;+ event.stopPropagation();};if (!nodes.length) return null;@@ -144,9 +193,14 @@ export default function LoomCanvas({<div className="relative h-full w-full"><divref={measureRef}- className={`overflow-auto h-full w-full overscroll-contain ${showStrip ? 'pb-28' : ''}`}+ className={`overflow-auto h-full w-full overscroll-contain cursor-grab active:cursor-grabbing ${showStrip ? 'pb-28' : ''}`}data-testid="loom-canvas"data-orientation={orientation}+ onPointerDown={handleSurfacePointerDown}+ onPointerMove={handleSurfacePointerMove}+ onPointerUp={handleSurfacePointerUp}+ onPointerCancel={handleSurfacePointerUp}+ onClickCapture={handleSurfaceClickCapture}><svgwidth={width}@@ -246,7 +300,8 @@ export default function LoomCanvas({onPointerDown={(e) => handlePointerDown(e, node)}onPointerMove={handlePointerMove}onPointerUp={handlePointerUp}- onClick={(e) => handleNodeActivate(e, node.id)}+ onPointerCancel={handlePointerUp}+ onClick={() => onSelectNode?.(node.id)}onKeyDown={(e) => {if (e.key === 'Enter' || e.key === ' ') {e.preventDefault();@@ -321,7 +376,8 @@ export default function LoomCanvas({onPointerDown={(event) => handlePointerDown(event, node)}onPointerMove={handlePointerMove}onPointerUp={handlePointerUp}- onClick={(event) => handleNodeActivate(event, node.id)}+ onPointerCancel={handlePointerUp}+ onClick={() => onSelectNode?.(node.id)}><div className="h-full w-full min-w-0 overflow-hidden" xmlns="http://www.w3.org/1999/xhtml"><LoomSceneMediadiff --git a/client/src/components/fableloom/LoomCanvas.test.jsx b/client/src/components/fableloom/LoomCanvas.test.jsxindex 374f139949..efd111ae39 100644--- a/client/src/components/fableloom/LoomCanvas.test.jsx+++ b/client/src/components/fableloom/LoomCanvas.test.jsx@@ -233,6 +233,129 @@ describe('LoomCanvas', () => {expect(screen.queryByTestId('loom-path-strip')).not.toBeInTheDocument();});+ it('pans the graph when the canvas background is dragged with the mouse', () => {+ render(<LoomCanvas episode={episode()} selectedNodeId={null} onSelectNode={() => {}} />);+ const surface = screen.getByTestId('loom-canvas');+ surface.scrollLeft = 120;+ surface.scrollTop = 60;++ fireEvent.pointerDown(surface, { pointerId: 1, pointerType: 'mouse', button: 0, clientX: 200, clientY: 200 });+ fireEvent.pointerMove(surface, { pointerId: 1, pointerType: 'mouse', clientX: 150, clientY: 170 });+ fireEvent.pointerUp(surface, { pointerId: 1, pointerType: 'mouse' });++ // The delta applies against the scroll offset captured at pointerdown.+ expect(surface.scrollLeft).toBe(170);+ expect(surface.scrollTop).toBe(90);+ });++ it('pans from a scene card on the stacked layout, where no card claims a drag', () => {+ const onMoveNode = vi.fn();+ render(+ <LoomCanvas+ episode={episode()}+ selectedNodeId={null}+ onSelectNode={() => {}}+ onMoveNode={onMoveNode}+ viewportWidth={390}+ />,+ );+ const surface = screen.getByTestId('loom-canvas');+ expect(surface).toHaveAttribute('data-orientation', 'tb');+ const card = screen.getByLabelText('Scene: The Gate');++ fireEvent.pointerDown(card, { pointerId: 6, pointerType: 'mouse', button: 0, clientX: 200, clientY: 300 });+ fireEvent.pointerMove(surface, { pointerId: 6, pointerType: 'mouse', clientX: 200, clientY: 220 });+ fireEvent.pointerUp(surface, { pointerId: 6, pointerType: 'mouse' });++ // Stacked cards span nearly the whole surface, so they must be pannable;+ // they must still never persist stacked coordinates as desktop `pos`.+ expect(surface.scrollTop).toBe(80);+ expect(onMoveNode).not.toHaveBeenCalled();+ });++ it('leaves a card drag to the card rather than panning the view', () => {+ const onMoveNode = vi.fn();+ const onSelectNode = vi.fn();+ render(+ <LoomCanvas+ episode={episode()}+ selectedNodeId={null}+ onSelectNode={onSelectNode}+ onMoveNode={onMoveNode}+ />,+ );+ const surface = screen.getByTestId('loom-canvas');+ const card = screen.getByLabelText('Scene: The Gate');+ surface.scrollLeft = 40;++ // The card captures the pointer, so the browser retargets the rest of the+ // gesture to it — fire there rather than on the surface.+ fireEvent.pointerDown(card, { pointerId: 2, pointerType: 'mouse', button: 0, clientX: 100, clientY: 100 });+ fireEvent.pointerMove(card, { pointerId: 2, pointerType: 'mouse', clientX: 140, clientY: 130 });+ fireEvent.pointerUp(card, { pointerId: 2, pointerType: 'mouse' });++ expect(onMoveNode).toHaveBeenCalledWith('n1', expect.objectContaining({ x: expect.any(Number) }));+ expect(surface.scrollLeft).toBe(40);++ // Repositioning a card must not also select it — the click the drag ends+ // with is swallowed by the surface, wherever the browser retargets it.+ fireEvent.click(card);+ expect(onSelectNode).not.toHaveBeenCalled();+ });++ it('keeps a press that never moved a select, not a drag', () => {+ const onSelectNode = vi.fn();+ render(<LoomCanvas episode={episode()} selectedNodeId={null} onSelectNode={onSelectNode} />);+ const surface = screen.getByTestId('loom-canvas');+ const card = screen.getByLabelText('Scene: The Gate');++ fireEvent.pointerDown(card, { pointerId: 3, pointerType: 'mouse', button: 0, clientX: 100, clientY: 100 });+ fireEvent.pointerMove(card, { pointerId: 3, pointerType: 'mouse', clientX: 102, clientY: 101 });+ fireEvent.pointerUp(card, { pointerId: 3, pointerType: 'mouse' });+ fireEvent.click(card);++ // Inside DRAG_THRESHOLD_PX, so nothing moved and the click still selects.+ expect(surface.scrollLeft).toBe(0);+ expect(onSelectNode).toHaveBeenCalledWith('n1');+ });++ it('swallows the click that ends a drag, wherever that click lands', () => {+ const onSelectNode = vi.fn();+ render(<LoomCanvas episode={episode()} selectedNodeId={null} onSelectNode={onSelectNode} />);+ const surface = screen.getByTestId('loom-canvas');+ const label = screen.getByLabelText('Path: enter the gate');++ fireEvent.pointerDown(label, { pointerId: 4, pointerType: 'mouse', button: 0, clientX: 300, clientY: 300 });+ fireEvent.pointerMove(surface, { pointerId: 4, pointerType: 'mouse', clientX: 240, clientY: 300 });+ fireEvent.pointerUp(surface, { pointerId: 4, pointerType: 'mouse' });+ fireEvent.click(label);++ expect(surface.scrollLeft).toBe(60);+ expect(onSelectNode).not.toHaveBeenCalled();++ // A cancelled gesture that never produced its click must not leave the+ // suppression armed and eat the next genuine select.+ fireEvent.pointerDown(surface, { pointerId: 5, pointerType: 'mouse', button: 0, clientX: 10, clientY: 10 });+ fireEvent.pointerMove(surface, { pointerId: 5, pointerType: 'mouse', clientX: 60, clientY: 10 });+ fireEvent.pointerCancel(surface, { pointerId: 5, pointerType: 'mouse' });+ fireEvent.pointerDown(label, { pointerId: 7, pointerType: 'mouse', button: 0, clientX: 300, clientY: 300 });+ fireEvent.pointerUp(surface, { pointerId: 7, pointerType: 'mouse' });+ fireEvent.click(label);+ expect(onSelectNode).toHaveBeenCalledWith('n2');+ });++ it('ignores a touch drag on the background so the native scroll gesture survives', () => {+ render(<LoomCanvas episode={episode()} selectedNodeId={null} onSelectNode={() => {}} />);+ const surface = screen.getByTestId('loom-canvas');+ surface.scrollTop = 25;++ fireEvent.pointerDown(surface, { pointerId: 8, pointerType: 'touch', button: 0, clientX: 200, clientY: 200 });+ fireEvent.pointerMove(surface, { pointerId: 8, pointerType: 'touch', clientX: 200, clientY: 120 });+ fireEvent.pointerUp(surface, { pointerId: 8, pointerType: 'touch' });++ expect(surface.scrollTop).toBe(25);+ });+it('stacks the graph and shows a path strip on a narrow canvas', () => {const onSelectNode = vi.fn();render(diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex b6fd846fec..6a2629dfc3 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -110,7 +110,7 @@ grep -i "what you want to do" client/src/lib/README.md| Module | Purpose ||---|---|| `brainGraphFocus.js` | Pure focus-trail (breadcrumb) transitions for BrainGraph re-focus navigation. |-| `graphPicking.js` | Screen-space touch picking for the 3D brain graph (#4114). `projectToScreen(point, viewProjection, width, height)` projects a world point to canvas-local pixels (y down, `null` when the point sits on or behind the camera plane); `pickNearestNodeByScreenDistance({ nodes, viewProjection, width, height, point, threshold })` returns the node whose projected centre is nearest the tap within `TOUCH_PICK_THRESHOLD_PX` (44px — a max-importance sphere only projects to ~38px at `OrbitControls minDistance`, so a tap anywhere inside a node still lands), tie-broken by depth then array order; `isTapGesture(start, end, slop)` separates a tap from an orbit drag (`TAP_SLOP_PX`). Takes the 16 flattened column-major `THREE.Matrix4` elements rather than a camera, so it stays three.js-free and unit-testable — jsdom has no WebGL context and therefore no raycast to exercise. |+| `graphPicking.js` | Screen-space touch picking for the 3D brain graph (#4114). `projectToScreen(point, viewProjection, width, height)` projects a world point to canvas-local pixels (y down, `null` when the point sits on or behind the camera plane); `pickNearestNodeByScreenDistance({ nodes, viewProjection, width, height, point, threshold })` returns the node whose projected centre is nearest the tap within `TOUCH_PICK_THRESHOLD_PX` (44px — a max-importance sphere only projects to ~38px at `OrbitControls minDistance`, so a tap anywhere inside a node still lands), tie-broken by depth then array order; `isTapGesture(start, end, slop)` separates a tap from a drag (`TAP_SLOP_PX`) — the picking helpers are 3D-only, but this one is the tree-wide movement-slop predicate and takes plain client coordinates, so 2D canvases use it too (`fableloom/LoomCanvas.jsx` passes its own tighter slop for node drag vs pan). Takes the 16 flattened column-major `THREE.Matrix4` elements rather than a camera, so it stays three.js-free and unit-testable — jsdom has no WebGL context and therefore no raycast to exercise. || `graphSimulation.js` | 3D force simulation parameters for BrainGraph / OpenWorld. || `goalFeatureMap.js` | Re-export of `server/lib/goalFeatureMap.js` — deterministic goal `category` → PortOS feature-area deep-link map (Daily Driver). `getGoalFeatureAreas(goal)` honors the per-goal `featureAreas` override. |