@omnigrid/core 0.1.37 → 0.1.39
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/LICENSE +21 -21
- package/README.md +310 -310
- package/dist/dom-pool.js +3 -0
- package/dist/grid.d.ts +9 -1
- package/dist/grid.js +50 -4
- package/dist/icons.d.ts +1 -1
- package/dist/icons.js +6 -0
- package/dist/index.d.ts +2 -2
- package/dist/types.d.ts +43 -0
- package/dist/ui.d.ts +84 -7
- package/dist/virtualizer.d.ts +6 -0
- package/dist/virtualizer.js +15 -0
- 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/dom-pool.js
CHANGED
|
@@ -47,6 +47,7 @@ export class DomPool {
|
|
|
47
47
|
* report describing the update.
|
|
48
48
|
*/
|
|
49
49
|
update(viewport) {
|
|
50
|
+
performance.mark("omnigrid.domPool.update.start");
|
|
50
51
|
this.assertActive();
|
|
51
52
|
const { data, rowRange, rowHeight, rowOffsets, rowHeights, visibleRowRange, rowWidth, skipBind } = viewport;
|
|
52
53
|
if (data !== this.lastData) {
|
|
@@ -206,6 +207,8 @@ export class DomPool {
|
|
|
206
207
|
recycled.push(host);
|
|
207
208
|
}
|
|
208
209
|
this.forceRebind = false;
|
|
210
|
+
performance.mark("omnigrid.domPool.update.end");
|
|
211
|
+
performance.measure("OmniGrid DomPool.update", "omnigrid.domPool.update.start", "omnigrid.domPool.update.end");
|
|
209
212
|
return {
|
|
210
213
|
windowStart: range.start,
|
|
211
214
|
windowEnd: range.end,
|
package/dist/grid.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import type { OverlayOptions, OverlayState } from "./overlays.js";
|
|
|
4
4
|
import { DataPipeline } from "./pipeline.js";
|
|
5
5
|
import { SlotManager } from "./slots.js";
|
|
6
6
|
import { type StateUpdater } from "./store.js";
|
|
7
|
-
import type { AggregationFunc, ColumnHeaderExtension, ColumnHeaderExtensionPosition, ColumnLeafDef, DataProcessor, DefaultColumnDef, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHierarchy, RowHoverEvent, RowId, RowSpanLayout, RowTransaction, ScrollPosition, GridStateUpdateOptions, SlotMount, SlotName, TransactionResult, TreeRowNode, ViewportData, ViewportState } from "./types.js";
|
|
7
|
+
import type { AggregationFunc, ColumnHeaderExtension, ColumnHeaderExtensionPosition, ColumnLeafDef, DataProcessor, DefaultColumnDef, GridApi, GridEvents, GridMetrics, GridOptions, GridPlugin, GridState, RowClickEvent, RowHeightUpdateOptions, RowHierarchy, RowHoverEvent, RowId, RowSpanLayout, RowTransaction, ScrollPosition, GridStateUpdateOptions, SlotMount, SlotName, TransactionResult, TreeRowNode, ViewportData, ViewportState } from "./types.js";
|
|
8
8
|
import type { UIPopupAnchor, UIPopupDescriptor } from "./ui.js";
|
|
9
9
|
export declare class Grid<T> implements GridApi<T> {
|
|
10
10
|
private readonly store;
|
|
@@ -282,6 +282,14 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
282
282
|
resetRowHeight(rowIndex: number, options?: RowHeightUpdateOptions): number;
|
|
283
283
|
/** Removes all measured row heights (e.g. after `setColumns`). @api */
|
|
284
284
|
resetAllRowHeights(): void;
|
|
285
|
+
/**
|
|
286
|
+
* Updates structural grid metrics at runtime (e.g. the base row height when
|
|
287
|
+
* a theme scales the whole grid). Recomputes the virtualizer geometry and
|
|
288
|
+
* notifies Store subscribers so the host re-renders with the new layout.
|
|
289
|
+
* @param metrics - Metrics to apply; omitted fields are left unchanged.
|
|
290
|
+
* @api
|
|
291
|
+
*/
|
|
292
|
+
setMetrics(metrics: GridMetrics): void;
|
|
285
293
|
/**
|
|
286
294
|
* Returns the absolute vertical offset (px) of the top of a row,
|
|
287
295
|
* accounting for variable heights. Falls back to `index * rowHeight`
|
package/dist/grid.js
CHANGED
|
@@ -89,12 +89,14 @@ export class Grid {
|
|
|
89
89
|
this.autoColumnsPending = options.columns === undefined && (options.data?.length ?? 0) === 0;
|
|
90
90
|
this.autoColumnHeaderMode = options.autoColumnHeaderMode;
|
|
91
91
|
this.getColumnHeader = options.getColumnHeader;
|
|
92
|
+
const scale = options.scale ?? 1;
|
|
92
93
|
const state = {
|
|
93
94
|
data: options.data ?? [],
|
|
94
95
|
columns: applyWrapText(applyDefaultColumnDef(options.columns ??
|
|
95
96
|
inferColumns(options.data, options.getColumnHeader, options.autoColumnHeaderMode), options.defaultColumnDef), options.wrapText),
|
|
96
97
|
viewport: { width: 0, height: 0, scrollTop: 0, scrollLeft: 0 },
|
|
97
|
-
rowHeight: options.rowHeight ?? 32,
|
|
98
|
+
rowHeight: options.rowHeight ?? Math.round(32 * scale),
|
|
99
|
+
scale,
|
|
98
100
|
groupBy: [],
|
|
99
101
|
expandedGroups: {},
|
|
100
102
|
groupColumnMode: "single",
|
|
@@ -528,11 +530,14 @@ export class Grid {
|
|
|
528
530
|
// optimization for DOM Pool operation with large row counts.
|
|
529
531
|
if (this.processedDataCache !== null)
|
|
530
532
|
return this.processedDataCache;
|
|
533
|
+
performance.mark("omnigrid.processedData.start");
|
|
531
534
|
const state = this.getState();
|
|
532
535
|
const filtered = this.getFilteredData();
|
|
533
536
|
const legacyProcessed = [...this.dataProcessors].reduce((data, processor) => processor(data), filtered);
|
|
534
537
|
const result = this.pipeline.process(legacyProcessed, state);
|
|
535
538
|
this.processedDataCache = result;
|
|
539
|
+
performance.mark("omnigrid.processedData.end");
|
|
540
|
+
performance.measure("OmniGrid getProcessedData pipeline", "omnigrid.processedData.start", "omnigrid.processedData.end");
|
|
536
541
|
return result;
|
|
537
542
|
}
|
|
538
543
|
/**
|
|
@@ -926,6 +931,38 @@ export class Grid {
|
|
|
926
931
|
this.revision += 1;
|
|
927
932
|
this.store.setState({}, { force: true });
|
|
928
933
|
}
|
|
934
|
+
/**
|
|
935
|
+
* Updates structural grid metrics at runtime (e.g. the base row height when
|
|
936
|
+
* a theme scales the whole grid). Recomputes the virtualizer geometry and
|
|
937
|
+
* notifies Store subscribers so the host re-renders with the new layout.
|
|
938
|
+
* @param metrics - Metrics to apply; omitted fields are left unchanged.
|
|
939
|
+
* @api
|
|
940
|
+
*/
|
|
941
|
+
setMetrics(metrics) {
|
|
942
|
+
this.assertActive();
|
|
943
|
+
const nextScale = metrics.scale;
|
|
944
|
+
const nextRowHeight = metrics.rowHeight;
|
|
945
|
+
let resolvedScale = nextScale;
|
|
946
|
+
let resolvedRowHeight = nextRowHeight;
|
|
947
|
+
if (nextScale !== undefined && Number.isFinite(nextScale) && nextScale > 0) {
|
|
948
|
+
resolvedScale = nextScale;
|
|
949
|
+
if (nextRowHeight === undefined) {
|
|
950
|
+
resolvedRowHeight = Math.round(32 * nextScale);
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
const state = this.getState();
|
|
954
|
+
const scaleChanged = resolvedScale !== undefined && resolvedScale !== state.scale;
|
|
955
|
+
const rowHeightChanged = resolvedRowHeight !== undefined && resolvedRowHeight !== state.rowHeight;
|
|
956
|
+
if (!scaleChanged && !rowHeightChanged)
|
|
957
|
+
return;
|
|
958
|
+
if (scaleChanged || rowHeightChanged) {
|
|
959
|
+
this.virtualizer.setBaseRowHeight(resolvedRowHeight ?? state.rowHeight);
|
|
960
|
+
}
|
|
961
|
+
this.store.setState({
|
|
962
|
+
...(resolvedScale !== undefined ? { scale: resolvedScale } : {}),
|
|
963
|
+
...(resolvedRowHeight !== undefined ? { rowHeight: resolvedRowHeight } : {}),
|
|
964
|
+
});
|
|
965
|
+
}
|
|
929
966
|
/**
|
|
930
967
|
* Returns the absolute vertical offset (px) of the top of a row,
|
|
931
968
|
* accounting for variable heights. Falls back to `index * rowHeight`
|
|
@@ -1426,12 +1463,21 @@ export class Grid {
|
|
|
1426
1463
|
if (this.overlayManual)
|
|
1427
1464
|
return;
|
|
1428
1465
|
const state = this.store.getState();
|
|
1429
|
-
const
|
|
1466
|
+
const loading = this.loading || !this.hasData;
|
|
1467
|
+
let processedData;
|
|
1468
|
+
if (!loading && this.loadError === undefined) {
|
|
1469
|
+
if (state.data.length === 0) {
|
|
1470
|
+
processedData = [];
|
|
1471
|
+
}
|
|
1472
|
+
else {
|
|
1473
|
+
processedData = this.getProcessedData();
|
|
1474
|
+
}
|
|
1475
|
+
}
|
|
1430
1476
|
const type = evaluateAutoOverlay({
|
|
1431
|
-
loading
|
|
1477
|
+
loading,
|
|
1432
1478
|
error: this.loadError,
|
|
1433
1479
|
rawData: state.data,
|
|
1434
|
-
processedData,
|
|
1480
|
+
processedData: processedData ?? [],
|
|
1435
1481
|
});
|
|
1436
1482
|
const next = type
|
|
1437
1483
|
? {
|
package/dist/icons.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SlotNodeContent } from "./types.js";
|
|
2
|
-
export type IconName = "chevron-left" | "chevron-right" | "chevron-up" | "chevron-down" | "chevron-first" | "chevron-last" | "arrow-up" | "arrow-down" | "arrow-up-down" | "filter" | "search";
|
|
2
|
+
export type IconName = "chevron-left" | "chevron-right" | "chevron-up" | "chevron-down" | "chevron-first" | "chevron-last" | "arrow-up" | "arrow-down" | "arrow-up-down" | "filter" | "search" | "calendar";
|
|
3
3
|
export type IconDefinition<T> = SlotNodeContent<T> | (() => SlotNodeContent<T>);
|
|
4
4
|
/** Framework-agnostic registry of declarative SVG slot nodes. */
|
|
5
5
|
export declare class IconRegistry<T> {
|
package/dist/icons.js
CHANGED
|
@@ -30,6 +30,12 @@ const DEFAULT_ICON_PATHS = {
|
|
|
30
30
|
{ tag: "circle", attrs: { cx: "11", cy: "11", r: "8" } },
|
|
31
31
|
{ tag: "path", attrs: { d: "m21 21-4.3-4.3" } },
|
|
32
32
|
],
|
|
33
|
+
"calendar": [
|
|
34
|
+
{ tag: "rect", attrs: { x: "3", y: "4", width: "18", height: "18", rx: "2", ry: "2" } },
|
|
35
|
+
{ tag: "line", attrs: { x1: "16", y1: "2", x2: "16", y2: "6" } },
|
|
36
|
+
{ tag: "line", attrs: { x1: "8", y1: "2", x2: "8", y2: "6" } },
|
|
37
|
+
{ tag: "line", attrs: { x1: "3", y1: "10", x2: "21", y2: "10" } },
|
|
38
|
+
],
|
|
33
39
|
};
|
|
34
40
|
function createSvgIcon(name, paths) {
|
|
35
41
|
return {
|
package/dist/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export { DataPipeline, PIPELINE_STAGE_ORDER } from "./pipeline.js";
|
|
|
12
12
|
export type { PipelineProcessor, PipelineStage } from "./pipeline.js";
|
|
13
13
|
export { applyFilterModel, applyQuickFilter, isActiveCondition, isFilterModelActive, matchesColumnFilter, } from "./filtering.js";
|
|
14
14
|
export type { ColumnFilterModel, FilterCondition, FilterModel, FilterOperator } from "./filtering.js";
|
|
15
|
-
export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIInputControl, UIPopupAnchor, UIPopupDescriptor, UISelectControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui.js";
|
|
15
|
+
export type { UIButtonControl, UICheckboxDescriptor, UIControlBase, UIControlDescriptor, UIGroupControl, UIIconControl, UIInputBase, UIInputControl, UIDateInputControl, UIDateLocaleStrings, UINumberInputControl, UITextInputControl, UIPopupAnchor, UIPopupDescriptor, UIRadioControl, UIRadioOption, UISelectControl, UISeparatorControl, UISelectOption, UITextBlockControl, UIMultiSelectControl, UIMultiSelectOption, } from "./ui.js";
|
|
16
16
|
export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays.js";
|
|
17
|
-
export type { BlockConfig, CellAlign, AggregationFunc, AutoColumnHeaderMode, ColumnHeaderExtension, ColumnHeaderExtensionPosition, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnDropPosition, DefaultColumnDef, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DataRowNode, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GroupRowNode, GroupRowRenderParams, GroupRowRenderer, CoreGridApi, CoreGridState, GridStateUpdateOptions, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PluginApiExtensions, PluginStateExtensions, ResolvedAggregationFunc, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowHierarchy, RowHierarchyScope, RowGroupContext, RowGroupContextChild, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, TreeRowNode, ViewportData, ViewportState, VirtualItem, } from "./types.js";
|
|
17
|
+
export type { BlockConfig, CellAlign, AggregationFunc, AutoColumnHeaderMode, ColumnHeaderExtension, ColumnHeaderExtensionPosition, CellRenderParams, CellClassRules, CellSpan, CellSpanningParams, CheckboxControl, CheckboxRenderParams, ColSpanDef, ColumnClassRules, ColumnDataType, ColumnDropPosition, DefaultColumnDef, ColumnFilterType, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, ColumnStyle, ColumnStyleParams, DataProcessor, DataRowNode, DomPoolBindings, DomPoolUpdate, DomPoolUpdateOptions, GroupRowNode, GroupRowRenderParams, GroupRowRenderer, CoreGridApi, CoreGridState, GridStateUpdateOptions, GridApi, GridEvents, GridMetrics, GridOptions, GridPlugin, GridState, PluginApiExtensions, PluginStateExtensions, ResolvedAggregationFunc, HeaderClassRules, HeaderGroupClassRules, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHeightUpdateOptions, RowHost, RowHoverEvent, RowId, RowHierarchy, RowHierarchyScope, RowGroupContext, RowGroupContextChild, RowNode, RowRenderParams, RowSpanLayout, RowStyle, RowTransaction, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, TransactionResult, TreeRowNode, ViewportData, ViewportState, VirtualItem, } from "./types.js";
|
|
18
18
|
export { applyDefaultColumnDef, getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf, getCellValue, getCellSpanningParams, resolveColSpan, getRowSpans, inferColumns, } from "./columns.js";
|
|
19
19
|
export { Virtualizer, RowHeightRegistry } from "./virtualizer.js";
|
package/dist/types.d.ts
CHANGED
|
@@ -613,6 +613,31 @@ export interface RowHeightUpdateOptions {
|
|
|
613
613
|
*/
|
|
614
614
|
notify?: boolean;
|
|
615
615
|
}
|
|
616
|
+
/**
|
|
617
|
+
* Structural grid metrics that can be updated at runtime.
|
|
618
|
+
*
|
|
619
|
+
* These drive both the virtualizer geometry (row height, total scroll height)
|
|
620
|
+
* and the rendered layout, so a single update keeps the scroll math and the
|
|
621
|
+
* DOM in sync — e.g. when a theme scales the whole grid proportionally.
|
|
622
|
+
*
|
|
623
|
+
* @api
|
|
624
|
+
*/
|
|
625
|
+
export interface GridMetrics {
|
|
626
|
+
/**
|
|
627
|
+
* Base row height (px) for fixed-height grids. Scaled/derived values
|
|
628
|
+
* (font size, paddings) live in CSS via `--omnigrid-scale`; this is the
|
|
629
|
+
* single source of truth the virtualizer uses for row geometry.
|
|
630
|
+
*/
|
|
631
|
+
rowHeight?: number;
|
|
632
|
+
/**
|
|
633
|
+
* Theme scale coefficient (1 = 100%). Core stores it and derives
|
|
634
|
+
* `rowHeight = Math.round(baseRowHeight * scale)` so the virtualizer
|
|
635
|
+
* geometry and the CSS tokens stay consistent. Each grid instance owns
|
|
636
|
+
* its own scale — it does not leak to other grids on the page.
|
|
637
|
+
* @default 1
|
|
638
|
+
*/
|
|
639
|
+
scale?: number;
|
|
640
|
+
}
|
|
616
641
|
/**
|
|
617
642
|
* Built-in formatting modes for headers inferred from row fields.
|
|
618
643
|
* @api
|
|
@@ -648,6 +673,14 @@ export interface GridOptions<T> {
|
|
|
648
673
|
/** Returns a stable row ID; defaults to the row's current index. Use a stable ID to preserve row identity when rows are reordered. */
|
|
649
674
|
getRowId?: (row: T, index: number) => RowId;
|
|
650
675
|
rowHeight?: number;
|
|
676
|
+
/**
|
|
677
|
+
* Theme scale coefficient applied to the base row height (`rowHeight =
|
|
678
|
+
* Math.round(baseRowHeight * scale)`). `1` means 100%. Each grid instance
|
|
679
|
+
* owns its own scale — it does not leak to other grids on the page.
|
|
680
|
+
* @default 1
|
|
681
|
+
* @api
|
|
682
|
+
*/
|
|
683
|
+
scale?: number;
|
|
651
684
|
/** Enables automatic text wrapping for all cells. @default false @api */
|
|
652
685
|
wrapText?: boolean;
|
|
653
686
|
/**
|
|
@@ -893,6 +926,8 @@ export interface CoreGridState<T> {
|
|
|
893
926
|
columns: ColumnDef<T>[];
|
|
894
927
|
viewport: ViewportState;
|
|
895
928
|
rowHeight: number;
|
|
929
|
+
/** Theme scale coefficient (1 = 100%). Drives rowHeight geometry. */
|
|
930
|
+
scale: number;
|
|
896
931
|
rowOverscan: number;
|
|
897
932
|
columnOverscan: number;
|
|
898
933
|
/** Cells currently flashed, keyed by `${rowId}:${columnId}` → expiry timestamp. */
|
|
@@ -1401,6 +1436,14 @@ export interface CoreGridApi<T> {
|
|
|
1401
1436
|
* @api
|
|
1402
1437
|
*/
|
|
1403
1438
|
setRowHeight(rowIndex: number, height: number, options?: RowHeightUpdateOptions): number;
|
|
1439
|
+
/**
|
|
1440
|
+
* Updates structural grid metrics at runtime (e.g. the base row height when
|
|
1441
|
+
* a theme scales the grid). Recomputes the virtualizer geometry and notifies
|
|
1442
|
+
* Store subscribers so the host re-renders with the new layout.
|
|
1443
|
+
* @param metrics - Metrics to apply; omitted fields are left unchanged.
|
|
1444
|
+
* @api
|
|
1445
|
+
*/
|
|
1446
|
+
setMetrics(metrics: GridMetrics): void;
|
|
1404
1447
|
/**
|
|
1405
1448
|
* Removes a measured row height (e.g. when row content collapses back to
|
|
1406
1449
|
* the estimate). Returns the scrollTop correction like `setRowHeight`.
|
package/dist/ui.d.ts
CHANGED
|
@@ -36,9 +36,8 @@ export interface UIControlBase {
|
|
|
36
36
|
/** Extra CSS class names. */
|
|
37
37
|
className?: string;
|
|
38
38
|
}
|
|
39
|
-
/**
|
|
40
|
-
export interface
|
|
41
|
-
type: "text" | "number" | "date";
|
|
39
|
+
/** Properties shared by all input controls. @api */
|
|
40
|
+
export interface UIInputBase extends UIControlBase {
|
|
42
41
|
/** Current value. */
|
|
43
42
|
value: string;
|
|
44
43
|
/** Placeholder text. */
|
|
@@ -50,6 +49,47 @@ export interface UIInputControl extends UIControlBase {
|
|
|
50
49
|
/** Called when the user presses Enter while the input is focused. */
|
|
51
50
|
onEnter?: () => void;
|
|
52
51
|
}
|
|
52
|
+
/** Single-line text input. @api */
|
|
53
|
+
export interface UITextInputControl extends UIInputBase {
|
|
54
|
+
type: "text";
|
|
55
|
+
/** Maximum number of characters. */
|
|
56
|
+
maxLength?: number;
|
|
57
|
+
}
|
|
58
|
+
/** Numeric input. @api */
|
|
59
|
+
export interface UINumberInputControl extends UIInputBase {
|
|
60
|
+
type: "number";
|
|
61
|
+
/** Minimum allowed value. */
|
|
62
|
+
min?: number;
|
|
63
|
+
/** Maximum allowed value. */
|
|
64
|
+
max?: number;
|
|
65
|
+
/** Step increment. */
|
|
66
|
+
step?: number;
|
|
67
|
+
}
|
|
68
|
+
/** Localized strings for a date input. @api */
|
|
69
|
+
export interface UIDateLocaleStrings {
|
|
70
|
+
/** Month names (12). */
|
|
71
|
+
months?: readonly string[];
|
|
72
|
+
/** Short weekday names (7). */
|
|
73
|
+
weekdaysShort?: readonly string[];
|
|
74
|
+
/** Label for "today". */
|
|
75
|
+
todayLabel?: string;
|
|
76
|
+
/** Label for "clear". */
|
|
77
|
+
clearLabel?: string;
|
|
78
|
+
}
|
|
79
|
+
/** Date input. @api */
|
|
80
|
+
export interface UIDateInputControl extends UIInputBase {
|
|
81
|
+
type: "date";
|
|
82
|
+
/** Minimum selectable date (ISO `YYYY-MM-DD`). */
|
|
83
|
+
minDate?: string;
|
|
84
|
+
/** Maximum selectable date (ISO `YYYY-MM-DD`). */
|
|
85
|
+
maxDate?: string;
|
|
86
|
+
/** Display format. */
|
|
87
|
+
dateFormat?: string;
|
|
88
|
+
/** Per-control locale override. */
|
|
89
|
+
locale?: UIDateLocaleStrings;
|
|
90
|
+
}
|
|
91
|
+
/** Single-line text, number or date input. @api */
|
|
92
|
+
export type UIInputControl = UITextInputControl | UINumberInputControl | UIDateInputControl;
|
|
53
93
|
/** Drop-down select. @api */
|
|
54
94
|
export interface UISelectControl extends UIControlBase {
|
|
55
95
|
type: "select";
|
|
@@ -68,13 +108,36 @@ export interface UICheckboxDescriptor extends UIControlBase {
|
|
|
68
108
|
/** Called with the new checked state. */
|
|
69
109
|
onChange: (checked: boolean) => void;
|
|
70
110
|
}
|
|
111
|
+
/** Radio option. @api */
|
|
112
|
+
export interface UIRadioOption {
|
|
113
|
+
/** Value of the item. */
|
|
114
|
+
value: string;
|
|
115
|
+
/** Human-readable label. */
|
|
116
|
+
label: string;
|
|
117
|
+
}
|
|
118
|
+
/** Radio button group. @api */
|
|
119
|
+
export interface UIRadioControl extends UIControlBase {
|
|
120
|
+
type: "radio";
|
|
121
|
+
/** Layout direction of the options. @default "row" */
|
|
122
|
+
direction?: "row" | "column";
|
|
123
|
+
/** Available options. */
|
|
124
|
+
options: UIRadioOption[];
|
|
125
|
+
/** Currently selected value. */
|
|
126
|
+
value: string;
|
|
127
|
+
/** Called with the newly selected value. */
|
|
128
|
+
onChange: (value: string) => void;
|
|
129
|
+
}
|
|
71
130
|
/** Push button. @api */
|
|
72
131
|
export interface UIButtonControl extends UIControlBase {
|
|
73
132
|
type: "button";
|
|
74
133
|
/** Button caption. */
|
|
75
|
-
text
|
|
134
|
+
text?: string;
|
|
135
|
+
/** Icon name rendered inside the button. */
|
|
136
|
+
icon?: string;
|
|
76
137
|
/** Visual emphasis. @default "secondary" */
|
|
77
|
-
variant?: "primary" | "secondary";
|
|
138
|
+
variant?: "primary" | "secondary" | "ghost";
|
|
139
|
+
/** CSS width; when omitted the button stretches to full parent width. */
|
|
140
|
+
width?: string;
|
|
78
141
|
/** Called when the button is clicked. */
|
|
79
142
|
onClick: () => void;
|
|
80
143
|
}
|
|
@@ -106,13 +169,27 @@ export interface UIMultiSelectControl extends UIControlBase {
|
|
|
106
169
|
/** Container laying out child controls. @api */
|
|
107
170
|
export interface UIGroupControl extends UIControlBase {
|
|
108
171
|
type: "group";
|
|
109
|
-
/** Layout direction. @default "
|
|
172
|
+
/** Layout direction. @default "row" */
|
|
110
173
|
direction?: "row" | "column";
|
|
174
|
+
/** Gap between child controls. @default "var(--omnigrid-control-gap, 8px)" */
|
|
175
|
+
gap?: string;
|
|
111
176
|
/** Nested controls. */
|
|
112
177
|
children: UIControlDescriptor[];
|
|
113
178
|
}
|
|
179
|
+
/** Renders a monochrome icon resolved through the grid's icon registry. @api */
|
|
180
|
+
export interface UIIconControl extends UIControlBase {
|
|
181
|
+
type: "icon";
|
|
182
|
+
/** Icon name resolved through {@link GridApi.icons}. */
|
|
183
|
+
name: string;
|
|
184
|
+
}
|
|
185
|
+
/** Visual separator. @api */
|
|
186
|
+
export interface UISeparatorControl extends UIControlBase {
|
|
187
|
+
type: "separator";
|
|
188
|
+
/** Orientation. @default "horizontal" */
|
|
189
|
+
orientation?: "horizontal" | "vertical";
|
|
190
|
+
}
|
|
114
191
|
/** Any declarative control. @api */
|
|
115
|
-
export type UIControlDescriptor = UIInputControl | UISelectControl | UICheckboxDescriptor | UIButtonControl | UITextBlockControl | UIMultiSelectControl | UIGroupControl;
|
|
192
|
+
export type UIControlDescriptor = UIInputControl | UISelectControl | UICheckboxDescriptor | UIRadioControl | UIButtonControl | UITextBlockControl | UIMultiSelectControl | UIGroupControl | UIIconControl | UISeparatorControl;
|
|
116
193
|
/** Viewport-relative anchor rectangle (CSS pixels) a popup is positioned against. @api */
|
|
117
194
|
export interface UIPopupAnchor {
|
|
118
195
|
x: number;
|
package/dist/virtualizer.d.ts
CHANGED
|
@@ -104,6 +104,12 @@ export declare class Virtualizer<T> {
|
|
|
104
104
|
constructor(options: VirtualizerOptions);
|
|
105
105
|
/** Dynamic height registry backing variable-height mode. @api */
|
|
106
106
|
get rowHeights(): RowHeightRegistry;
|
|
107
|
+
/**
|
|
108
|
+
* Updates the base row height used for fixed-height grids and invalidates
|
|
109
|
+
* the memoized row range (its cache key does not include the row height).
|
|
110
|
+
* @api
|
|
111
|
+
*/
|
|
112
|
+
setBaseRowHeight(height: number): void;
|
|
107
113
|
/** Estimated height used for rows without a measurement. @api */
|
|
108
114
|
get estimatedRowHeight(): number;
|
|
109
115
|
/** Whether any variable-height input exists (resolver counts or measured heights exist). @api */
|
package/dist/virtualizer.js
CHANGED
|
@@ -248,6 +248,21 @@ export class Virtualizer {
|
|
|
248
248
|
get rowHeights() {
|
|
249
249
|
return this.heights;
|
|
250
250
|
}
|
|
251
|
+
/**
|
|
252
|
+
* Updates the base row height used for fixed-height grids and invalidates
|
|
253
|
+
* the memoized row range (its cache key does not include the row height).
|
|
254
|
+
* @api
|
|
255
|
+
*/
|
|
256
|
+
setBaseRowHeight(height) {
|
|
257
|
+
if (!Number.isFinite(height) || height <= 0)
|
|
258
|
+
return;
|
|
259
|
+
const rounded = Math.round(height);
|
|
260
|
+
if (this.options.rowHeight === rounded)
|
|
261
|
+
return;
|
|
262
|
+
this.options.rowHeight = rounded;
|
|
263
|
+
this.lastScrollTop = null;
|
|
264
|
+
this.lastRowRange = null;
|
|
265
|
+
}
|
|
251
266
|
/** Estimated height used for rows without a measurement. @api */
|
|
252
267
|
get estimatedRowHeight() {
|
|
253
268
|
return this.options.estimatedRowHeight ?? this.options.rowHeight;
|
package/package.json
CHANGED
|
@@ -1,44 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@omnigrid/core",
|
|
3
|
-
"version": "0.1.
|
|
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
|
-
"
|
|
43
|
-
|
|
44
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@omnigrid/core",
|
|
3
|
+
"version": "0.1.39",
|
|
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
|
+
}
|