@omnigrid/core 0.1.38 → 0.1.40

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.
Files changed (4) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +310 -310
  3. package/dist/types.d.ts +3 -3
  4. package/package.json +45 -44
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 KRZK Apps
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 KRZK Apps
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,310 +1,310 @@
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>[]; // inferred from the first row when omitted
34
- autoColumnHeaderMode?: "as-is" | "title-case"; // default: "as-is"
35
- getColumnHeader?: (field: string) => string; // custom formatter; takes precedence over autoColumnHeaderMode
36
- getRowId?: (row: T, index: number) => RowId; // default: index-based
37
- rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
38
- rowOverscan?: number; // extra rows above/below viewport; default 5
39
- columnOverscan?: number; // extra columns beyond horizontal window; default 2
40
- cellFlash?: boolean | number; // highlight changed cells after applyTransaction
41
- suppressRowHoverHighlight?: boolean;
42
- rowStyle?: RowStyle;
43
- getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
44
- rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
45
- getRowClass?: (params: RowRenderParams<T>) => string | undefined;
46
- rowClassRules?: RowClassRules<T>; // class name → predicate
47
- plugins?: GridPlugin<T>[]; // plugin instances registered at construction
48
- loading?: boolean; // active fetch; shows loading even with prior rows
49
- overlayComponents?: Record<string, OverlayComponent<T>>;
50
- }
51
- ```
52
-
53
- When `columns` is omitted, the core infers leaf columns from the first row.
54
- If the initial dataset is empty or pending, it waits for the first non-empty
55
- `setData` or `appendData`. The inferred schema stays fixed afterward; call
56
- `setColumns` when the schema changes. An explicit `columns: []` disables
57
- inference. Headers default to the field key; set `autoColumnHeaderMode` to
58
- `"title-case"` to split camel-case keys into capitalized words, or provide
59
- `getColumnHeader` for a custom formatter.
60
-
61
- Row callbacks receive `params.rowType` (`"leaf"` or `"group"`). Group rows are synthetic and have no `data`; checking `rowType` narrows the callback parameters.
62
-
63
- ### `ColumnDef<T>`
64
-
65
- `ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
66
-
67
- ```ts
68
- interface ColumnLeafDef<T> {
69
- id: string; // unique column id (also stable slot key)
70
- header: string;
71
- field?: keyof T | string; // value accessor (default cell value source)
72
- valueGetter?: (row: T) => unknown; // overrides field
73
- valueFormatter?: (value: unknown) => string;
74
- width?: number; // fixed px width
75
- flex?: number; // flex weight; expands to fill remaining space
76
- minWidth?: number;
77
- maxWidth?: number;
78
- hidden?: boolean;
79
- movable?: boolean; // opt in to leaf drag-and-drop with a reorder plugin
80
- pinned?: "left" | "right"; // fixed column in horizontal viewport
81
- sortable?: boolean; // read by SortingPlugin
82
- sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
83
- sortIndex?: number; // runtime 1-based priority when multi-sorted
84
- align?: "left" | "center" | "right";
85
- cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
86
- cellFlash?: boolean; // set false to opt out when GridOptions.cellFlash is enabled
87
- cellStyle?: RowStyle;
88
- getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
89
- cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
90
- getCellClass?: (params: CellRenderParams<T>) => string | undefined;
91
- cellClassRules?: CellClassRules<T>;
92
- getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
93
- getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
94
- columnClassRules?: ColumnClassRules<T>;
95
- headerStyle?: HeaderStyle;
96
- getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
97
- headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
98
- getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
99
- headerClassRules?: HeaderClassRules<T>;
100
- headerRenderer?: (column: ColumnDef<T>) => unknown; // primary header content; adapter controls remain separate
101
- stopRowClick?: boolean;
102
- stopHeaderClick?: boolean;
103
- }
104
-
105
- interface ColumnGroupDef<T> {
106
- id: string;
107
- header: string;
108
- children: ColumnDef<T>[]; // nested leaves / groups
109
- movable?: boolean; // opt in to moving the entire group with a reorder plugin
110
- pinned?: "left" | "right";
111
- collapsible?: boolean;
112
- defaultExpanded?: boolean;
113
- headerStyle?: HeaderStyle;
114
- getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
115
- headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
116
- getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
117
- headerClassRules?: HeaderGroupClassRules<T>;
118
- headerRenderer?: (column: ColumnDef<T>) => unknown;
119
- }
120
- ```
121
-
122
- `movable` is available on both leaf columns and groups. Dragging a group moves its complete
123
- subtree; dropping after the last leaf in the final group places the dragged column after the group.
124
-
125
- When grid-level `cellFlash` is enabled, set `cellFlash: false` on an individual leaf column to opt it out.
126
-
127
- ### `GridApi<T>`
128
-
129
- `Grid<T>` implements this interface — the single public surface for adapters and plugins.
130
- UI code must never touch core internals directly.
131
-
132
- ```ts
133
- interface GridApi<T> {
134
- getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
135
- getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
136
- scrollTo(position: Partial<ScrollPosition>): void; // request a native scroll adjustment from the adapter
137
- getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
138
- getProcessedData(): T[]; // after all registered data processors
139
- getRowId(row: T, index: number): RowId;
140
- setData(data: T[] | null | undefined): void;
141
- setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
142
- refresh(): void; // repaint hints (rowClassRules), bumps revision
143
- subscribe(listener: () => void): () => void;
144
- on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
145
- registerPlugin(plugin: GridPlugin<T>): () => void;
146
- registerHeaderExtension(extension: ColumnHeaderExtension<T>): () => void;
147
- getHeaderExtensions(position?: ColumnHeaderExtensionPosition): ColumnHeaderExtension<T>[];
148
- registerDataProcessor(processor: DataProcessor<T>): () => void;
149
- setColumns(columns: ColumnDef<T>[]): void;
150
- headerClick(columnId: string, multiSort?: boolean): void;
151
- rowClick(row: RowClickEvent<T>): void;
152
- rowHover(row: RowHoverEvent<T>): void;
153
- readonly slots: SlotManager<T>; // mount headless widgets
154
- readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
155
- getSlotMounts(slot: SlotName): SlotMount<T>[];
156
- showOverlay(options: OverlayOptions): void;
157
- hideOverlay(): void;
158
- getOverlayState(): OverlayState;
159
- setLoading(isLoading: boolean, error?: unknown): void;
160
- getRevision(): number; // monotonic counter for structural changes
161
- destroy(): void;
162
- isDestroyed(): boolean;
163
- }
164
- ```
165
-
166
- `registerHeaderExtension` lets plugins add header content without wrapping or replacing a
167
- column's `headerRenderer`. Extensions render for each visible leaf column and can target the
168
- `"start"`, `"end"`, or `"overlay"` region. Lower `priority` values render first; equal priorities
169
- retain registration order. The returned cleanup callback removes the extension.
170
-
171
- ### Overlays
172
-
173
- Overlays are managed in core state, so state transitions notify subscribers only when the
174
- overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
175
- loading; an explicit empty array shows the no-rows state. Empty processed results with source
176
- rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
177
- through `setLoading(false, error)`; a successful `setData` clears the error.
178
-
179
- ```ts
180
- grid.showOverlay({
181
- type: "error",
182
- // Errors default to "full"; other overlay types default to "bodyOnly".
183
- // Set scope explicitly to choose a different placement.
184
- message: "Could not load records",
185
- });
186
- grid.hideOverlay(); // restores automatic loading / empty-state evaluation
187
- const overlay = grid.getOverlayState();
188
- ```
189
-
190
- Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
191
- is present. Horizontal scrolling remains enabled by default and can be locked with
192
- `blockScroll: true`.
193
-
194
- `overlayComponents` accepts framework-specific components through the adapter or core render
195
- callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
196
-
197
- `GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
198
- Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
199
-
200
- ### Plugin contract — `GridPlugin<T>`
201
-
202
- ```ts
203
- interface GridPlugin<T> {
204
- name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
205
- register(api: GridApi<T>): void | (() => void); // returns cleanup
206
- getRowClass?(params: RowRenderParams<T>): string | undefined;
207
- getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
208
- }
209
- ```
210
-
211
- A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
212
- and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
213
- Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
214
- [`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
215
-
216
- ## Quick start
217
-
218
- Headless core only (no UI):
219
-
220
- ```ts
221
- import { Grid } from "@omnigrid/core";
222
- import type { ColumnDef } from "@omnigrid/core";
223
-
224
- interface Row {
225
- id: string;
226
- name: string;
227
- }
228
-
229
- const columns: ColumnDef<Row>[] = [{ id: "name", field: "name", header: "Name", width: 220 }];
230
-
231
- const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
232
-
233
- grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
234
- const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
235
- grid.on("rowClick", (e) => console.log(e.index));
236
- grid.destroy();
237
- ```
238
-
239
- With base plugins:
240
-
241
- ```ts
242
- import { Grid } from "@omnigrid/core";
243
- import { PaginationPlugin } from "@omnigrid/pagination-plugin";
244
- import { SelectionPlugin } from "@omnigrid/selection-plugin";
245
- import { SortingPlugin } from "@omnigrid/sorting-plugin";
246
-
247
- const grid = new Grid<Row>({
248
- data,
249
- columns,
250
- getRowId: (row) => row.id,
251
- plugins: [
252
- new SortingPlugin<Row>(),
253
- new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
254
- new PaginationPlugin<Row>({ pageSize: 50 }),
255
- ],
256
- });
257
- ```
258
-
259
- In a UI framework, use the adapter — e.g. `@omnigrid/react`:
260
-
261
- ```tsx
262
- <OmniGrid
263
- columns={columns}
264
- data={rows}
265
- getRowId={(row) => row.id}
266
- plugins={plugins}
267
- height={480}
268
- />
269
- ```
270
-
271
- See [@omnigrid/react](../../adapters/react/README.md).
272
-
273
- ## Exported helpers
274
-
275
- - `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
276
- - `resolveColSpan`, `getRowSpans`, `getCellSpanningParams` — column spanning
277
- (`ColumnDef.colSpan`): normalized per-cell spans and per-row merged layouts.
278
- - `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
279
- (mostly used internally; public for advanced integrations/tests).
280
-
281
- ### Column spanning (`colSpan`)
282
-
283
- A leaf column may merge horizontally across consecutive visible columns:
284
-
285
- ```ts
286
- const columns: ColumnDef<Row>[] = [
287
- { id: "title", width: 200, colSpan: 2 }, // static: always 2
288
- { id: "note", width: 160, colSpan: ({ data }) => (data.merged ? 3 : 1) },
289
- ];
290
- ```
291
-
292
- `resolveColSpan` normalizes one cell (floors, clamps to `>= 1`, clips to the
293
- pin group, falls back to `1` on resolver errors); `getRowSpans` / `Grid.getRowSpans`
294
- aggregates a whole row — the origin carries the summed pixel width aligned to
295
- the starting column, covered cells are skipped. `Grid.getViewportData`
296
- additionally exposes the full leaf groups (`leafColumns` + `columnOffsets`,
297
- pinned siblings likewise) and expands the shared column window so spans
298
- crossing the viewport boundary are never clipped. The React adapter resolves
299
- per-row layouts (memoized per viewport commit) and paints merged widths via
300
- `translateX` without breaking node recycling.
301
-
302
- ## Links
303
-
304
- - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
305
- - **Demo:** https://omnigrid.cc/demo/react/quick-start
306
- - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
307
-
308
- ## License
309
-
310
- 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>[]; // inferred from the first row when omitted
34
+ autoColumnHeaderMode?: "as-is" | "title-case"; // default: "as-is"
35
+ getColumnHeader?: (field: string) => string; // custom formatter; takes precedence over autoColumnHeaderMode
36
+ getRowId?: (row: T, index: number) => RowId; // default: index-based
37
+ rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
38
+ rowOverscan?: number; // extra rows above/below viewport; default 5
39
+ columnOverscan?: number; // extra columns beyond horizontal window; default 2
40
+ cellFlash?: boolean | number; // highlight changed cells after applyTransaction
41
+ suppressRowHoverHighlight?: boolean;
42
+ rowStyle?: RowStyle;
43
+ getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
44
+ rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
45
+ getRowClass?: (params: RowRenderParams<T>) => string | undefined;
46
+ rowClassRules?: RowClassRules<T>; // class name → predicate
47
+ plugins?: GridPlugin<T>[]; // plugin instances registered at construction
48
+ loading?: boolean; // active fetch; shows loading even with prior rows
49
+ overlayComponents?: Record<string, OverlayComponent<T>>;
50
+ }
51
+ ```
52
+
53
+ When `columns` is omitted, the core infers leaf columns from the first row.
54
+ If the initial dataset is empty or pending, it waits for the first non-empty
55
+ `setData` or `appendData`. The inferred schema stays fixed afterward; call
56
+ `setColumns` when the schema changes. An explicit `columns: []` disables
57
+ inference. Headers default to the field key; set `autoColumnHeaderMode` to
58
+ `"title-case"` to split camel-case keys into capitalized words, or provide
59
+ `getColumnHeader` for a custom formatter.
60
+
61
+ Row callbacks receive `params.rowType` (`"leaf"` or `"group"`). Group rows are synthetic and have no `data`; checking `rowType` narrows the callback parameters.
62
+
63
+ ### `ColumnDef<T>`
64
+
65
+ `ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
66
+
67
+ ```ts
68
+ interface ColumnLeafDef<T> {
69
+ id: string; // unique column id (also stable slot key)
70
+ header: string;
71
+ field?: keyof T | string; // value accessor (default cell value source)
72
+ valueGetter?: (row: T) => unknown; // overrides field
73
+ valueFormatter?: (value: unknown) => string;
74
+ width?: number; // fixed px width
75
+ flex?: number; // flex weight; expands to fill remaining space
76
+ minWidth?: number;
77
+ maxWidth?: number;
78
+ hidden?: boolean;
79
+ movable?: boolean; // opt in to leaf drag-and-drop with a reorder plugin
80
+ pinned?: "left" | "right"; // fixed column in horizontal viewport
81
+ sortable?: boolean; // read by SortingPlugin
82
+ sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
83
+ sortIndex?: number; // runtime 1-based priority when multi-sorted
84
+ align?: "left" | "center" | "right";
85
+ cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
86
+ cellFlash?: boolean; // set false to opt out when GridOptions.cellFlash is enabled
87
+ cellStyle?: RowStyle;
88
+ getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
89
+ cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
90
+ getCellClass?: (params: CellRenderParams<T>) => string | undefined;
91
+ cellClassRules?: CellClassRules<T>;
92
+ getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
93
+ getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
94
+ columnClassRules?: ColumnClassRules<T>;
95
+ headerStyle?: HeaderStyle;
96
+ getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
97
+ headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
98
+ getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
99
+ headerClassRules?: HeaderClassRules<T>;
100
+ headerRenderer?: (column: ColumnDef<T>) => unknown; // primary header content; adapter controls remain separate
101
+ stopRowClick?: boolean;
102
+ stopHeaderClick?: boolean;
103
+ }
104
+
105
+ interface ColumnGroupDef<T> {
106
+ id: string;
107
+ header: string;
108
+ children: ColumnDef<T>[]; // nested leaves / groups
109
+ movable?: boolean; // opt in to moving the entire group with a reorder plugin
110
+ pinned?: "left" | "right";
111
+ collapsible?: boolean;
112
+ defaultExpanded?: boolean;
113
+ headerStyle?: HeaderStyle;
114
+ getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
115
+ headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
116
+ getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
117
+ headerClassRules?: HeaderGroupClassRules<T>;
118
+ headerRenderer?: (column: ColumnDef<T>) => unknown;
119
+ }
120
+ ```
121
+
122
+ `movable` is available on both leaf columns and groups. Dragging a group moves its complete
123
+ subtree; dropping after the last leaf in the final group places the dragged column after the group.
124
+
125
+ When grid-level `cellFlash` is enabled, set `cellFlash: false` on an individual leaf column to opt it out.
126
+
127
+ ### `GridApi<T>`
128
+
129
+ `Grid<T>` implements this interface — the single public surface for adapters and plugins.
130
+ UI code must never touch core internals directly.
131
+
132
+ ```ts
133
+ interface GridApi<T> {
134
+ getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
135
+ getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
136
+ scrollTo(position: Partial<ScrollPosition>): void; // request a native scroll adjustment from the adapter
137
+ getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
138
+ getProcessedData(): T[]; // after all registered data processors
139
+ getRowId(row: T, index: number): RowId;
140
+ setData(data: T[] | null | undefined): void;
141
+ setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
142
+ refresh(): void; // repaint hints (rowClassRules), bumps revision
143
+ subscribe(listener: () => void): () => void;
144
+ on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
145
+ registerPlugin(plugin: GridPlugin<T>): () => void;
146
+ registerHeaderExtension(extension: ColumnHeaderExtension<T>): () => void;
147
+ getHeaderExtensions(position?: ColumnHeaderExtensionPosition): ColumnHeaderExtension<T>[];
148
+ registerDataProcessor(processor: DataProcessor<T>): () => void;
149
+ setColumns(columns: ColumnDef<T>[]): void;
150
+ headerClick(columnId: string, multiSort?: boolean): void;
151
+ rowClick(row: RowClickEvent<T>): void;
152
+ rowHover(row: RowHoverEvent<T>): void;
153
+ readonly slots: SlotManager<T>; // mount headless widgets
154
+ readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
155
+ getSlotMounts(slot: SlotName): SlotMount<T>[];
156
+ showOverlay(options: OverlayOptions): void;
157
+ hideOverlay(): void;
158
+ getOverlayState(): OverlayState;
159
+ setLoading(isLoading: boolean, error?: unknown): void;
160
+ getRevision(): number; // monotonic counter for structural changes
161
+ destroy(): void;
162
+ isDestroyed(): boolean;
163
+ }
164
+ ```
165
+
166
+ `registerHeaderExtension` lets plugins add header content without wrapping or replacing a
167
+ column's `headerRenderer`. Extensions render for each visible leaf column and can target the
168
+ `"start"`, `"end"`, or `"overlay"` region. Lower `priority` values render first; equal priorities
169
+ retain registration order. The returned cleanup callback removes the extension.
170
+
171
+ ### Overlays
172
+
173
+ Overlays are managed in core state, so state transitions notify subscribers only when the
174
+ overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
175
+ loading; an explicit empty array shows the no-rows state. Empty processed results with source
176
+ rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
177
+ through `setLoading(false, error)`; a successful `setData` clears the error.
178
+
179
+ ```ts
180
+ grid.showOverlay({
181
+ type: "error",
182
+ // Errors default to "full"; other overlay types default to "bodyOnly".
183
+ // Set scope explicitly to choose a different placement.
184
+ message: "Could not load records",
185
+ });
186
+ grid.hideOverlay(); // restores automatic loading / empty-state evaluation
187
+ const overlay = grid.getOverlayState();
188
+ ```
189
+
190
+ Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
191
+ is present. Horizontal scrolling remains enabled by default and can be locked with
192
+ `blockScroll: true`.
193
+
194
+ `overlayComponents` accepts framework-specific components through the adapter or core render
195
+ callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
196
+
197
+ `GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
198
+ Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
199
+
200
+ ### Plugin contract — `GridPlugin<T>`
201
+
202
+ ```ts
203
+ interface GridPlugin<T> {
204
+ name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
205
+ register(api: GridApi<T>): void | (() => void); // returns cleanup
206
+ getRowClass?(params: RowRenderParams<T>): string | undefined;
207
+ getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
208
+ }
209
+ ```
210
+
211
+ A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
212
+ and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
213
+ Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
214
+ [`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
215
+
216
+ ## Quick start
217
+
218
+ Headless core only (no UI):
219
+
220
+ ```ts
221
+ import { Grid } from "@omnigrid/core";
222
+ import type { ColumnDef } from "@omnigrid/core";
223
+
224
+ interface Row {
225
+ id: string;
226
+ name: string;
227
+ }
228
+
229
+ const columns: ColumnDef<Row>[] = [{ id: "name", field: "name", header: "Name", width: 220 }];
230
+
231
+ const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
232
+
233
+ grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
234
+ const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
235
+ grid.on("rowClick", (e) => console.log(e.index));
236
+ grid.destroy();
237
+ ```
238
+
239
+ With base plugins:
240
+
241
+ ```ts
242
+ import { Grid } from "@omnigrid/core";
243
+ import { PaginationPlugin } from "@omnigrid/pagination-plugin";
244
+ import { SelectionPlugin } from "@omnigrid/selection-plugin";
245
+ import { SortingPlugin } from "@omnigrid/sorting-plugin";
246
+
247
+ const grid = new Grid<Row>({
248
+ data,
249
+ columns,
250
+ getRowId: (row) => row.id,
251
+ plugins: [
252
+ new SortingPlugin<Row>(),
253
+ new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
254
+ new PaginationPlugin<Row>({ pageSize: 50 }),
255
+ ],
256
+ });
257
+ ```
258
+
259
+ In a UI framework, use the adapter — e.g. `@omnigrid/react`:
260
+
261
+ ```tsx
262
+ <OmniGrid
263
+ columns={columns}
264
+ data={rows}
265
+ getRowId={(row) => row.id}
266
+ plugins={plugins}
267
+ height={480}
268
+ />
269
+ ```
270
+
271
+ See [@omnigrid/react](../../adapters/react/README.md).
272
+
273
+ ## Exported helpers
274
+
275
+ - `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
276
+ - `resolveColSpan`, `getRowSpans`, `getCellSpanningParams` — column spanning
277
+ (`ColumnDef.colSpan`): normalized per-cell spans and per-row merged layouts.
278
+ - `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
279
+ (mostly used internally; public for advanced integrations/tests).
280
+
281
+ ### Column spanning (`colSpan`)
282
+
283
+ A leaf column may merge horizontally across consecutive visible columns:
284
+
285
+ ```ts
286
+ const columns: ColumnDef<Row>[] = [
287
+ { id: "title", width: 200, colSpan: 2 }, // static: always 2
288
+ { id: "note", width: 160, colSpan: ({ data }) => (data.merged ? 3 : 1) },
289
+ ];
290
+ ```
291
+
292
+ `resolveColSpan` normalizes one cell (floors, clamps to `>= 1`, clips to the
293
+ pin group, falls back to `1` on resolver errors); `getRowSpans` / `Grid.getRowSpans`
294
+ aggregates a whole row — the origin carries the summed pixel width aligned to
295
+ the starting column, covered cells are skipped. `Grid.getViewportData`
296
+ additionally exposes the full leaf groups (`leafColumns` + `columnOffsets`,
297
+ pinned siblings likewise) and expands the shared column window so spans
298
+ crossing the viewport boundary are never clipped. The React adapter resolves
299
+ per-row layouts (memoized per viewport commit) and paints merged widths via
300
+ `translateX` without breaking node recycling.
301
+
302
+ ## Links
303
+
304
+ - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
305
+ - **Demo:** https://omnigrid.cc/demo/react/quick-start
306
+ - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
307
+
308
+ ## License
309
+
310
+ MIT © KRZK Apps
package/dist/types.d.ts CHANGED
@@ -468,10 +468,10 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
468
468
  /** Aggregation function used when this column is inside a group. */
