@omnigrid/core 0.1.29 → 0.1.31

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,294 +1,300 @@
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
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
+ - **Column drag events** — adapters emit `columnDragStart`, `columnDrop`, and `columnDragEnd` for movable leaf and group headers.
16
+ - **DOM Pool mapping** — the core decides _which_ rows are visible; the adapter performs DOM ops via injected `DomPoolBindings`.
17
+ - **Slot Manager / `GridApi.slots`** — headless widgets mounted by plugins into `top | bottom | left | right`.
18
+ - **Column header extensions** — plugins register independent header elements; adapters render them beside the shared label and controls.
19
+ - **Icon Registry** — framework-agnostic declarative SVG icons for plugin UI (`api.icons.get(name)`).
20
+
21
+ **Scroll is ephemeral, not state.** `scrollTop`/`scrollLeft` are kept out of the Store:
22
+ scroll-only `setViewport({ scrollTop, scrollLeft })` calls never notify subscribers, so adapters do
23
+ not re-render on scroll frames. Read them via `getScrollPosition()`; use `scrollTo()` to request an
24
+ adapter-native scroll adjustment without moving scroll coordinates into the Store.
25
+
26
+ ## Key contracts
27
+
28
+ ### `GridOptions<T>`
29
+
30
+ ```ts
31
+ interface GridOptions<T> {
32
+ data?: T[] | null; // row data; null/omitted means initial loading
33
+ columns: ColumnDef<T>[]; // required
34
+ getRowId?: (row: T, index: number) => RowId; // default: index-based
35
+ rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
36
+ rowOverscan?: number; // extra rows above/below viewport; default 5
37
+ columnOverscan?: number; // extra columns beyond horizontal window; default 2
38
+ cellFlash?: boolean | number; // highlight changed cells after applyTransaction
39
+ suppressRowHoverHighlight?: boolean;
40
+ rowStyle?: RowStyle;
41
+ getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
42
+ rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
43
+ getRowClass?: (params: RowRenderParams<T>) => string | undefined;
44
+ rowClassRules?: RowClassRules<T>; // class name → predicate
45
+ plugins?: GridPlugin<T>[]; // plugin instances registered at construction
46
+ loading?: boolean; // active fetch; shows loading even with prior rows
47
+ overlayComponents?: Record<string, OverlayComponent<T>>;
48
+ }
49
+ ```
50
+
51
+ Row callbacks receive `params.rowType` (`"leaf"` or `"group"`). Group rows are synthetic and have no `data`; checking `rowType` narrows the callback parameters.
52
+
53
+ ### `ColumnDef<T>`
54
+
55
+ `ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
56
+
57
+ ```ts
58
+ interface ColumnLeafDef<T> {
59
+ id: string; // unique column id (also stable slot key)
60
+ header: string;
61
+ field?: keyof T | string; // value accessor (default cell value source)
62
+ valueGetter?: (row: T) => unknown; // overrides field
63
+ valueFormatter?: (value: unknown) => string;
64
+ width?: number; // fixed px width
65
+ flex?: number; // flex weight; expands to fill remaining space
66
+ minWidth?: number;
67
+ maxWidth?: number;
68
+ hidden?: boolean;
69
+ movable?: boolean; // opt in to leaf drag-and-drop with a reorder plugin
70
+ pinned?: "left" | "right"; // fixed column in horizontal viewport
71
+ sortable?: boolean; // read by SortingPlugin
72
+ sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
73
+ sortIndex?: number; // runtime 1-based priority when multi-sorted
74
+ align?: "left" | "center" | "right";
75
+ cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
76
+ cellFlash?: boolean; // set false to opt out when GridOptions.cellFlash is enabled
77
+ cellStyle?: RowStyle;
78
+ getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
79
+ cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
80
+ getCellClass?: (params: CellRenderParams<T>) => string | undefined;
81
+ cellClassRules?: CellClassRules<T>;
82
+ getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
83
+ getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
84
+ columnClassRules?: ColumnClassRules<T>;
85
+ headerStyle?: HeaderStyle;
86
+ getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
87
+ headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
88
+ getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
89
+ headerClassRules?: HeaderClassRules<T>;
90
+ headerRenderer?: (column: ColumnDef<T>) => unknown; // primary header content; adapter controls remain separate
91
+ stopRowClick?: boolean;
92
+ stopHeaderClick?: boolean;
93
+ }
94
+
95
+ interface ColumnGroupDef<T> {
96
+ id: string;
97
+ header: string;
98
+ children: ColumnDef<T>[]; // nested leaves / groups
99
+ movable?: boolean; // opt in to moving the entire group with a reorder plugin
100
+ pinned?: "left" | "right";
101
+ collapsible?: boolean;
102
+ defaultExpanded?: boolean;
103
+ headerStyle?: HeaderStyle;
104
+ getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
105
+ headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
106
+ getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
107
+ headerClassRules?: HeaderGroupClassRules<T>;
108
+ headerRenderer?: (column: ColumnDef<T>) => unknown;
109
+ }
110
+ ```
111
+
112
+ `movable` is available on both leaf columns and groups. Dragging a group moves its complete
113
+ subtree; dropping after the last leaf in the final group places the dragged column after the group.
114
+
115
+ When grid-level `cellFlash` is enabled, set `cellFlash: false` on an individual leaf column to opt it out.
116
+
117
+ ### `GridApi<T>`
118
+
119
+ `Grid<T>` implements this interface — the single public surface for adapters and plugins.
120
+ UI code must never touch core internals directly.
121
+
122
+ ```ts
123
+ interface GridApi<T> {
124
+ getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
125
+ getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
126
+ scrollTo(position: Partial<ScrollPosition>): void; // request a native scroll adjustment from the adapter
127
+ getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
128
+ getProcessedData(): T[]; // after all registered data processors
129
+ getRowId(row: T, index: number): RowId;
130
+ setData(data: T[] | null | undefined): void;
131
+ setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
132
+ refresh(): void; // repaint hints (rowClassRules), bumps revision
133
+ subscribe(listener: () => void): () => void;
134
+ on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
135
+ registerPlugin(plugin: GridPlugin<T>): () => void;
136
+ registerHeaderExtension(extension: ColumnHeaderExtension<T>): () => void;
137
+ getHeaderExtensions(position?: ColumnHeaderExtensionPosition): ColumnHeaderExtension<T>[];
138
+ registerDataProcessor(processor: DataProcessor<T>): () => void;
139
+ setColumns(columns: ColumnDef<T>[]): void;
140
+ headerClick(columnId: string, multiSort?: boolean): void;
141
+ rowClick(row: RowClickEvent<T>): void;
142
+ rowHover(row: RowHoverEvent<T>): void;
143
+ readonly slots: SlotManager<T>; // mount headless widgets
144
+ readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
145
+ getSlotMounts(slot: SlotName): SlotMount<T>[];
146
+ showOverlay(options: OverlayOptions): void;
147
+ hideOverlay(): void;
148
+ getOverlayState(): OverlayState;
149
+ setLoading(isLoading: boolean, error?: unknown): void;
150
+ getRevision(): number; // monotonic counter for structural changes
151
+ destroy(): void;
152
+ isDestroyed(): boolean;
153
+ }
154
+ ```
155
+
156
+ `registerHeaderExtension` lets plugins add header content without wrapping or replacing a
157
+ column's `headerRenderer`. Extensions render for each visible leaf column and can target the
158
+ `"start"`, `"end"`, or `"overlay"` region. Lower `priority` values render first; equal priorities
159
+ retain registration order. The returned cleanup callback removes the extension.
160
+
161
+ ### Overlays
162
+
163
+ Overlays are managed in core state, so state transitions notify subscribers only when the
164
+ overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
165
+ loading; an explicit empty array shows the no-rows state. Empty processed results with source
166
+ rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
167
+ through `setLoading(false, error)`; a successful `setData` clears the error.
168
+
169
+ ```ts
170
+ grid.showOverlay({
171
+ type: "error",
172
+ // Errors default to "full"; other overlay types default to "bodyOnly".
173
+ // Set scope explicitly to choose a different placement.
174
+ message: "Could not load records",
175
+ });
176
+ grid.hideOverlay(); // restores automatic loading / empty-state evaluation
177
+ const overlay = grid.getOverlayState();
178
+ ```
179
+
180
+ Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
181
+ is present. Horizontal scrolling remains enabled by default and can be locked with
182
+ `blockScroll: true`.
183
+
184
+ `overlayComponents` accepts framework-specific components through the adapter or core render
185
+ callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
186
+
187
+ `GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
188
+ Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
189
+
190
+ ### Plugin contract — `GridPlugin<T>`
191
+
192
+ ```ts
193
+ interface GridPlugin<T> {
194
+ name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
195
+ register(api: GridApi<T>): void | (() => void); // returns cleanup
196
+ getRowClass?(params: RowRenderParams<T>): string | undefined;
197
+ getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
198
+ }
199
+ ```
200
+
201
+ A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
202
+ and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
203
+ Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
204
+ [`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
205
+
206
+ ## Quick start
207
+
208
+ Headless core only (no UI):
209
+
210
+ ```ts
211
+ import { Grid } from "@omnigrid/core";
212
+ import type { ColumnDef } from "@omnigrid/core";
213
+
214
+ interface Row {
215
+ id: string;
216
+ name: string;
217
+ }
218
+
219
+ const columns: ColumnDef<Row>[] = [{ id: "name", field: "name", header: "Name", width: 220 }];
220
+
221
+ const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
222
+
223
+ grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
224
+ const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
225
+ grid.on("rowClick", (e) => console.log(e.index));
226
+ grid.destroy();
227
+ ```
228
+
229
+ With base plugins:
230
+
231
+ ```ts
232
+ import { Grid } from "@omnigrid/core";
233
+ import { PaginationPlugin } from "@omnigrid/pagination-plugin";
234
+ import { SelectionPlugin } from "@omnigrid/selection-plugin";
235
+ import { SortingPlugin } from "@omnigrid/sorting-plugin";
236
+
237
+ const grid = new Grid<Row>({
238
+ data,
239
+ columns,
240
+ getRowId: (row) => row.id,
241
+ plugins: [
242
+ new SortingPlugin<Row>(),
243
+ new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
244
+ new PaginationPlugin<Row>({ pageSize: 50 }),
245
+ ],
246
+ });
247
+ ```
248
+
249
+ In a UI framework, use the adapter — e.g. `@omnigrid/react`:
250
+
251
+ ```tsx
252
+ <OmniGrid
253
+ columns={columns}
254
+ data={rows}
255
+ getRowId={(row) => row.id}
256
+ plugins={plugins}
257
+ style={{ height: 480 }}
258
+ />
259
+ ```
260
+
261
+ See [@omnigrid/react](../../adapters/react/README.md).
262
+
263
+ ## Exported helpers
264
+
265
+ - `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
266
+ - `resolveColSpan`, `getRowSpans`, `getCellSpanningParams` — column spanning
267
+ (`ColumnDef.colSpan`): normalized per-cell spans and per-row merged layouts.
268
+ - `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
269
+ (mostly used internally; public for advanced integrations/tests).
270
+
271
+ ### Column spanning (`colSpan`)
272
+
273
+ A leaf column may merge horizontally across consecutive visible columns:
274
+
275
+ ```ts
276
+ const columns: ColumnDef<Row>[] = [
277
+ { id: "title", width: 200, colSpan: 2 }, // static: always 2
278
+ { id: "note", width: 160, colSpan: ({ data }) => (data.merged ? 3 : 1) },
279
+ ];
280
+ ```
281
+
282
+ `resolveColSpan` normalizes one cell (floors, clamps to `>= 1`, clips to the
283
+ pin group, falls back to `1` on resolver errors); `getRowSpans` / `Grid.getRowSpans`
284
+ aggregates a whole row — the origin carries the summed pixel width aligned to
285
+ the starting column, covered cells are skipped. `Grid.getViewportData`
286
+ additionally exposes the full leaf groups (`leafColumns` + `columnOffsets`,
287
+ pinned siblings likewise) and expands the shared column window so spans
288
+ crossing the viewport boundary are never clipped. The React adapter resolves
289
+ per-row layouts (memoized per viewport commit) and paints merged widths via
290
+ `translateX` without breaking node recycling.
291
+
292
+ ## Links
293
+
294
+ - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
295
+ - **Demo:** https://omnigrid-demo.vercel.app/
296
+ - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
297
+
298
+ ## License
299
+
300
+ MIT © KRZK Apps
package/dist/index.d.ts CHANGED
@@ -14,6 +14,6 @@ export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelAct
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, 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";
17
+ export type { BlockConfig, CellAlign, AggregationFunc, ColumnHeaderExtension, ColumnHeaderExtensionPosition, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnDropPosition, 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, ResolvedAggregationFunc, 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
18
  export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, } from "./columns";
19
19
  export { Virtualizer, RowHeightRegistry } from "./virtualizer";
package/dist/types.d.ts CHANGED
@@ -72,6 +72,8 @@ export interface RowNode<T> {
72
72
  }
73
73
  /** Aggregation function applied to column values within a group. */
74
74
  export type AggregationFunc<T = unknown> = (values: unknown[]) => unknown;
75
+ /** Resolved aggregation callback registered with the grid grouping engine. */
76
+ export type ResolvedAggregationFunc<T = unknown> = AggregationFunc<T>;
75
77
  /**
76
78
  * A group (aggregated) row produced by the Row Grouping engine.
77
79
  *
@@ -414,8 +416,12 @@ interface BaseColumnDef<T> {
414
416
  header: string;
415
417
  /** Pins the column to a horizontal edge of the grid. */
416
418
  pinned?: "left" | "right";
419
+ /** Keeps this column or group at the start of the column order. @api */
420
+ lockPosition?: "start";
417
421
  /** Whether this column may be resized by the resize plugin. */
418
422
  resizable?: boolean;
423
+ /** Whether this column can be moved by a column drag-and-drop plugin. @default false @api */
424
+ movable?: boolean;
419
425
  /**
420
426
  * Custom renderer for the primary content of this column's header.
421
427
  * Adapter controls and plugin extensions are rendered alongside it.
@@ -459,6 +465,8 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
459
465
  * @api
460
466
  */
461
467
  maxLines?: number;
468
+ /** Aggregation function used when this column is inside a group. */
469
+ aggFunc?: AggregationFunc<T> | string;
462
470
  /**
463
471
  * Controls whether the cell keeps the theme's internal padding or removes it
464
472
  * so custom content can fill the cell.
@@ -546,6 +554,12 @@ export interface ColumnGroupDef<T> extends BaseColumnDef<T> {
546
554
  }
547
555
  /** Leaf or grouped column definition accepted by the grid. */
548
556
  export type ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>;
557
+ /**
558
+ * Position at which a dragged column is dropped relative to its target.
559
+ *
560
+ * @api
561
+ */
562
+ export type ColumnDropPosition = "before" | "after";
549
563
  /**
550
564
  * Properties inherited by leaf columns unless overridden by the column.
551
565
  *
@@ -660,6 +674,14 @@ export interface GridOptions<T> {
660
674
  * whose `searchable` property is not `false`.
661
675
  */
662
676
  quickFilter?: string;
677
+ /**
678
+ * Animates visible rows when filtering, sorting, or other data changes
679
+ * reposition them. Row movement uses a separate transform component and
680
+ * does not change the grid's scroll position.
681
+ * @default false
682
+ * @api
683
+ */
684
+ animateRows?: boolean;
663
685
  /**
664
686
  * License key for Pro plugins. When provided, Pro plugins verify the
665
687
  * cryptographic signature and activate full functionality. When missing
@@ -899,6 +921,20 @@ export interface GridEvents<T> {
899
921
  columnId: string;
900
922
  multiSort: boolean;
901
923
  };
924
+ /** Fired when a movable column header starts being dragged. @api */
925
+ columnDragStart: {
926
+ columnId: string;
927
+ };
928
+ /** Fired when a movable column header drag ends. @api */
929
+ columnDragEnd: {
930
+ columnId: string;
931
+ };
932
+ /** Fired when a movable column is dropped relative to another leaf header. @api */
933
+ columnDrop: {
934
+ sourceColumnId: string;
935
+ targetColumnId: string;
936
+ position: ColumnDropPosition;
937
+ };
902
938
  sortingChanged: Array<{
903
939
  columnId: string;
904
940
  direction: SortDirection;
@@ -1192,6 +1228,8 @@ export interface SlotMount<T> {
1192
1228
  * @api
1193
1229
  */
1194
1230
  export interface PluginApiExtensions<T> {
1231
+ /** Registers column id -> aggregation function mappings. */
1232
+ registerAggregationFuncs: (funcs: Record<string, ResolvedAggregationFunc<T>>) => () => void;
1195
1233
  }
1196
1234
  /**
1197
1235
  * Base grid API surface provided by the core engine.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.29",
3
+ "version": "0.1.31",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",