Plugin file structure
src/plugins/{pluginName}/
├── index.ts # Re-exports PLUGIN_KEY, PLUGIN_PRIORITY, ClassName
├── {pluginName}.ts # Main class extending BasePlugin
├── AGENTS.md # Plugin knowledge file, REQUIRED (see below)
├── CLAUDE.md # symlink -> AGENTS.md, never a copy
├── types.ts # (optional) exported plugin-local types
├── __tests__/ # *.unit.js unit tests (new E2E is Playwright, in tests/e2e/)
└── {submodules}/ # UI classes, strategies, etc.
Contract
Statics (PLUGIN_KEY, PLUGIN_PRIORITY, SETTING_KEYS, PLUGIN_DEPS – generated from feature.json, see "Plugin dependencies" below, DEFAULT_SETTINGS, SETTINGS_VALIDATORS), lifecycle order, onUpdateSettings, hard conflicts, and the PLUGIN_PRIORITY table: src/plugins/base/AGENTS.md. Pick a free priority number from that table and add your row to it.
Key patterns (gold standard: `src/plugins/pagination/pagination.ts`)
- Configure in
enablePlugin(), touch the grid inonGridReady():enablePlugin()/updatePlugin()register hooks and index maps and read settings only. Work that reads the rows,hot.view, the DOM or the editor manager goes in the optionalonGridReady(), which core runs once after every enable or update, when all of them exist. Never writeif (this.hot.view)in enable/update, and never park that work on aninit/afterInitlistener (src/plugins/base/AGENTS.md, "The ready step"). The step runs after every update too, so whenupdatePlugin()oronDataReady()already does the same work, keep a private#...Owedflag set inenablePlugin()and cleared by whichever path does it, or the work runs twice per update (CustomBorders, Pagination and MergeCells are worked examples). At init core holds the renders a step asks for, so the step may sort or write cells; the first render draws the result. - Private fields:
#prefix for all internal state, no@privateJSDoc. - Hook callbacks (required for new code): pass
#on*handlers toaddHookas arrow function class fields, directly:this.addHook('afterLoadData', this.#onAfterLoadData)(priority stays the 3rd arg)..bind(this)builds a new function per call, so the registered reference can never be removed. Existing inline-wrapper sites work; leave them as they are. - Hook registration:
this.addHook()auto-cleans ondisablePlugin();this.hot.addHook()does not. Register new hook names at module level:Hooks.getSingleton().register('beforeMyAction');(importHooksfrom'../../core/hooks'). - Settings: read via
this.getSetting('key')(dot notation supported); defaults come fromDEFAULT_SETTINGS. - Conflict registration (module level, before the class), then check
this.isHardConflictBlocked()inenablePlugin():
```js
import { registerConflict } from '../base/conflictRegistry';
registerConflict(PLUGIN_KEY, ['nestedRows', 'mergeCells']);
```
- IndexMapper: create maps in
enablePlugin(), unregister indisablePlugin():
```js
this.#map = this.hot.rowIndexMapper.createAndRegisterIndexMap(this.pluginName, 'hiding', false);
// 'hiding' = HidingMap (not rendered, stays in DataMap); 'trimming' = TrimmingMap (removed from DataMap)
```
- UI: extract it into its own class with dependency injection (no direct
hotreference). Swappable logic uses a strategy (e.g.autoPageSizevsfixedPageSize). - Batch rendering: wrap multiple data/render changes in
this.hot.batch(() => { ... })for one render, but never around code that can run host code (updateSettings,loadData, another plugin's hooks).Core#batch/batchRenderdo not resume in afinally, so a listener that throws mid-batch leaves the grid render-suspended for good. For such code, callthis.hot.suspendRender()and putthis.hot.resumeRender()in afinally. - Sliced per-unit settings (one plugin managing several units, e.g. sheets): treat each unit's settings as a partial slice, applying only the declared keys. Apply the slice and its data together in one guarded batch (
suspendRender()+ try/finallyresumeRender()), and run the swap directly whenthis.hot.viewdoes not exist yet (initial setup). Reference:src/plugins/sheetsBar/sheetsBar.ts(#applySheet). A plugin that also owns a layout slot (handsontable/AGENTS.md"Wrapper UI placement") registers its UI once inenablePlugin(); this method owns only the settings/data swap.
Decoupling rules
- Cross-plugin access goes through hooks or
hot.getPlugin('{Name}'), never imports; no circular dependencies between plugins. - The plugin introducing the incompatibility owns the blocking logic.
- For custom error UI when Notification is off, use the hooks
afterDataProviderFetchErrorandafterRowsMutationError. Built-in DataProvider toasts:src/plugins/dataProvider/AGENTS.md.
Registration checklist
index.ts:export { PLUGIN_KEY, PLUGIN_PRIORITY, ClassName } from './pluginName';- Wire into
src/plugins/index.ts. - Add the default option (disabled) in
src/dataMap/metaManager/metaSchema.ts. - For new hook signatures or settings, add them to
src/core/settings.ts(GridSettings);npm run build:typesregenerates the public.d.tsfiles intotmp/. - Write
AGENTS.mdand symlinkCLAUDE.mdto it with the relative target, so the link resolves in a git worktree:
```bash
cd handsontable/src/plugins/myPlugin && ln -s AGENTS.md CLAUDE.md
```
Git stores it as mode 120000; a regular file in git status means you copied.
- Add your
PLUGIN_PRIORITYrow to the table insrc/plugins/base/AGENTS.md, in the same change: nothing enforces it, so it drifts silently. - Add the plugin to
tests/a11y/coverage.mjs: the pages that scan it, why it draws nothing, or a counted gap. The roottest:toolingfails until you do. A plugin with UI adds a page totests/a11y/pages.mjsand follows thehandsontable-a11yskill (plan, build rules, proof). - Write
feature.jsonin the plugin folder – its feature manifest entry (feat:<plugin_key_in_snake_case>,licensing: "token", agate, a plain-Englishnameanddescription, andrequires– only what the plugin cannot work without). Then runnpm run generate:feature-manifest --prefix handsontableand commit what it writes. The unit suite fails until the entry exists. Copy an existing one (src/plugins/filters/feature.json); the fields and rules are insrc/featureManifest/AGENTS.md.
Plugin dependencies (`PLUGIN_DEPS`) are generated
Never write a PLUGIN_DEPS array in the class. Declare what the plugin needs in requires.allOf of its feature.json. Add "enforceAtInit": true only when new Handsontable() must throw if the module is not registered: the generator then writes the 'type:Name' list to feature.generated.ts in the folder, and the class returns a copy of it:
import { PLUGIN_DEPS } from './feature.generated';
static get PLUGIN_DEPS() {
return [...PLUGIN_DEPS];
}
To change a dependency, edit feature.json and run generate:feature-manifest; never edit feature.generated.ts by hand. Turn enforceAtInit on for every dependency the plugin cannot work without, and add a __tests__/pluginDependencies.unit.ts like the others. For a plugin no release has shipped yet that costs nothing. For a released plugin it is a breaking change for modular users: add a migration-guide step and a breaking changelog entry (Loading → Dialog, 19.0).
The license token (`LICENSE`) is generated too
A plugin with licensing: "token" (every new one) gets a LICENSE export in the same feature.generated.ts: its token (capability), display name, gate and tiers. The class returns it, and the unit suite fails until it does:
import { LICENSE } from './feature.generated';
static get LICENSE() {
return LICENSE;
}
With it, the plugin stays off when the license key names tiers and none of them is in the plugin's LICENSE.tiers (BasePlugin#isLicenseBlocked(), at the same places as a hard conflict, never rewriting the setting). Pick gate: "enable" for a plugin turned on by its option. A plugin on in every grid (isEnabled() returns true) takes gate: "call" and checks the token itself at the top of each public method that does work: assertLicensedCall(this.hot, LICENSE) from utils/licenseNotification.ts, or isLicensedUse() where a throw would break a render. And when your plugin asks another plugin whether it runs, read .enabled, never isEnabled(): a plugin the key leaves out keeps its setting. Rules: src/utils/entitlementLicenseKey/AGENTS.md.
Focus management
A plugin with UI (buttons, inputs, navigation bars) integrates with src/focusManager/. Reference: Pagination (#registerFocusScope / #unregisterFocusScope). Roles, names, keys and announcements for that UI: the handsontable-a11y skill.
- Register a focus scope with a unique name for the plugin's UI region.
- On scope activation, focus the first element for Tab and the last for Shift+Tab.
- Decide whether your scope COVERS the grid or REPLACES it. Activating a scope switches the shortcut manager to the scope's
shortcutsContextName, and only that context runs, so an empty one kills every grid shortcut while your UI is up (emptyDataStateshipped that way; DEV-53). An overlay the user still thinks of as "the grid underneath" addsfallbackShortcutsContextName: 'grid'toregisterScope()and inherits every grid shortcut, including ones added later (reference:emptyDataState). A modal scope leaves it unset: letting grid shortcuts through a modal is the bug. Register a shortcut in your own context only to OVERRIDE one, and record in yourAGENTS.mdwhy the grid's version does not fit. - UI painted OVER the grid body also adds
coversGridBody: true. Inheriting and covering are separate questions. Without the flag, a content-writing shortcut sees that the grid still draws cells and letsDeletereach data the user cannot touch (DEV-2917:emptyDataStatecovered a rendered grid during a DataProvider fetch and the dataset was wiped). The flag is read from every ENABLED scope, not only the active one.
Gotchas
- Merged cells: read
colspan/rowspanfromhot.getCellMeta(row, col)(set by MergeCells viaafterGetCellMeta), not from DOM attributes; the meta is available regardless of viewport state.
Knowledge file (required)
Every plugin directory carries an AGENTS.md with CLAUDE.md symlinked to it; a new plugin without one is incomplete. Edit AGENTS.md, never CLAUDE.md.
It answers "what must I never get wrong here, and where do I look next": the reason a guard exists, the load-bearing ordering, the shortcut that looks right and is wrong. Required sections:
# {PluginName} plugin – {one-line focus}, then one or two sentences naming the files covered and saying "Read this before touching X." (10 pre-existing files lack## Where to look nextor## Testing; new files carry both, and fixing those 10 belongs in its own change.)- What it owns and what it does not. Most plugin bugs are ownership confusion.
- The traps, each with the reason it exists (and the issue or DEV id where you have one). "Do not reorder these calls, because Formulas syncs the data source in that hook and selecting first made
afterSelectionread the stale value" survives; the bare rule gets undone. ## Where to look next: sibling plugins, the.ai/reference,../base/AGENTS.mdfor the contract, and this skill for the workflow.## Testing: targeted commands and anything non-obvious about the suite (a__tests__/split, a spec failing for an unrelated reason, a case needing a real device).
Length follows the plugin: stretchColumns/AGENTS.md (three bullets) and base/AGENTS.md (the contract for every plugin) are the two ends; read one of each before writing yours.
Where a fact belongs. A trap found while changing an existing plugin goes in that plugin's AGENTS.md. handsontable/AGENTS.md holds rules that span plugins; for a core-wide rule with one worked example, state the rule there and put the example in the plugin file with a pointer back.
Testing requirements
- New E2E tests are Playwright in
tests/e2e/(skillhandsontable-playwright-e2e) for a plugin's UI, interaction, and rendering. The presence gate blocks new legacy*.spec.js; editing an existing one (asyncit()callbacks) is fine. - Unit tests (
__tests__/*.unit.js): strategies and helpers in isolation. - Cover
updateSettings(),enablePlugin()/disablePlugin()toggling, and interactions with other plugins (sorting, filters, hidden rows).
Base class: src/plugins/base/base.ts. Deeper context: handsontable/.ai/ARCHITECTURE.md, handsontable/.ai/CONVENTIONS.md.