Skip to content

Extract createInputController #113

Open

Description

@JadRizk

Part of #107.

Merge: held until 2.0 ships. Depends on #112.

Scope: move pointer, wheel and keyboard dispatch into createInputController(deps). The navigate reducer is untouched. Make the wheel zoom-anchor maths pure.

Acceptance: the same as #111. The recording's pointer, wheel and keyboard scenarios are unchanged.

Activity

  1. added
    refactorCode-quality refactor tracked under the code-quality direction issue
    on Oct 10, 2026
  2. JadRizk commented on Oct 11, 2026

    @JadRizk
    OwnerAuthor

    Scope notes

    Checked against origin/refactor/112-scene-labels at 0a96d69. The PR body starts with "⏸ Held until 2.0 ships (see #107)", then "Stacked on #122".

    Files. All under packages/graph/src/, none exported:

    • input.ts: createInputController, zoomAbout, pastDragSlop. Not camera.ts: index.ts re-exports it through export *, so a helper there would change the public API.
    • input.test.ts
    • GraphCanvas.tsx
    • .changeset/graph-input-controller.md: patch, "Internal restructure; no API or behaviour change."

    Shape. createInputController(deps) returns { dragging() }, because the frame loop reads it. Listeners register through deps.track.

    • Deps: el, track, toWorld, pick, curve(), viewport, simulation (cursor, pin), rig (takeOver, panBy, live, target), hovered(), hover(i), showTooltip, dismissTooltip(), overlayFocused(), onPress(), click(i).
    • Refs are read through getters. That is the React 18 exception in the guide.
    • zoomAbout keeps today's expression order, and the viewport.curve write stays before the call.
    • handlePointerMove is split so it stays at complexity 12 or below.

    What stays in GraphCanvas, different from the issue's wording

    Ordering

    • The controller is built once, where the pointer code is today.
    • It adds listeners in this order: window keydown, pointermove, pointerdown, window pointerup, click, pointerleave, wheel {passive:false}.
    • It uses two track entries, so the removal order doesn't change.
    • It is built before frame, and webglcontextlost is still registered last.

    Unit-tested rather than recorded. The recordings are at 199.3 KB of 200 KB, so input.test.ts covers:

    • pointerleave
    • window Escape: suppression, preventDefault, and the early returns when the overlay is focused or there's no tooltip
    • suppression clearing on the next hover
    • the zoom clamp at both bounds, and the anchor fixed point
    • setPointerCapture throwing
    • cursor styles
    • the slop boundary at 3 and 3.5 px
    • dragging()
    • listener order and options

    Acceptance

    1. vitest run passes without -u, and git diff --exit-code packages/graph/src/__recordings__ is clean. That includes the listener lines in boot.mount and lifecycle.unmount.
    2. browser/graph.spec.ts passes, with its baselines unchanged.
    3. dist/index.d.ts and dist/index.d.cts are byte-identical to refactor/112-scene-labels, and the npm pack --dry-run file list is unchanged.
    4. A prettier-formatted diff of dist/index.js shows relocation only.
    5. Every new function is ≤ 60 code lines with cognitive complexity ≤ 12, and the graph lint warning count doesn't rise.
    6. Built on refactor/112-scene-labels, with that branch as the PR's base. navigator.ts is untouched.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactorCode-quality refactor tracked under the code-quality direction issue

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions