@omnigrid/core 0.1.28 → 0.1.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,275 +1,294 @@
1
- # @omnigrid/core
2
-
3
- Framework-agnostic core engine for OmniGrid — a fast, headless, extensible data grid.
4
- Pure TypeScript, zero runtime dependencies, **no DOM, no framework imports**. The core owns data,
5
- state, the data pipeline, 2D virtualization, DOM-pool row mapping, slots, and plugins; an adapter
6
- (the React adapter in `@omnigrid/react`) renders it into a UI.
7
-
8
- ## What it provides
9
-
10
- - **`Grid`** — entry point (`new Grid<T>(options)`), implements `GridApi<T>`.
11
- - **State Store** — observable `GridState<T>`; structural changes notify subscribers and emit `stateChange`.
12
- - **Data Pipeline** — plugins attach pure transforms (`T[] → T[]`) in registration order: raw → processed → virtualized.
13
- - **Virtualization Engine (2D)** — visible window of rows *and* columns plus overscan; offsets are absolute table-space coordinates.
14
- - **Event Bus** — typed `on(event, listener)`; returns an unsubscribe function.
15
- - **DOM Pool mapping** — the core decides *which* rows are visible; the adapter performs DOM ops via injected `DomPoolBindings`.
16
- - **Slot Manager / `GridApi.slots`** — headless widgets mounted by plugins into `top | bottom | left | right`.
17
- - **Icon Registry** — framework-agnostic declarative SVG icons for plugin UI (`api.icons.get(name)`).
18
-
19
- **Scroll is ephemeral, not state.** `scrollTop`/`scrollLeft` are kept out of the Store:
20
- scroll-only `setViewport({ scrollTop, scrollLeft })` calls never notify subscribers, so adapters do
21
- not re-render on scroll frames. Read them via `getScrollPosition()`; use `scrollTo()` to request an
22
- adapter-native scroll adjustment without moving scroll coordinates into the Store.
23
-
24
- ## Key contracts
25
-
26
- ### `GridOptions<T>`
27
-
28
- ```ts
29
- interface GridOptions<T> {
30
- data?: T[] | null; // row data; null/omitted means initial loading
31
- columns: ColumnDef<T>[]; // required
32
- getRowId?: (row: T, index: number) => RowId; // default: index-based
33
- rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
34
- rowOverscan?: number; // extra rows above/below viewport; default 5
35
- columnOverscan?: number; // extra columns beyond horizontal window; default 2
36
- suppressRowHoverHighlight?: boolean;
37
- rowStyle?: RowStyle;
38
- getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
39
- rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
40
- getRowClass?: (params: RowRenderParams<T>) => string | undefined;
41
- rowClassRules?: RowClassRules<T>; // class name → predicate
42
- plugins?: GridPlugin<T>[]; // plugin instances registered at construction
43
- loading?: boolean; // active fetch; shows loading even with prior rows
44
- overlayComponents?: Record<string, OverlayComponent<T>>;
45
- }
46
- ```
47
-
48
- Row callbacks receive `params.rowType` (`"leaf"` or `"group"`). Group rows are synthetic and have no `data`; checking `rowType` narrows the callback parameters.
49
-
50
- ### `ColumnDef<T>`
51
-
52
- `ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
53
-
54
- ```ts
55
- interface ColumnLeafDef<T> {
56
- id: string; // unique column id (also stable slot key)
57
- header: string;
58
- field?: keyof T | string; // value accessor (default cell value source)
59
- valueGetter?: (row: T) => unknown; // overrides field
60
- valueFormatter?: (value: unknown) => string;
61
- width?: number; // fixed px width
62
- flex?: number; // flex weight; expands to fill remaining space
63
- minWidth?: number;
64
- maxWidth?: number;
65
- hidden?: boolean;
66
- pinned?: "left" | "right"; // fixed column in horizontal viewport
67
- sortable?: boolean; // read by SortingPlugin
68
- sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
69
- sortIndex?: number; // runtime 1-based priority when multi-sorted
70
- align?: "left" | "center" | "right";
71
- cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
72
- cellStyle?: RowStyle;
73
- getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
74
- cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
75
- getCellClass?: (params: CellRenderParams<T>) => string | undefined;
76
- cellClassRules?: CellClassRules<T>;
77
- getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
78
- getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
79
- columnClassRules?: ColumnClassRules<T>;
80
- headerStyle?: HeaderStyle;
81
- getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
82
- headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
83
- getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
84
- headerClassRules?: HeaderClassRules<T>;
85
- headerRenderer?: (column: ColumnDef<T>) => unknown;
86
- stopRowClick?: boolean;
87
- stopHeaderClick?: boolean;
88
- }
89
-
90
- interface ColumnGroupDef<T> {
91
- id: string;
92
- header: string;
93
- children: ColumnDef<T>[]; // nested leaves / groups
94
- pinned?: "left" | "right";
95
- collapsible?: boolean;
96
- defaultExpanded?: boolean;
97
- headerStyle?: HeaderStyle;
98
- getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
99
- headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
100
- getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
101
- headerClassRules?: HeaderGroupClassRules<T>;
102
- headerRenderer?: (column: ColumnDef<T>) => unknown;
103
- }
104
- ```
105
-
106
- ### `GridApi<T>`
107
-
108
- `Grid<T>` implements this interface — the single public surface for adapters and plugins.
109
- UI code must never touch core internals directly.
110
-
111
- ```ts
112
- interface GridApi<T> {
113
- getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
114
- getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
115
- scrollTo(position: Partial<ScrollPosition>): void; // request a native scroll adjustment from the adapter
116
- getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
117
- getProcessedData(): T[]; // after all registered data processors
118
- getRowId(row: T, index: number): RowId;
119
- setData(data: T[] | null | undefined): void;
120
- setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
121
- refresh(): void; // repaint hints (rowClassRules), bumps revision
122
- subscribe(listener: () => void): () => void;
123
- on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
124
- registerPlugin(plugin: GridPlugin<T>): () => void;
125
- registerDataProcessor(processor: DataProcessor<T>): () => void;
126
- setColumns(columns: ColumnDef<T>[]): void;
127
- headerClick(columnId: string, multiSort?: boolean): void;
128
- rowClick(row: RowClickEvent<T>): void;
129
- rowHover(row: RowHoverEvent<T>): void;
130
- readonly slots: SlotManager<T>; // mount headless widgets
131
- readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
132
- getSlotMounts(slot: SlotName): SlotMount<T>[];
133
- showOverlay(options: OverlayOptions): void;
134
- hideOverlay(): void;
135
- getOverlayState(): OverlayState;
136
- setLoading(isLoading: boolean, error?: unknown): void;
137
- getRevision(): number; // monotonic counter for structural changes
138
- destroy(): void;
139
- isDestroyed(): boolean;
140
- }
141
- ```
142
-
143
- ### Overlays
144
-
145
- Overlays are managed in core state, so state transitions notify subscribers only when the
146
- overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
147
- loading; an explicit empty array shows the no-rows state. Empty processed results with source
148
- rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
149
- through `setLoading(false, error)`; a successful `setData` clears the error.
150
-
151
- ```ts
152
- grid.showOverlay({
153
- type: "error",
154
- // Errors default to "full"; other overlay types default to "bodyOnly".
155
- // Set scope explicitly to choose a different placement.
156
- message: "Could not load records",
157
- });
158
- grid.hideOverlay(); // restores automatic loading / empty-state evaluation
159
- const overlay = grid.getOverlayState();
160
- ```
161
-
162
- Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
163
- is present. Horizontal scrolling remains enabled by default and can be locked with
164
- `blockScroll: true`.
165
-
166
- `overlayComponents` accepts framework-specific components through the adapter or core render
167
- callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
168
-
169
- `GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
170
- Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
171
-
172
- ### Plugin contract — `GridPlugin<T>`
173
-
174
- ```ts
175
- interface GridPlugin<T> {
176
- name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
177
- register(api: GridApi<T>): void | (() => void); // returns cleanup
178
- getRowClass?(params: RowRenderParams<T>): string | undefined;
179
- getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
180
- }
181
- ```
182
-
183
- A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
184
- and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
185
- Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
186
- [`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
187
-
188
- ## Quick start
189
-
190
- Headless core only (no UI):
191
-
192
- ```ts
193
- import { Grid } from "@omnigrid/core";
194
- import type { ColumnDef } from "@omnigrid/core";
195
-
196
- interface Row { id: string; name: string }
197
-
198
- const columns: ColumnDef<Row>[] = [
199
- { id: "name", field: "name", header: "Name", width: 220 },
200
- ];
201
-
202
- const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
203
-
204
- grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
205
- const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
206
- grid.on("rowClick", (e) => console.log(e.index));
207
- grid.destroy();
208
- ```
209
-
210
- With base plugins:
211
-
212
- ```ts
213
- import { Grid } from "@omnigrid/core";
214
- import { SortingPlugin } from "@omnigrid/sorting-plugin";
215
- import { SelectionPlugin } from "@omnigrid/selection-plugin";
216
- import { PaginationPlugin } from "@omnigrid/pagination-plugin";
217
-
218
- const grid = new Grid<Row>({
219
- data,
220
- columns,
221
- getRowId: (row) => row.id,
222
- plugins: [
223
- new SortingPlugin<Row>(),
224
- new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
225
- new PaginationPlugin<Row>({ pageSize: 50 }),
226
- ],
227
- });
228
- ```
229
-
230
- In a UI framework, use the adapter — e.g. `@omnigrid/react`:
231
-
232
- ```tsx
233
- <OmniGrid columns={columns} data={rows} getRowId={(row) => row.id} plugins={plugins} style={{ height: 480 }} />
234
- ```
235
-
236
- See [@omnigrid/react](../../adapters/react/README.md).
237
-
238
- ## Exported helpers
239
-
240
- - `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
241
- - `resolveColSpan`, `getRowSpans`, `getCellSpanningParams` — column spanning
242
- (`ColumnDef.colSpan`): normalized per-cell spans and per-row merged layouts.
243
- - `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
244
- (mostly used internally; public for advanced integrations/tests).
245
-
246
- ### Column spanning (`colSpan`)
247
-
248
- A leaf column may merge horizontally across consecutive visible columns:
249
-
250
- ```ts
251
- const columns: ColumnDef<Row>[] = [
252
- { id: "title", width: 200, colSpan: 2 }, // static: always 2
253
- { id: "note", width: 160, colSpan: ({ data }) => (data.merged ? 3 : 1) },
254
- ];
255
- ```
256
-
257
- `resolveColSpan` normalizes one cell (floors, clamps to `>= 1`, clips to the
258
- pin group, falls back to `1` on resolver errors); `getRowSpans` / `Grid.getRowSpans`
259
- aggregates a whole row — the origin carries the summed pixel width aligned to
260
- the starting column, covered cells are skipped. `Grid.getViewportData`
261
- additionally exposes the full leaf groups (`leafColumns` + `columnOffsets`,
262
- pinned siblings likewise) and expands the shared column window so spans
263
- crossing the viewport boundary are never clipped. The React adapter resolves
264
- per-row layouts (memoized per viewport commit) and paints merged widths via
265
- `translateX` without breaking node recycling.
266
-
267
- ## Links
268
-
269
- - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
270
- - **Demo:** https://omnigrid-demo.vercel.app/
271
- - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
272
-
273
- ## License
274
-
275
- MIT © KRZK Apps
1
+ # @omnigrid/core
2
+
3
+ Framework-agnostic core engine for OmniGrid — a fast, headless, extensible data grid.
4
+ Pure TypeScript, zero runtime dependencies, **no DOM, no framework imports**. The core owns data,
5
+ state, the data pipeline, 2D virtualization, DOM-pool row mapping, slots, and plugins; an adapter
6
+ (the React adapter in `@omnigrid/react`) renders it into a UI.
7
+
8
+ ## What it provides
9
+
10
+ - **`Grid`** — entry point (`new Grid<T>(options)`), implements `GridApi<T>`.
11
+ - **State Store** — observable `GridState<T>`; structural changes notify subscribers and emit `stateChange`.
12
+ - **Data Pipeline** — plugins attach pure transforms (`T[] → T[]`) in registration order: raw → processed → virtualized.
13
+ - **Virtualization Engine (2D)** — visible window of rows _and_ columns plus overscan; offsets are absolute table-space coordinates.
14
+ - **Event Bus** — typed `on(event, listener)`; returns an unsubscribe function.
15
+ - **DOM Pool mapping** — the core decides _which_ rows are visible; the adapter performs DOM ops via injected `DomPoolBindings`.
16
+ - **Slot Manager / `GridApi.slots`** — headless widgets mounted by plugins into `top | bottom | left | right`.
17
+ - **Column header extensions** — plugins register independent header elements; adapters render them beside the shared label and controls.
18
+ - **Icon Registry** — framework-agnostic declarative SVG icons for plugin UI (`api.icons.get(name)`).
19
+
20
+ **Scroll is ephemeral, not state.** `scrollTop`/`scrollLeft` are kept out of the Store:
21
+ scroll-only `setViewport({ scrollTop, scrollLeft })` calls never notify subscribers, so adapters do
22
+ not re-render on scroll frames. Read them via `getScrollPosition()`; use `scrollTo()` to request an
23
+ adapter-native scroll adjustment without moving scroll coordinates into the Store.
24
+
25
+ ## Key contracts
26
+
27
+ ### `GridOptions<T>`
28
+
29
+ ```ts
30
+ interface GridOptions<T> {
31
+ data?: T[] | null; // row data; null/omitted means initial loading
32
+ columns: ColumnDef<T>[]; // required
33
+ getRowId?: (row: T, index: number) => RowId; // default: index-based
34
+ rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
35
+ rowOverscan?: number; // extra rows above/below viewport; default 5
36
+ columnOverscan?: number; // extra columns beyond horizontal window; default 2
37
+ cellFlash?: boolean | number; // highlight changed cells after applyTransaction
38
+ suppressRowHoverHighlight?: boolean;
39
+ rowStyle?: RowStyle;
40
+ getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
41
+ rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
42
+ getRowClass?: (params: RowRenderParams<T>) => string | undefined;
43
+ rowClassRules?: RowClassRules<T>; // class name → predicate
44
+ plugins?: GridPlugin<T>[]; // plugin instances registered at construction
45
+ loading?: boolean; // active fetch; shows loading even with prior rows
46
+ overlayComponents?: Record<string, OverlayComponent<T>>;
47
+ }
48
+ ```
49
+
50
+ Row callbacks receive `params.rowType` (`"leaf"` or `"group"`). Group rows are synthetic and have no `data`; checking `rowType` narrows the callback parameters.
51
+
52
+ ### `ColumnDef<T>`
53
+
54
+ `ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
55
+
56
+ ```ts
57
+ interface ColumnLeafDef<T> {
58
+ id: string; // unique column id (also stable slot key)
59
+ header: string;
60
+ field?: keyof T | string; // value accessor (default cell value source)
61
+ valueGetter?: (row: T) => unknown; // overrides field
62
+ valueFormatter?: (value: unknown) => string;
63
+ width?: number; // fixed px width
64
+ flex?: number; // flex weight; expands to fill remaining space
65
+ minWidth?: number;
66
+ maxWidth?: number;
67
+ hidden?: boolean;
68
+ pinned?: "left" | "right"; // fixed column in horizontal viewport
69
+ sortable?: boolean; // read by SortingPlugin
70
+ sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
71
+ sortIndex?: number; // runtime 1-based priority when multi-sorted
72
+ align?: "left" | "center" | "right";
73
+ cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
74
+ cellFlash?: boolean; // set false to opt out when GridOptions.cellFlash is enabled
75
+ cellStyle?: RowStyle;
76
+ getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
77
+ cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
78
+ getCellClass?: (params: CellRenderParams<T>) => string | undefined;
79
+ cellClassRules?: CellClassRules<T>;
80
+ getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
81
+ getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
82
+ columnClassRules?: ColumnClassRules<T>;
83
+ headerStyle?: HeaderStyle;
84
+ getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
85
+ headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
86
+ getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
87
+ headerClassRules?: HeaderClassRules<T>;
88
+ headerRenderer?: (column: ColumnDef<T>) => unknown; // primary header content; adapter controls remain separate
89
+ stopRowClick?: boolean;
90
+ stopHeaderClick?: boolean;
91
+ }
92
+
93
+ interface ColumnGroupDef<T> {
94
+ id: string;
95
+ header: string;
96
+ children: ColumnDef<T>[]; // nested leaves / groups
97
+ pinned?: "left" | "right";
98
+ collapsible?: boolean;
99
+ defaultExpanded?: boolean;
100
+ headerStyle?: HeaderStyle;
101
+ getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
102
+ headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
103
+ getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
104
+ headerClassRules?: HeaderGroupClassRules<T>;
105
+ headerRenderer?: (column: ColumnDef<T>) => unknown;
106
+ }
107
+ ```
108
+
109
+ When grid-level `cellFlash` is enabled, set `cellFlash: false` on an individual leaf column to opt it out.
110
+
111
+ ### `GridApi<T>`
112
+
113
+ `Grid<T>` implements this interface — the single public surface for adapters and plugins.
114
+ UI code must never touch core internals directly.
115
+
116
+ ```ts
117
+ interface GridApi<T> {
118
+ getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
119
+ getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
120
+ scrollTo(position: Partial<ScrollPosition>): void; // request a native scroll adjustment from the adapter
121
+ getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
122
+ getProcessedData(): T[]; // after all registered data processors
123
+ getRowId(row: T, index: number): RowId;
124
+ setData(data: T[] | null | undefined): void;
125
+ setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
126
+ refresh(): void; // repaint hints (rowClassRules), bumps revision
127
+ subscribe(listener: () => void): () => void;
128
+ on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
129
+ registerPlugin(plugin: GridPlugin<T>): () => void;
130
+ registerHeaderExtension(extension: ColumnHeaderExtension<T>): () => void;
131
+ getHeaderExtensions(position?: ColumnHeaderExtensionPosition): ColumnHeaderExtension<T>[];
132
+ registerDataProcessor(processor: DataProcessor<T>): () => void;
133
+ setColumns(columns: ColumnDef<T>[]): void;
134
+ headerClick(columnId: string, multiSort?: boolean): void;
135
+ rowClick(row: RowClickEvent<T>): void;
136
+ rowHover(row: RowHoverEvent<T>): void;
137
+ readonly slots: SlotManager<T>; // mount headless widgets
138
+ readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
139
+ getSlotMounts(slot: SlotName): SlotMount<T>[];
140
+ showOverlay(options: OverlayOptions): void;
141
+ hideOverlay(): void;
142
+ getOverlayState(): OverlayState;
143
+ setLoading(isLoading: boolean, error?: unknown): void;
144
+ getRevision(): number; // monotonic counter for structural changes
145
+ destroy(): void;
146
+ isDestroyed(): boolean;
147
+ }
148
+ ```
149
+
150
+ `registerHeaderExtension` lets plugins add header content without wrapping or replacing a
151
+ column's `headerRenderer`. Extensions render for each visible leaf column and can target the
152
+ `"start"`, `"end"`, or `"overlay"` region. Lower `priority` values render first; equal priorities
153
+ retain registration order. The returned cleanup callback removes the extension.
154
+
155
+ ### Overlays
156
+
157
+ Overlays are managed in core state, so state transitions notify subscribers only when the
158
+ overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
159
+ loading; an explicit empty array shows the no-rows state. Empty processed results with source
160
+ rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
161
+ through `setLoading(false, error)`; a successful `setData` clears the error.
162
+
163
+ ```ts
164
+ grid.showOverlay({
165
+ type: "error",
166
+ // Errors default to "full"; other overlay types default to "bodyOnly".
167
+ // Set scope explicitly to choose a different placement.
168
+ message: "Could not load records",
169
+ });
170
+ grid.hideOverlay(); // restores automatic loading / empty-state evaluation
171
+ const overlay = grid.getOverlayState();
172
+ ```
173
+
174
+ Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
175
+ is present. Horizontal scrolling remains enabled by default and can be locked with
176
+ `blockScroll: true`.
177
+
178
+ `overlayComponents` accepts framework-specific components through the adapter or core render
179
+ callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
180
+
181
+ `GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
182
+ Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
183
+
184
+ ### Plugin contract — `GridPlugin<T>`
185
+
186
+ ```ts
187
+ interface GridPlugin<T> {
188
+ name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
189
+ register(api: GridApi<T>): void | (() => void); // returns cleanup
190
+ getRowClass?(params: RowRenderParams<T>): string | undefined;
191
+ getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
192
+ }
193
+ ```
194
+
195
+ A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
196
+ and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
197
+ Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
198
+ [`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
199
+
200
+ ## Quick start
201
+
202
+ Headless core only (no UI):
203
+
204
+ ```ts
205
+ import { Grid } from "@omnigrid/core";
206
+ import type { ColumnDef } from "@omnigrid/core";
207
+
208
+ interface Row {
209
+ id: string;
210
+ name: string;
211
+ }
212
+
213
+ const columns: ColumnDef<Row>[] = [{ id: "name", field: "name", header: "Name", width: 220 }];
214
+
215
+ const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
216
+
217
+ grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
218
+ const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
219
+ grid.on("rowClick", (e) => console.log(e.index));
220
+ grid.destroy();
221
+ ```
222
+
223
+ With base plugins:
224
+
225
+ ```ts
226
+ import { Grid } from "@omnigrid/core";
227
+ import { PaginationPlugin } from "@omnigrid/pagination-plugin";
228
+ import { SelectionPlugin } from "@omnigrid/selection-plugin";
229
+ import { SortingPlugin } from "@omnigrid/sorting-plugin";
230
+
231
+ const grid = new Grid<Row>({
232
+ data,
233
+ columns,
234
+ getRowId: (row) => row.id,
235
+ plugins: [
236
+ new SortingPlugin<Row>(),
237
+ new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
238
+ new PaginationPlugin<Row>({ pageSize: 50 }),
239
+ ],
240
+ });
241
+ ```
242
+
243
+ In a UI framework, use the adapter — e.g. `@omnigrid/react`:
244
+
245
+ ```tsx
246
+ <OmniGrid
247
+ columns={columns}
248
+ data={rows}
249
+ getRowId={(row) => row.id}
250
+ plugins={plugins}
251
+ style={{ height: 480 }}
252
+ />
253
+ ```
254
+
255
+ See [@omnigrid/react](../../adapters/react/README.md).
256
+
257
+ ## Exported helpers
258
+
259
+ - `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
260
+ - `resolveColSpan`, `getRowSpans`, `getCellSpanningParams` — column spanning
261
+ (`ColumnDef.colSpan`): normalized per-cell spans and per-row merged layouts.
262
+ - `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
263
+ (mostly used internally; public for advanced integrations/tests).
264
+
265
+ ### Column spanning (`colSpan`)
266
+
267
+ A leaf column may merge horizontally across consecutive visible columns:
268
+
269
+ ```ts
270
+ const columns: ColumnDef<Row>[] = [
271
+ { id: "title", width: 200, colSpan: 2 }, // static: always 2
272
+ { id: "note", width: 160, colSpan: ({ data }) => (data.merged ? 3 : 1) },
273
+ ];
274
+ ```
275
+
276
+ `resolveColSpan` normalizes one cell (floors, clamps to `>= 1`, clips to the
277
+ pin group, falls back to `1` on resolver errors); `getRowSpans` / `Grid.getRowSpans`
278
+ aggregates a whole row — the origin carries the summed pixel width aligned to
279
+ the starting column, covered cells are skipped. `Grid.getViewportData`
280
+ additionally exposes the full leaf groups (`leafColumns` + `columnOffsets`,
281
+ pinned siblings likewise) and expands the shared column window so spans
282
+ crossing the viewport boundary are never clipped. The React adapter resolves
283
+ per-row layouts (memoized per viewport commit) and paints merged widths via
284
+ `translateX` without breaking node recycling.
285
+
286
+ ## Links
287
+
288
+ - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
289
+ - **Demo:** https://omnigrid-demo.vercel.app/
290
+ - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
291
+
292
+ ## License
293
+
294
+ MIT © KRZK Apps
package/dist/grid.d.ts CHANGED
@@ -1,17 +1,18 @@
1
1
  import type { FilterCondition, FilterModel } from "./filtering";
2
- import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
3
2
  import { IconRegistry } from "./icons";
3
+ import type { OverlayOptions, OverlayState } from "./overlays";
4
+ import { DataPipeline } from "./pipeline";
4
5
  import { SlotManager } from "./slots";
5
6
  import { type StateUpdater } from "./store";
6
- import { DataPipeline } from "./pipeline";
7
- import type { AggregationFunc, ColumnLeafDef, DataProcessor, DefaultColumnDef, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHoverEvent, RowHierarchy, RowId, RowSpanLayout, ScrollPosition, SlotMount, SlotName, TransactionResult, TreeRowNode, RowTransaction, ViewportData, ViewportState } from "./types";
8
- import type { OverlayOptions, OverlayState } from "./overlays";
7
+ import type { AggregationFunc, ColumnHeaderExtension, ColumnHeaderExtensionPosition, ColumnLeafDef, DataProcessor, DefaultColumnDef, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHierarchy, RowHoverEvent, RowId, RowSpanLayout, RowTransaction, ScrollPosition, SlotMount, SlotName, TransactionResult, TreeRowNode, ViewportData, ViewportState } from "./types";
8
+ import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
9
9
  export declare class Grid<T> implements GridApi<T> {
10
10
  private readonly store;
11
11
  private readonly events;
12
12
  private readonly virtualizer;
13
13
  private readonly cleanupPlugins;
14
14
  private readonly pluginRegistrations;
15
+ private readonly headerExtensions;
15
16
  private readonly dataProcessors;
16
17
  private rowHierarchy?;
17
18
  private readonly resolveRowId;
@@ -208,7 +209,7 @@ export declare class Grid<T> implements GridApi<T> {
208
209
  registerAggregationFuncs(funcs: Record<string, AggregationFunc<T>>): () => void;
209
210
  /** Configures the group column UI mode and header. @api */
210
211
  setGroupColumnConfig(config: {
211
- mode: 'single' | 'perLevel';
212
+ mode: "single" | "perLevel";
212
213
  header?: string;
213
214
  showChildCount?: boolean;
214
215
  groupRowRenderer?: any;
@@ -332,6 +333,20 @@ export declare class Grid<T> implements GridApi<T> {
332
333
  on<EventName extends keyof GridEvents<T>>(event: EventName, listener: (payload: GridEvents<T>[EventName]) => void): () => void;
333
334
  emit<EventName extends keyof GridEvents<T>>(event: EventName, payload: GridEvents<T>[EventName]): void;
334
335
  registerPlugin(plugin: GridPlugin<T>): () => void;
336
+ /**
337
+ * Registers an element for the adapter to render in leaf column headers.
338
+ * @param extension - Headless header contribution.
339
+ * @returns Cleanup callback that unregisters this contribution.
340
+ * @api
341
+ */
342
+ registerHeaderExtension(extension: ColumnHeaderExtension<T>): () => void;
343
+ /**
344
+ * Returns registered header contributions in priority and registration order.
345
+ * @param position - Optional header region to filter by.
346
+ * @returns The registered contributions for the requested region.
347
+ * @api
348
+ */
349
+ getHeaderExtensions(position?: ColumnHeaderExtensionPosition): ColumnHeaderExtension<T>[];
335
350
  /**
336
351
  * Reconciles the registered plugins with the given list: plugins missing from
337
352
  * the list are unregistered (their cleanup restores default behavior), new
package/dist/grid.js CHANGED
@@ -1,19 +1,20 @@
1
- import { applyDefaultColumnDef, applyWrapText, flattenColumns, getColumnGroups, getCellValue, getRowSpans, resolveColSpan } from "./columns";
1
+ import { applyDefaultColumnDef, applyWrapText, flattenColumns, getCellValue, getColumnGroups, getRowSpans, resolveColSpan, } from "./columns";
2
2
  import { EventBus } from "./events";
3
3
  import { applyFilterModel, applyQuickFilter, isActiveCondition } from "./filtering";
4
- import { PopupManager } from "./ui";
5
- import { evaluateAutoOverlay } from "./overlays";
4
+ import { buildGroupTree, computeAggregations, flattenTree } from "./groupingPipeline";
6
5
  import { IconRegistry } from "./icons";
6
+ import { evaluateAutoOverlay } from "./overlays";
7
+ import { DataPipeline } from "./pipeline";
7
8
  import { SlotManager } from "./slots";
8
9
  import { Store } from "./store";
9
- import { DataPipeline } from "./pipeline";
10
- import { buildGroupTree, computeAggregations, flattenTree } from "./groupingPipeline";
10
+ import { PopupManager } from "./ui";
11
11
  import { Virtualizer } from "./virtualizer";
12
12
  export class Grid {
13
13
  constructor(options) {
14
14
  this.events = new EventBus();
15
15
  this.cleanupPlugins = new Set();
16
16
  this.pluginRegistrations = new Map();
17
+ this.headerExtensions = new Map();
17
18
  this.dataProcessors = new Set();
18
19
  this.icons = new IconRegistry();
19
20
  this.methods = {};
@@ -54,8 +55,8 @@ export class Grid {
54
55
  rowHeight: options.rowHeight ?? 32,
55
56
  groupBy: [],
56
57
  expandedGroups: {},
57
- groupColumnMode: 'single',
58
- groupColumnHeader: 'Group',
58
+ groupColumnMode: "single",
59
+ groupColumnHeader: "Group",
59
60
  showChildCount: true,
60
61
  groupRowRenderer: undefined,
61
62
  rowOverscan: options.rowOverscan ?? 5,
@@ -208,7 +209,8 @@ export class Grid {
208
209
  scrollTo(position) {
209
210
  this.assertActive();
210
211
  const nextPosition = { ...this.scrollPosition, ...position };
211
- if (nextPosition.scrollTop === this.scrollPosition.scrollTop && nextPosition.scrollLeft === this.scrollPosition.scrollLeft)
212
+ if (nextPosition.scrollTop === this.scrollPosition.scrollTop &&
213
+ nextPosition.scrollLeft === this.scrollPosition.scrollLeft)
212
214
  return;
213
215
  this.scrollPosition = nextPosition;
214
216
  this.events.emit("scrollTo", nextPosition);
@@ -335,17 +337,19 @@ export class Grid {
335
337
  };
336
338
  });
337
339
  return {
338
- rows: (grouped.length > 0 ? grouped : processedData).slice(rowRange.start, rowRange.end).map((row, index) => {
340
+ rows: (grouped.length > 0 ? grouped : processedData)
341
+ .slice(rowRange.start, rowRange.end)
342
+ .map((row, index) => {
339
343
  const rowIndex = rowRange.start + index;
340
344
  if (grouped.length > 0) {
341
345
  const node = row;
342
- if (node.type === 'group') {
346
+ if (node.type === "group") {
343
347
  return {
344
348
  id: node.id,
345
349
  data: undefined,
346
350
  index: rowIndex,
347
351
  level: node.level,
348
- type: 'group',
352
+ type: "group",
349
353
  group: node,
350
354
  offset: rowIndex * state.rowHeight,
351
355
  height: state.rowHeight,
@@ -356,7 +360,7 @@ export class Grid {
356
360
  data: node.data,
357
361
  index: rowIndex,
358
362
  level: node.level,
359
- type: 'leaf',
363
+ type: "leaf",
360
364
  group: node.parent,
361
365
  offset: rowIndex * state.rowHeight,
362
366
  height: state.rowHeight,
@@ -368,7 +372,7 @@ export class Grid {
368
372
  data,
369
373
  index: rowIndex,
370
374
  level: 0,
371
- type: 'leaf',
375
+ type: "leaf",
372
376
  group: undefined,
373
377
  offset: rowOffsets ? rowOffsets[index] : rowIndex * state.rowHeight,
374
378
  height: rowHeights ? rowHeights[index] : state.rowHeight,
@@ -570,7 +574,7 @@ export class Grid {
570
574
  const state = this.getState();
571
575
  const next = { ...state.expandedGroups };
572
576
  this.getGroupedRows()
573
- .filter((row) => row.type === 'group')
577
+ .filter((row) => row.type === "group")
574
578
  .forEach((group) => {
575
579
  next[group.id] = true;
576
580
  });
@@ -584,7 +588,7 @@ export class Grid {
584
588
  const state = this.getState();
585
589
  const next = { ...state.expandedGroups };
586
590
  this.getGroupedRows()
587
- .filter((row) => row.type === 'group')
591
+ .filter((row) => row.type === "group")
588
592
  .forEach((group) => {
589
593
  next[group.id] = false;
590
594
  });
@@ -962,7 +966,7 @@ export class Grid {
962
966
  // ---------- cell flash on update ----------
963
967
  if (this.cellFlash !== false && updated.length > 0) {
964
968
  const state = this.store.getState();
965
- const leafColumns = flattenColumns(state.columns).filter((column) => column.field !== undefined);
969
+ const leafColumns = flattenColumns(state.columns).filter((column) => column.field !== undefined && column.cellFlash !== false);
966
970
  // Lazy cleanup: drop entries older than the flash duration so the map
967
971
  // doesn't grow unboundedly and cells can re-flash later.
968
972
  const cutoff = Date.now() - this.cellFlash.durationMs;
@@ -1095,7 +1099,9 @@ export class Grid {
1095
1099
  this.groupedRowsCache = null;
1096
1100
  this.groupedRowsRevision = -1;
1097
1101
  this.revision += 1;
1098
- this.store.setState({ columns: applyWrapText(applyDefaultColumnDef(columns, this.defaultColumnDef), this.wrapTextAll) });
1102
+ this.store.setState({
1103
+ columns: applyWrapText(applyDefaultColumnDef(columns, this.defaultColumnDef), this.wrapTextAll),
1104
+ });
1099
1105
  this.recomputeOverlay();
1100
1106
  }
1101
1107
  registerDataProcessor(processor) {
@@ -1151,6 +1157,36 @@ export class Grid {
1151
1157
  this.pluginRegistrations.set(plugin, unregister);
1152
1158
  return unregister;
1153
1159
  }
1160
+ /**
1161
+ * Registers an element for the adapter to render in leaf column headers.
1162
+ * @param extension - Headless header contribution.
1163
+ * @returns Cleanup callback that unregisters this contribution.
1164
+ * @api
1165
+ */
1166
+ registerHeaderExtension(extension) {
1167
+ this.assertActive();
1168
+ const registered = { ...extension };
1169
+ this.headerExtensions.set(extension.id, registered);
1170
+ this.store.setState({});
1171
+ return () => {
1172
+ if (this.headerExtensions.get(extension.id) !== registered)
1173
+ return;
1174
+ this.headerExtensions.delete(extension.id);
1175
+ if (!this.destroyed)
1176
+ this.store.setState({});
1177
+ };
1178
+ }
1179
+ /**
1180
+ * Returns registered header contributions in priority and registration order.
1181
+ * @param position - Optional header region to filter by.
1182
+ * @returns The registered contributions for the requested region.
1183
+ * @api
1184
+ */
1185
+ getHeaderExtensions(position) {
1186
+ return Array.from(this.headerExtensions.values())
1187
+ .filter((extension) => position === undefined || (extension.position ?? "end") === position)
1188
+ .sort((left, right) => (left.priority ?? 0) - (right.priority ?? 0));
1189
+ }
1154
1190
  /**
1155
1191
  * Reconciles the registered plugins with the given list: plugins missing from
1156
1192
  * the list are unregistered (their cleanup restores default behavior), new
@@ -1261,6 +1297,7 @@ export class Grid {
1261
1297
  this.cleanupPlugins.forEach((cleanup) => cleanup());
1262
1298
  this.cleanupPlugins.clear();
1263
1299
  this.dataProcessors.clear();
1300
+ this.headerExtensions.clear();
1264
1301
  this.pipeline.clear();
1265
1302
  this.rowHierarchy = undefined;
1266
1303
  for (const key of Object.keys(this.methods)) {
package/dist/index.d.ts CHANGED
@@ -10,10 +10,10 @@ export { Store } from "./store";
10
10
  export type { StateUpdater } from "./store";
11
11
  export { DataPipeline, PIPELINE_STAGE_ORDER } from "./pipeline";
12
12
  export type { PipelineProcessor, PipelineStage } from "./pipeline";
13
- export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
13
+ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter, } from "./filtering";
14
14
  export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering";
15
15
  export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui";
16
16
  export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
17
- export type { BlockConfig, CellAlign, AggregationFunc, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, DefaultColumnDef, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DataRowNode, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GroupRowNode, GroupRowRenderParams, GroupRowRenderer, CoreGridApi, CoreGridState, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PluginApiExtensions, PluginStateExtensions, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowHierarchy, RowHierarchyScope, RowGroupContext, RowGroupContextChild, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, TreeRowNode, ViewportData, ViewportState, VirtualItem, } from "./types";
18
- export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
17
+ export type { BlockConfig, CellAlign, AggregationFunc, ColumnHeaderExtension, ColumnHeaderExtensionPosition, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, DefaultColumnDef, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DataRowNode, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GroupRowNode, GroupRowRenderParams, GroupRowRenderer, CoreGridApi, CoreGridState, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PluginApiExtensions, PluginStateExtensions, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowHierarchy, RowHierarchyScope, RowGroupContext, RowGroupContextChild, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, TreeRowNode, ViewportData, ViewportState, VirtualItem, } from "./types";
18
+ export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, } from "./columns";
19
19
  export { Virtualizer, RowHeightRegistry } from "./virtualizer";
package/dist/index.js CHANGED
@@ -7,6 +7,6 @@ export { Grid as GridCore } from "./grid";
7
7
  export { SlotManager } from "./slots";
8
8
  export { Store } from "./store";
9
9
  export { DataPipeline, PIPELINE_STAGE_ORDER } from "./pipeline";
10
- export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter } from "./filtering";
11
- export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans } from "./columns";
10
+ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter, } from "./filtering";
11
+ export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, } from "./columns";
12
12
  export { Virtualizer, RowHeightRegistry } from "./virtualizer";
package/dist/types.d.ts CHANGED
@@ -1,10 +1,10 @@
1
+ import type { FilterCondition, FilterModel } from "./filtering";
2
+ import type { IconRegistry } from "./icons";
1
3
  import type { OverlayOptions, OverlayState, OverlayType } from "./overlays";
4
+ import type { DataPipeline } from "./pipeline";
2
5
  import type { SlotManager } from "./slots";
3
- import type { IconRegistry } from "./icons";
4
- import type { FilterCondition, FilterModel } from "./filtering";
5
- import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
6
6
  import type { StateUpdater } from "./store";
7
- import type { DataPipeline } from "./pipeline";
7
+ import type { UIPopupAnchor, UIPopupDescriptor } from "./ui";
8
8
  export type { PipelineProcessor, PipelineStage } from "./pipeline";
9
9
  export type RowId = string | number;
10
10
  export type SortDirection = "asc" | "desc";
@@ -84,7 +84,7 @@ export type AggregationFunc<T = unknown> = (values: unknown[]) => unknown;
84
84
  * @api
85
85
  */
86
86
  export interface GroupRowNode<T> {
87
- type: 'group';
87
+ type: "group";
88
88
  /** Stable path identifying the group, e.g. "Region:Europe/Country:France". */
89
89
  id: string;
90
90
  /** Column field this group levels on. */
@@ -137,7 +137,7 @@ export type GroupRowRenderer<T> = (params: GroupRowRenderParams<T>) => unknown;
137
137
  * @api
138
138
  */
139
139
  export interface DataRowNode<T> {
140
- type: 'leaf';
140
+ type: "leaf";
141
141
  /** Stable row identifier (from `getRowId`). */
142
142
  id: RowId;
143
143
  /** Raw row data object. */
@@ -338,6 +338,27 @@ export interface HeaderRenderParams<T> {
338
338
  /** Zero-based index of the leaf column in the visible layout. */
339
339
  index?: number;
340
340
  }
341
+ /** Position of a plugin-contributed element in a leaf column header. @api */
342
+ export type ColumnHeaderExtensionPosition = "start" | "end" | "overlay";
343
+ /**
344
+ * A headless element contributed to every leaf column header by a plugin.
345
+ *
346
+ * The active adapter renders the returned content alongside the built-in
347
+ * header label and controls. Extensions are ordered by ascending priority;
348
+ * equal priorities retain registration order.
349
+ *
350
+ * @api
351
+ */
352
+ export interface ColumnHeaderExtension<T> {
353
+ /** Unique identifier within the grid instance. */
354
+ id: string;
355
+ /** Header region for the contributed content. Defaults to `"end"`. */
356
+ position?: ColumnHeaderExtensionPosition;
357
+ /** Lower values render first. Defaults to `0`. */
358
+ priority?: number;
359
+ /** Returns headless content accepted by the active adapter. */
360
+ render: (params: HeaderRenderParams<T>) => unknown;
361
+ }
341
362
  /**
342
363
  * Inline styles applied to a column or group header.
343
364
  *
@@ -395,7 +416,11 @@ interface BaseColumnDef<T> {
395
416
  pinned?: "left" | "right";
396
417
  /** Whether this column may be resized by the resize plugin. */
397
418
  resizable?: boolean;
398
- /** Custom renderer for this column's header. */
419
+ /**
420
+ * Custom renderer for the primary content of this column's header.
421
+ * Adapter controls and plugin extensions are rendered alongside it.
422
+ * @api
423
+ */
399
424
  headerRenderer?: (column: ColumnDef<T>) => unknown;
400
425
  /**
401
426
  * Whether this column participates in the global quick filter. Defaults to true.
@@ -404,6 +429,8 @@ interface BaseColumnDef<T> {
404
429
  * @api
405
430
  */
406
431
  searchable?: boolean;
432
+ /** Horizontal alignment of header content. Uses the same values as `align`. @api */
433
+ headerAlign?: CellAlign;
407
434
  }
408
435
  export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
409
436
  /** Row property used as the cell value source. */
@@ -470,6 +497,8 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
470
497
  valueFormatter?: (value: unknown) => string;
471
498
  /** Replaces the default cell content with custom content. */
472
499
  cellRenderer?: (params: CellRenderParams<T>) => unknown;
500
+ /** Set to `false` to prevent this column from flashing when grid-level `cellFlash` is enabled. @default true */
501
+ cellFlash?: boolean;
473
502
  /** Static inline styles applied to cells in this column. */
474
503
  cellStyle?: RowStyle;
475
504
  /** Computes inline styles for each rendered cell. */
@@ -610,9 +639,10 @@ export interface GridOptions<T> {
610
639
  /**
611
640
  * Enables automatic cell flashing when data is mutated via
612
641
  * `grid.applyTransaction()`. Cells whose values changed are highlighted
613
- * with a CSS transition that fades out automatically. Pass `true` for the
614
- * default duration (1000ms), or a number for a custom duration in
615
- * milliseconds. `false` / `0` / `undefined` disables the feature.
642
+ * with a CSS transition that fades out automatically, except in columns
643
+ * whose `cellFlash` option is `false`. Pass `true` for the default duration
644
+ * (1000ms), or a number for a custom duration in milliseconds.
645
+ * `false` / `0` / `undefined` disables the feature.
616
646
  * @default false
617
647
  * @api
618
648
  */
@@ -698,7 +728,7 @@ export interface ViewportData<T> {
698
728
  /** Nesting depth (0 = outermost group, equal to groupBy length for leaves). */
699
729
  level: number;
700
730
  /** `'group'` for a group row, `'leaf'` for a data row. */
701
- type: 'group' | 'leaf';
731
+ type: "group" | "leaf";
702
732
  /** The group node when `type === 'group'`, otherwise `undefined`. */
703
733
  group: GroupRowNode<T> | undefined;
704
734
  /** Absolute vertical offset (px) of the row top. */
@@ -1321,6 +1351,19 @@ export interface CoreGridApi<T> {
1321
1351
  /** Emits a typed grid event for plugin-to-plugin and adapter notifications. */
1322
1352
  emit<EventName extends keyof GridEvents<T>>(event: EventName, payload: GridEvents<T>[EventName]): void;
1323
1353
  registerPlugin(plugin: GridPlugin<T>): () => void;
1354
+ /**
1355
+ * Registers an element that an adapter renders in each leaf column header.
1356
+ * @param extension - Headless header contribution.
1357
+ * @returns Cleanup callback that unregisters this contribution.
1358
+ * @api
1359
+ */
1360
+ registerHeaderExtension(extension: ColumnHeaderExtension<T>): () => void;
1361
+ /**
1362
+ * Returns registered header contributions in render order.
1363
+ * @param position - Optional header region to filter by.
1364
+ * @api
1365
+ */
1366
+ getHeaderExtensions(position?: ColumnHeaderExtensionPosition): ColumnHeaderExtension<T>[];
1324
1367
  registerDataProcessor(processor: DataProcessor<T>): () => void;
1325
1368
  /**
1326
1369
  * Replaces the column definitions. Pass a second argument to update the shared leaf-column defaults.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",