Walkontable dev

From handsontable/handsontable · View interactive version

Walkontable dev is an AI agent skill from the GitHub repository handsontable/handsontable. Use when modifying the Walkontable rendering engine in src/3rdparty/walkontable/ - overlay system, viewport calculations, scroll handling, DOM management, or the TableView bridge between core Handsontable and Walkontable

How to use this skill

Skill file

Walkontable Development Guide

Walkontable is the rendering engine (viewport calculation, DOM rendering, scroll sync, overlays). Rules and traps live in handsontable/src/3rdparty/walkontable/AGENTS.md; architecture in handsontable/src/3rdparty/walkontable/.ai/ARCHITECTURE.md and .ai/CONCERNS.md.

Architecture boundary

Source is TypeScript in src/3rdparty/walkontable/src/, excluded from the main tsconfig.json, with its own build/test pipeline. The bridge to core is TableView in src/tableView.ts. Plugins and core reach Walkontable only through TableView or the public Core API. Inside Walkontable, wrap DOM logic in abstraction modules.

Dependency injection and DOM geometry reads (mandatory, lint-enforced)

Dependency injection

wire.ts is the single composition root: buildContext(wot) returns an EngineContext. Each module has a co-located factory create<Module>Deps(ctx); its type is inferred.

// scroll/scroll.ts: the only place Scroll's deps are declared
export function createScrollDeps(ctx: EngineContext) {
  return { wtSettings: ctx.wtSettings, geometryReader: ctx.geometryReader, getWtTable: ctx.getWtTable /* … */ };
}
export type ScrollDeps = ReturnType<typeof createScrollDeps>;

class Scroll {
  #deps: ScrollDeps;
  constructor(deps: ScrollDeps) { this.#deps = deps; }
}

DOM geometry reads go through the `GeometryReader` proxy

Layout-forcing reads go through the injected reader: getBoundingClientRect, getClientRects, getComputedStyle, offsetWidth/offsetHeight/offsetTop/offsetLeft/offsetParent, clientWidth/clientHeight, scrollWidth/scrollHeight, and the helpers/dom/element measurement helpers (offset, outerWidth/outerHeight, element innerWidth/innerHeight, getMaximumScrollTop/getMaximumScrollLeft, getScrollbarWidth, getStyle). The reader is the seam a future per-draw CachingGeometryReader replaces.

Scroll-position and window-viewport reads are read directly: scrollX/scrollY/pageXOffset/pageYOffset, element scrollTop/scrollLeft, window innerWidth/innerHeight. For a polymorphic element-or-window scroll position use the raw getScrollLeft/getScrollTop helper (it also survives an iframe realm boundary, where the instanceof Window-gated helper returns undefined).

const rect = this.#deps.geometryReader.getBoundingClientRect(el);
const w = this.#deps.geometryReader.offsetWidth(el);
const top = rootWindow.scrollY;       // direct

Reader handles: this.#deps.geometryReader (most modules), this.deps.geometryReader (overlays/table), wotInstance.domBindings.geometryReader when only the instance is in hand (utils/pointerToCoords.ts, selection/border/border.ts).

Writes (el.scrollTop = n, el.style.x = …) and this.<field> (stored state, even when named clientHeight/scrollTop) are direct.

When the proxy lacks a method for a layout-forcing read, add it to both domMeasure/geometryReader.ts (interface) and domMeasure/liveGeometryReader.ts (live adapter), then use it.

ESLint rule handsontable/no-direct-dom-geometry-read (error) covers all of src/3rdparty/walkontable/src except domMeasure/**. The rule lives in handsontable/.config/plugin/eslint/rules/ and is a pnpm file: dependency that is copied, not symlinked: after editing the rule (or on a checkout that predates it) run pnpm install, or eslint fails with "definition not found".

Key subsystems

Single-pass layout and sizing

The engine predicts scrollbars from numbers instead of render, measure, re-render:

singlePassLayout escape hatch. The prediction is used only in element mode with uniform sizes and the singlePassLayout setting on. TableView sets it to false whenever mergeCells is enabled (a virtualized merged cell's height depends on the viewport being computed); window-scrolled tables fall back to measurement too. Any new method that reads getLayout() must branch on singlePassLayout and window mode and fall back to a direct DOM measure otherwise; without that branch, merged-cell and window-scrolled tables break. Viewport.usesLayoutSnapshotForCalculators() is the gate predicate.

Draw orchestration: table/drawCycle.ts; Table.draw() delegates to the class-free runDrawCycle(table, fastDraw).

Known technical debt (details in `.ai/CONCERNS.md`)

Performance rules

Testing

Walkontable has its own runner, separate from the main E2E pipeline.

Key source files

| Path | Purpose |

|---|---|

| src/3rdparty/walkontable/src/ | All Walkontable source |

| src/tableView.ts | Bridge to core (the boundary for plugins) |

| src/3rdparty/walkontable/src/overlay/ | Overlay system |

| src/3rdparty/walkontable/src/render/ | DOM rendering |

| src/3rdparty/walkontable/src/viewport/boxLayout/ | Layout snapshot + scrollbar fix-point solver |

| src/3rdparty/walkontable/src/axisSizing/ | Size sources, prefix-sum caches, box model |

| src/3rdparty/walkontable/src/domMeasure/ | GeometryReader proxy + live adapter |

| src/3rdparty/walkontable/src/table/drawCycle.ts | runDrawCycle |

| src/3rdparty/walkontable/src/wire.ts | Composition root (buildContext → EngineContext) |

Common mistakes

TypeScript gotchas

1. Generalize the signature instead of casting

When a function receives a value whose shape varies, make the signature generic instead of casting with as SomeType (or <SomeType>value). For any, take a type parameter; use unknown at boundaries and narrow with a type guard.

function getFirst<T>(items: T[]): T { return items[0]; }
const row = getFirst(rows); // typed as UserRow

1a. DOM narrowing

Narrow a Node | Element | null with isHTMLElement from src/helpers/dom/element.ts wherever you would write x as HTMLElement, x instanceof HTMLElement, or a nodeType === Node.ELEMENT_NODE guard. From Walkontable source the import is ../../../../helpers/dom/element (adjust ../ count to file depth).

if (isHTMLElement(node.nextSibling)) { /* HTMLElement here */ }

2. Declarations are generated

Fix the JSDoc/export in the .ts source and rerun npm run build:types; handsontable/tmp/ stays generated.

3. `import type` for types

import type { ViewportColumnsCalculator } from './calculator/viewportColumns';

4. Shared types live in `core/`

| Type | Location |

|---|---|

| GridSettings, Events, HookKey | src/core/settings.ts |

| HotInstance | src/core/types.ts |

Import them with import type; never paste a partial copy of GridSettings/HotInstance into the file you are editing (a local copy drifts from the real signature).

5. Private fields use `#`; callbacks are arrow-function class fields

class Overlay {
  #cachedWidth: number | null = null;
  #onScroll = (): void => { /* `this` is bound */ };
}

@private JSDoc tags and .bind(this) are forbidden.

6. Cognitive complexity ≤ 15 per function

ESLint fails the build above it; extract a helper.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.