469
469
  aggFunc?: AggregationFunc<T> | string;
470
470
  /**
471
- * Controls whether the cell keeps the theme's internal padding or removes it
472
- * so custom content can fill the cell.
471
+ * Controls whether the cell keeps the theme's internal padding or lets
472
+ * custom content fill the cell.
473
473
  * - `"normal"` (default): preserves the theme padding.
474
- * - `"flush"`: removes the cell padding.
474
+ * - `"flush"`: removes the cell padding and stretches custom content to fill the cell.
475
475
  * @default "normal"
476
476
  * @api
477
477
  */
package/package.json CHANGED
@@ -1,44 +1,45 @@
1
- {
2
- "name": "@omnigrid/core",
3
- "version": "0.1.38",
4
- "description": "Framework-agnostic core engine for OmniGrid",
5
- "keywords": [
6
- "omnigrid",
7
- "grid",
8
- "table",
9
- "datatable",
10
- "core",
11
- "typescript"
12
- ],
13
- "repository": {
14
- "type": "git",
15
- "url": "https://github.com/KRZK-Apps/omnigrid.git",
16
- "directory": "core"
17
- },
18
- "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/core#readme",
19
- "bugs": {
20
- "url": "https://github.com/KRZK-Apps/omnigrid/issues"
21
- },
22
- "license": "MIT",
23
- "type": "module",
24
- "main": "dist/index.js",
25
- "types": "dist/index.d.ts",
26
- "exports": {
27
- ".": {
28
- "types": "./dist/index.d.ts",
29
- "import": "./dist/index.js"
30
- }
31
- },
32
- "files": [
33
- "dist"
34
- ],
35
- "scripts": {
36
- "build": "npx tsc -p tsconfig.json",
37
- "lint": "npx tsc --noEmit -p tsconfig.json",
38
- "test": "vitest run",
39
- "prepublishOnly": "npm run build"
40
- },
41
- "devDependencies": {
42
- "vitest": "^5.0.2"
43
- }
44
- }
1
+ {
2
+ "name": "@omnigrid/core",
3
+ "version": "0.1.40",
4
+ "description": "Framework-agnostic core engine for OmniGrid",
5
+ "keywords": [
6
+ "omnigrid",
7
+ "grid",
8
+ "table",
9
+ "datatable",
10
+ "core",
11
+ "typescript"
12
+ ],
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/KRZK-Apps/omnigrid.git",
16
+ "directory": "core"
17
+ },
18
+ "homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/core#readme",
19
+ "bugs": {
20
+ "url": "https://github.com/KRZK-Apps/omnigrid/issues"
21
+ },
22
+ "license": "MIT",
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": {
28
+ "types": "./dist/index.d.ts",
29
+ "import": "./dist/index.js"
30
+ }
31
+ },
32
+ "files": [
33
+ "dist"
34
+ ],
35
+ "scripts": {
36
+ "build": "npx tsc -p tsconfig.json",
37
+ "lint": "npx tsc --noEmit -p tsconfig.json",
38
+ "test": "vitest run",
39
+ "prepublishOnly": "npm run build"
40
+ },
41
+ "devDependencies": {
42
+ "typescript": "^5.9.3",
43
+ "vitest": "^5.0.2"
44
+ }
45
+ }