@omnigrid/core 0.1.10 → 0.1.12
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 +248 -231
- package/dist/columns.d.ts +9 -0
- package/dist/columns.js +15 -0
- package/dist/grid.js +7 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/overlays.d.ts +2 -2
- package/dist/types.d.ts +106 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,231 +1,248 @@
|
|
|
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()`.
|
|
22
|
-
|
|
23
|
-
## Key contracts
|
|
24
|
-
|
|
25
|
-
### `GridOptions<T>`
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
interface GridOptions<T> {
|
|
29
|
-
data?: T[] | null; // row data; null/omitted means initial loading
|
|
30
|
-
columns: ColumnDef<T>[]; // required
|
|
31
|
-
getRowId?: (row: T, index: number) => RowId; // default: index-based
|
|
32
|
-
rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
|
|
33
|
-
rowOverscan?: number; // extra rows above/below viewport; default 5
|
|
34
|
-
columnOverscan?: number; // extra columns beyond horizontal window; default 2
|
|
35
|
-
suppressRowHoverHighlight?: boolean;
|
|
36
|
-
rowStyle?: RowStyle;
|
|
37
|
-
getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
|
|
38
|
-
rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
|
|
39
|
-
getRowClass?: (params: RowRenderParams<T>) => string | undefined;
|
|
40
|
-
rowClassRules?: RowClassRules<T>; // class name → predicate
|
|
41
|
-
plugins?: GridPlugin<T>[]; // plugin instances registered at construction
|
|
42
|
-
loading?: boolean; // active fetch; shows loading even with prior rows
|
|
43
|
-
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### `ColumnDef<T>`
|
|
48
|
-
|
|
49
|
-
`ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
interface ColumnLeafDef<T> {
|
|
53
|
-
id: string; // unique column id (also stable slot key)
|
|
54
|
-
header: string;
|
|
55
|
-
field?: keyof T | string; // value accessor (default cell value source)
|
|
56
|
-
valueGetter?: (row: T) => unknown; // overrides field
|
|
57
|
-
valueFormatter?: (value: unknown) => string;
|
|
58
|
-
width?: number; // fixed px width
|
|
59
|
-
flex?: number; // flex weight; expands to fill remaining space
|
|
60
|
-
minWidth?: number;
|
|
61
|
-
maxWidth?: number;
|
|
62
|
-
hidden?: boolean;
|
|
63
|
-
pinned?: "left" | "right"; // fixed column in horizontal viewport
|
|
64
|
-
sortable?: boolean; // read by SortingPlugin
|
|
65
|
-
sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
|
|
66
|
-
sortIndex?: number; // runtime 1-based priority when multi-sorted
|
|
67
|
-
align?: "left" | "center" | "right";
|
|
68
|
-
cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
|
|
69
|
-
cellStyle?: RowStyle;
|
|
70
|
-
getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
|
|
71
|
-
cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
|
|
72
|
-
getCellClass?: (params: CellRenderParams<T>) => string | undefined;
|
|
73
|
-
cellClassRules?: CellClassRules<T>;
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
`
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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()`.
|
|
22
|
+
|
|
23
|
+
## Key contracts
|
|
24
|
+
|
|
25
|
+
### `GridOptions<T>`
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
interface GridOptions<T> {
|
|
29
|
+
data?: T[] | null; // row data; null/omitted means initial loading
|
|
30
|
+
columns: ColumnDef<T>[]; // required
|
|
31
|
+
getRowId?: (row: T, index: number) => RowId; // default: index-based
|
|
32
|
+
rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
|
|
33
|
+
rowOverscan?: number; // extra rows above/below viewport; default 5
|
|
34
|
+
columnOverscan?: number; // extra columns beyond horizontal window; default 2
|
|
35
|
+
suppressRowHoverHighlight?: boolean;
|
|
36
|
+
rowStyle?: RowStyle;
|
|
37
|
+
getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
|
|
38
|
+
rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
|
|
39
|
+
getRowClass?: (params: RowRenderParams<T>) => string | undefined;
|
|
40
|
+
rowClassRules?: RowClassRules<T>; // class name → predicate
|
|
41
|
+
plugins?: GridPlugin<T>[]; // plugin instances registered at construction
|
|
42
|
+
loading?: boolean; // active fetch; shows loading even with prior rows
|
|
43
|
+
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `ColumnDef<T>`
|
|
48
|
+
|
|
49
|
+
`ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
interface ColumnLeafDef<T> {
|
|
53
|
+
id: string; // unique column id (also stable slot key)
|
|
54
|
+
header: string;
|
|
55
|
+
field?: keyof T | string; // value accessor (default cell value source)
|
|
56
|
+
valueGetter?: (row: T) => unknown; // overrides field
|
|
57
|
+
valueFormatter?: (value: unknown) => string;
|
|
58
|
+
width?: number; // fixed px width
|
|
59
|
+
flex?: number; // flex weight; expands to fill remaining space
|
|
60
|
+
minWidth?: number;
|
|
61
|
+
maxWidth?: number;
|
|
62
|
+
hidden?: boolean;
|
|
63
|
+
pinned?: "left" | "right"; // fixed column in horizontal viewport
|
|
64
|
+
sortable?: boolean; // read by SortingPlugin
|
|
65
|
+
sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
|
|
66
|
+
sortIndex?: number; // runtime 1-based priority when multi-sorted
|
|
67
|
+
align?: "left" | "center" | "right";
|
|
68
|
+
cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
|
|
69
|
+
cellStyle?: RowStyle;
|
|
70
|
+
getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
|
|
71
|
+
cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
|
|
72
|
+
getCellClass?: (params: CellRenderParams<T>) => string | undefined;
|
|
73
|
+
cellClassRules?: CellClassRules<T>;
|
|
74
|
+
getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
|
|
75
|
+
getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
|
|
76
|
+
columnClassRules?: ColumnClassRules<T>;
|
|
77
|
+
headerStyle?: HeaderStyle;
|
|
78
|
+
getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
|
|
79
|
+
headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
|
|
80
|
+
getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
|
|
81
|
+
headerClassRules?: HeaderClassRules<T>;
|
|
82
|
+
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
83
|
+
stopRowClick?: boolean;
|
|
84
|
+
stopHeaderClick?: boolean;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
interface ColumnGroupDef<T> {
|
|
88
|
+
id: string;
|
|
89
|
+
header: string;
|
|
90
|
+
children: ColumnDef<T>[]; // nested leaves / groups
|
|
91
|
+
pinned?: "left" | "right";
|
|
92
|
+
collapsible?: boolean;
|
|
93
|
+
defaultExpanded?: boolean;
|
|
94
|
+
headerStyle?: HeaderStyle;
|
|
95
|
+
getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
|
|
96
|
+
headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
|
|
97
|
+
getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
|
|
98
|
+
headerClassRules?: HeaderGroupClassRules<T>;
|
|
99
|
+
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
100
|
+
}
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### `GridApi<T>`
|
|
104
|
+
|
|
105
|
+
`Grid<T>` implements this interface — the single public surface for adapters and plugins.
|
|
106
|
+
UI code must never touch core internals directly.
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
interface GridApi<T> {
|
|
110
|
+
getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
|
|
111
|
+
getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
|
|
112
|
+
getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
|
|
113
|
+
getProcessedData(): T[]; // after all registered data processors
|
|
114
|
+
getRowId(row: T, index: number): RowId;
|
|
115
|
+
setData(data: T[] | null | undefined): void;
|
|
116
|
+
setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
|
|
117
|
+
refresh(): void; // repaint hints (rowClassRules), bumps revision
|
|
118
|
+
subscribe(listener: () => void): () => void;
|
|
119
|
+
on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
|
|
120
|
+
registerPlugin(plugin: GridPlugin<T>): () => void;
|
|
121
|
+
registerDataProcessor(processor: DataProcessor<T>): () => void;
|
|
122
|
+
setColumns(columns: ColumnDef<T>[]): void;
|
|
123
|
+
headerClick(columnId: string, multiSort?: boolean): void;
|
|
124
|
+
rowClick(row: RowClickEvent<T>): void;
|
|
125
|
+
rowHover(row: RowHoverEvent<T>): void;
|
|
126
|
+
readonly slots: SlotManager<T>; // mount headless widgets
|
|
127
|
+
readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
|
|
128
|
+
getSlotMounts(slot: SlotName): SlotMount<T>[];
|
|
129
|
+
showOverlay(options: OverlayOptions): void;
|
|
130
|
+
hideOverlay(): void;
|
|
131
|
+
getOverlayState(): OverlayState;
|
|
132
|
+
setLoading(isLoading: boolean, error?: unknown): void;
|
|
133
|
+
getRevision(): number; // monotonic counter for structural changes
|
|
134
|
+
destroy(): void;
|
|
135
|
+
isDestroyed(): boolean;
|
|
136
|
+
}
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
### Overlays
|
|
140
|
+
|
|
141
|
+
Overlays are managed in core state, so state transitions notify subscribers only when the
|
|
142
|
+
overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
|
|
143
|
+
loading; an explicit empty array shows the no-rows state. Empty processed results with source
|
|
144
|
+
rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
|
|
145
|
+
through `setLoading(false, error)`; a successful `setData` clears the error.
|
|
146
|
+
|
|
147
|
+
```ts
|
|
148
|
+
grid.showOverlay({
|
|
149
|
+
type: "error",
|
|
150
|
+
// Errors default to "full"; other overlay types default to "bodyOnly".
|
|
151
|
+
// Set scope explicitly to choose a different placement.
|
|
152
|
+
message: "Could not load records",
|
|
153
|
+
});
|
|
154
|
+
grid.hideOverlay(); // restores automatic loading / empty-state evaluation
|
|
155
|
+
const overlay = grid.getOverlayState();
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
|
|
159
|
+
is present. Horizontal scrolling remains enabled by default and can be locked with
|
|
160
|
+
`blockScroll: true`.
|
|
161
|
+
|
|
162
|
+
`overlayComponents` accepts framework-specific components through the adapter or core render
|
|
163
|
+
callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
|
|
164
|
+
|
|
165
|
+
`GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
|
|
166
|
+
Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
|
|
167
|
+
|
|
168
|
+
### Plugin contract — `GridPlugin<T>`
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
interface GridPlugin<T> {
|
|
172
|
+
name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
|
|
173
|
+
register(api: GridApi<T>): void | (() => void); // returns cleanup
|
|
174
|
+
getRowClass?(params: RowRenderParams<T>): string | undefined;
|
|
175
|
+
getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
|
|
180
|
+
and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
|
|
181
|
+
Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
|
|
182
|
+
[`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
|
|
183
|
+
|
|
184
|
+
## Quick start
|
|
185
|
+
|
|
186
|
+
Headless core only (no UI):
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import { Grid } from "@omnigrid/core";
|
|
190
|
+
import type { ColumnDef } from "@omnigrid/core";
|
|
191
|
+
|
|
192
|
+
interface Row { id: string; name: string }
|
|
193
|
+
|
|
194
|
+
const columns: ColumnDef<Row>[] = [
|
|
195
|
+
{ id: "name", field: "name", header: "Name", width: 220 },
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
|
|
199
|
+
|
|
200
|
+
grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
|
|
201
|
+
const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
|
|
202
|
+
grid.on("rowClick", (e) => console.log(e.index));
|
|
203
|
+
grid.destroy();
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
With base plugins:
|
|
207
|
+
|
|
208
|
+
```ts
|
|
209
|
+
import { Grid } from "@omnigrid/core";
|
|
210
|
+
import { SortingPlugin } from "@omnigrid/sorting-plugin";
|
|
211
|
+
import { SelectionPlugin } from "@omnigrid/selection-plugin";
|
|
212
|
+
import { PaginationPlugin } from "@omnigrid/pagination-plugin";
|
|
213
|
+
|
|
214
|
+
const grid = new Grid<Row>({
|
|
215
|
+
data,
|
|
216
|
+
columns,
|
|
217
|
+
getRowId: (row) => row.id,
|
|
218
|
+
plugins: [
|
|
219
|
+
new SortingPlugin<Row>(),
|
|
220
|
+
new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
|
|
221
|
+
new PaginationPlugin<Row>({ pageSize: 50 }),
|
|
222
|
+
],
|
|
223
|
+
});
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
In a UI framework, use the adapter — e.g. `@omnigrid/react`:
|
|
227
|
+
|
|
228
|
+
```tsx
|
|
229
|
+
<OmniGrid columns={columns} data={rows} getRowId={(row) => row.id} plugins={plugins} style={{ height: 480 }} />
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
See [@omnigrid/react](../../adapters/react/README.md).
|
|
233
|
+
|
|
234
|
+
## Exported helpers
|
|
235
|
+
|
|
236
|
+
- `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
|
|
237
|
+
- `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
|
|
238
|
+
(mostly used internally; public for advanced integrations/tests).
|
|
239
|
+
|
|
240
|
+
## Links
|
|
241
|
+
|
|
242
|
+
- **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
|
|
243
|
+
- **Demo:** https://omnigrid-demo.vercel.app/
|
|
244
|
+
- **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT © KRZK Apps
|
package/dist/columns.d.ts
CHANGED
|
@@ -31,3 +31,12 @@ export declare function flattenColumns<T>(columns: ColumnDef<T>[]): ColumnLeafDe
|
|
|
31
31
|
* tree when rendering stacked header rows.
|
|
32
32
|
*/
|
|
33
33
|
export declare function getColumnGroups<T>(columns: ColumnDef<T>[], isVisible?: (leaf: ColumnLeafDef<T>) => boolean): ColumnGroupViewport<T>[];
|
|
34
|
+
/**
|
|
35
|
+
* Resolves the raw cell value from a row object using `valueGetter` or `field`.
|
|
36
|
+
*
|
|
37
|
+
* @param row - The row data object.
|
|
38
|
+
* @param column - The leaf column definition.
|
|
39
|
+
* @returns The resolved cell value, or undefined if not accessible.
|
|
40
|
+
* @api
|
|
41
|
+
*/
|
|
42
|
+
export declare function getCellValue<T>(row: T, column: ColumnLeafDef<T>): unknown;
|
package/dist/columns.js
CHANGED
|
@@ -75,3 +75,18 @@ export function getColumnGroups(columns, isVisible = () => true) {
|
|
|
75
75
|
walk(columns, 0);
|
|
76
76
|
return result;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Resolves the raw cell value from a row object using `valueGetter` or `field`.
|
|
80
|
+
*
|
|
81
|
+
* @param row - The row data object.
|
|
82
|
+
* @param column - The leaf column definition.
|
|
83
|
+
* @returns The resolved cell value, or undefined if not accessible.
|
|
84
|
+
* @api
|
|
85
|
+
*/
|
|
86
|
+
export function getCellValue(row, column) {
|
|
87
|
+
if (column.valueGetter)
|
|
88
|
+
return column.valueGetter(row);
|
|
89
|
+
if (column.field)
|
|
90
|
+
return row[column.field];
|
|
91
|
+
return undefined;
|
|
92
|
+
}
|
package/dist/grid.js
CHANGED
|
@@ -321,7 +321,11 @@ export class Grid {
|
|
|
321
321
|
showOverlay(options) {
|
|
322
322
|
this.assertActive();
|
|
323
323
|
this.overlayManual = true;
|
|
324
|
-
this.overlayState = {
|
|
324
|
+
this.overlayState = {
|
|
325
|
+
...options,
|
|
326
|
+
scope: options.scope ?? (options.type === "error" ? "full" : "bodyOnly"),
|
|
327
|
+
blockScroll: options.blockScroll ?? false,
|
|
328
|
+
};
|
|
325
329
|
this.store.setState({ overlay: { ...this.overlayState } });
|
|
326
330
|
this.events.emit("overlayChange", { ...this.overlayState });
|
|
327
331
|
}
|
|
@@ -365,8 +369,9 @@ export class Grid {
|
|
|
365
369
|
const next = type
|
|
366
370
|
? {
|
|
367
371
|
type,
|
|
372
|
+
scope: type === "error" ? "full" : "bodyOnly",
|
|
373
|
+
blockScroll: false,
|
|
368
374
|
...(type === "error" && this.loadError !== undefined ? { payload: this.loadError } : {}),
|
|
369
|
-
...(type === "noMatchingRows" ? { blockScroll: false } : {}),
|
|
370
375
|
}
|
|
371
376
|
: { type };
|
|
372
377
|
if (next.type !== this.overlayState.type ||
|
package/dist/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ export { Grid as GridCore } from "./grid";
|
|
|
8
8
|
export { SlotManager } from "./slots";
|
|
9
9
|
export { Store } from "./store";
|
|
10
10
|
export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
|
|
11
|
-
export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
12
|
-
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf } from "./columns";
|
|
11
|
+
export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnClassRules, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
|
|
12
|
+
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
|
|
13
13
|
export { Virtualizer } from "./virtualizer";
|
package/dist/index.js
CHANGED
|
@@ -6,5 +6,5 @@ export { Grid } from "./grid";
|
|
|
6
6
|
export { Grid as GridCore } from "./grid";
|
|
7
7
|
export { SlotManager } from "./slots";
|
|
8
8
|
export { Store } from "./store";
|
|
9
|
-
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf } from "./columns";
|
|
9
|
+
export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue } from "./columns";
|
|
10
10
|
export { Virtualizer } from "./virtualizer";
|
package/dist/overlays.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export type OverlayScope = "full" | "bodyOnly";
|
|
|
24
24
|
export interface OverlayOptions {
|
|
25
25
|
/** Overlay state to display. */
|
|
26
26
|
type: OverlayType;
|
|
27
|
-
/** Whether the overlay covers the complete grid or only its data body.
|
|
27
|
+
/** Whether the overlay covers the complete grid or only its data body. Defaults to "full" for errors and "bodyOnly" otherwise. */
|
|
28
28
|
scope?: OverlayScope;
|
|
29
|
-
/** Whether horizontal scrolling is
|
|
29
|
+
/** Whether horizontal scrolling is locked. Vertical scrolling is locked for every active overlay. */
|
|
30
30
|
blockScroll?: boolean;
|
|
31
31
|
/** Optional text displayed by the default overlay or passed to a custom component. */
|
|
32
32
|
message?: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -39,6 +39,84 @@ export interface CellRenderParams<T> {
|
|
|
39
39
|
value?: unknown;
|
|
40
40
|
}
|
|
41
41
|
export type CellClassRules<T> = Record<string, (params: CellRenderParams<T>) => boolean>;
|
|
42
|
+
/**
|
|
43
|
+
* Inline styles applied to all cells in a column.
|
|
44
|
+
*
|
|
45
|
+
* @api
|
|
46
|
+
*/
|
|
47
|
+
export interface ColumnStyle {
|
|
48
|
+
[property: string]: string | number | undefined;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Context passed to column-level presentation callbacks (`getColumnStyle`,
|
|
52
|
+
* `getColumnClass`, `columnClassRules`).
|
|
53
|
+
*
|
|
54
|
+
* Evaluated once per column across the dataset rather than per individual cell.
|
|
55
|
+
*
|
|
56
|
+
* @api
|
|
57
|
+
*/
|
|
58
|
+
export interface ColumnStyleParams<T> {
|
|
59
|
+
/** The leaf column definition being evaluated. */
|
|
60
|
+
column: ColumnLeafDef<T>;
|
|
61
|
+
/** All visible/filtered values for this column. */
|
|
62
|
+
values: any[];
|
|
63
|
+
/** The grid API instance. */
|
|
64
|
+
api: GridApi<T>;
|
|
65
|
+
/** Current grid state. */
|
|
66
|
+
state: GridState<T>;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Dynamic rules for assigning CSS classes to a column as a whole.
|
|
70
|
+
*
|
|
71
|
+
* @api
|
|
72
|
+
*/
|
|
73
|
+
export type ColumnClassRules<T> = Record<string, (params: ColumnStyleParams<T>) => boolean>;
|
|
74
|
+
/**
|
|
75
|
+
* Context passed to leaf header presentation callbacks.
|
|
76
|
+
*
|
|
77
|
+
* @api
|
|
78
|
+
*/
|
|
79
|
+
export interface HeaderRenderParams<T> {
|
|
80
|
+
/** The leaf column definition being rendered. */
|
|
81
|
+
column: ColumnLeafDef<T>;
|
|
82
|
+
/** Zero-based index of the leaf column in the visible layout. */
|
|
83
|
+
index?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Inline styles applied to a column or group header.
|
|
87
|
+
*
|
|
88
|
+
* @api
|
|
89
|
+
*/
|
|
90
|
+
export interface HeaderStyle {
|
|
91
|
+
[property: string]: string | number | undefined;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Dynamic rules for assigning CSS classes to a leaf column header.
|
|
95
|
+
*
|
|
96
|
+
* @api
|
|
97
|
+
*/
|
|
98
|
+
export type HeaderClassRules<T> = Record<string, (params: HeaderRenderParams<T>) => boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Context passed to column group header presentation callbacks.
|
|
101
|
+
*
|
|
102
|
+
* @api
|
|
103
|
+
*/
|
|
104
|
+
export interface HeaderGroupRenderParams<T> {
|
|
105
|
+
/** The column group definition being rendered. */
|
|
106
|
+
group: ColumnGroupDef<T>;
|
|
107
|
+
/** Alias for `group` providing uniform access to the column definition. */
|
|
108
|
+
column: ColumnGroupDef<T>;
|
|
109
|
+
/** Depth of the group in the stacked header hierarchy (0 = topmost). */
|
|
110
|
+
depth?: number;
|
|
111
|
+
/** Number of leaf columns spanned by this group segment. */
|
|
112
|
+
columnCount?: number;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Dynamic rules for assigning CSS classes to a column group header.
|
|
116
|
+
*
|
|
117
|
+
* @api
|
|
118
|
+
*/
|
|
119
|
+
export type HeaderGroupClassRules<T> = Record<string, (params: HeaderGroupRenderParams<T>) => boolean>;
|
|
42
120
|
export interface CheckboxRenderParams {
|
|
43
121
|
checked: boolean;
|
|
44
122
|
indeterminate: boolean;
|
|
@@ -107,6 +185,22 @@ export interface ColumnLeafDef<T> extends BaseColumnDef<T> {
|
|
|
107
185
|
getCellClass?: (params: CellRenderParams<T>) => string | undefined;
|
|
108
186
|
/** Maps CSS class names to predicates evaluated for each rendered cell. */
|
|
109
187
|
cellClassRules?: CellClassRules<T>;
|
|
188
|
+
/** Computes inline styles for the entire column body once per column evaluation across dataset. */
|
|
189
|
+
getColumnStyle?: (params: ColumnStyleParams<T>) => ColumnStyle | undefined;
|
|
190
|
+
/** Computes a CSS class for the entire column body across dataset. */
|
|
191
|
+
getColumnClass?: (params: ColumnStyleParams<T>) => string | undefined;
|
|
192
|
+
/** Maps CSS class names to predicates evaluated once for the entire column body across dataset. */
|
|
193
|
+
columnClassRules?: ColumnClassRules<T>;
|
|
194
|
+
/** Static inline styles applied to the leaf header cell of this column. */
|
|
195
|
+
headerStyle?: HeaderStyle;
|
|
196
|
+
/** Computes inline styles for the leaf header cell of this column. */
|
|
197
|
+
getHeaderStyle?: (params: HeaderRenderParams<T>) => HeaderStyle | undefined;
|
|
198
|
+
/** Static CSS class or resolver applied to the leaf header cell of this column. */
|
|
199
|
+
headerClass?: string | ((params: HeaderRenderParams<T>) => string | undefined);
|
|
200
|
+
/** Computes a CSS class for the leaf header cell of this column. */
|
|
201
|
+
getHeaderClass?: (params: HeaderRenderParams<T>) => string | undefined;
|
|
202
|
+
/** Maps CSS class names to predicates evaluated for the leaf header cell of this column. */
|
|
203
|
+
headerClassRules?: HeaderClassRules<T>;
|
|
110
204
|
}
|
|
111
205
|
export interface ColumnGroupDef<T> extends BaseColumnDef<T> {
|
|
112
206
|
/** Child column definitions nested under this group. */
|
|
@@ -115,6 +209,16 @@ export interface ColumnGroupDef<T> extends BaseColumnDef<T> {
|
|
|
115
209
|
collapsible?: boolean;
|
|
116
210
|
/** Whether this group starts expanded when it is collapsible. */
|
|
117
211
|
defaultExpanded?: boolean;
|
|
212
|
+
/** Static inline styles applied to this group header cell. */
|
|
213
|
+
headerStyle?: HeaderStyle;
|
|
214
|
+
/** Computes inline styles for this group header cell. */
|
|
215
|
+
getHeaderStyle?: (params: HeaderGroupRenderParams<T>) => HeaderStyle | undefined;
|
|
216
|
+
/** Static CSS class or resolver applied to this group header cell. */
|
|
217
|
+
headerClass?: string | ((params: HeaderGroupRenderParams<T>) => string | undefined);
|
|
218
|
+
/** Computes a CSS class for this group header cell. */
|
|
219
|
+
getHeaderClass?: (params: HeaderGroupRenderParams<T>) => string | undefined;
|
|
220
|
+
/** Maps CSS class names to predicates evaluated for this group header cell. */
|
|
221
|
+
headerClassRules?: HeaderGroupClassRules<T>;
|
|
118
222
|
}
|
|
119
223
|
/** Leaf or grouped column definition accepted by the grid. */
|
|
120
224
|
export type ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>;
|
|
@@ -457,8 +561,8 @@ export interface GridApi<T> {
|
|
|
457
561
|
* Shows an overlay using the supplied options.
|
|
458
562
|
*
|
|
459
563
|
* Manual overlays take precedence over automatic states until `hideOverlay`
|
|
460
|
-
* is called. Vertical scrolling is locked for
|
|
461
|
-
* controls whether horizontal scrolling is locked
|
|
564
|
+
* is called. Vertical scrolling is locked for every active overlay;
|
|
565
|
+
* `blockScroll` controls whether horizontal scrolling is locked.
|
|
462
566
|
* @param options - Overlay type, scope, message, and custom render payload.
|
|
463
567
|
* @api
|
|
464
568
|
*/
|