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