@omnigrid/core 0.1.9 → 0.1.11
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 +235 -231
- package/dist/grid.d.ts +1 -3
- package/dist/grid.js +8 -4
- package/dist/overlays.d.ts +2 -2
- package/dist/types.d.ts +2 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,231 +1,235 @@
|
|
|
1
|
-
# @omnigrid/core
|
|
2
|
-
|
|
3
|
-
Framework-agnostic core engine for OmniGrid — a fast, headless, extensible data grid.
|
|
4
|
-
Pure TypeScript, zero runtime dependencies, **no DOM, no framework imports**. The core owns data,
|
|
5
|
-
state, the data pipeline, 2D virtualization, DOM-pool row mapping, slots, and plugins; an adapter
|
|
6
|
-
(the React adapter in `@omnigrid/react`) renders it into a UI.
|
|
7
|
-
|
|
8
|
-
## What it provides
|
|
9
|
-
|
|
10
|
-
- **`Grid`** — entry point (`new Grid<T>(options)`), implements `GridApi<T>`.
|
|
11
|
-
- **State Store** — observable `GridState<T>`; structural changes notify subscribers and emit `stateChange`.
|
|
12
|
-
- **Data Pipeline** — plugins attach pure transforms (`T[] → T[]`) in registration order: raw → processed → virtualized.
|
|
13
|
-
- **Virtualization Engine (2D)** — visible window of rows *and* columns plus overscan; offsets are absolute table-space coordinates.
|
|
14
|
-
- **Event Bus** — typed `on(event, listener)`; returns an unsubscribe function.
|
|
15
|
-
- **DOM Pool mapping** — the core decides *which* rows are visible; the adapter performs DOM ops via injected `DomPoolBindings`.
|
|
16
|
-
- **Slot Manager / `GridApi.slots`** — headless widgets mounted by plugins into `top | bottom | left | right`.
|
|
17
|
-
- **Icon Registry** — framework-agnostic declarative SVG icons for plugin UI (`api.icons.get(name)`).
|
|
18
|
-
|
|
19
|
-
**Scroll is ephemeral, not state.** `scrollTop`/`scrollLeft` are kept out of the Store:
|
|
20
|
-
scroll-only `setViewport({ scrollTop, scrollLeft })` calls never notify subscribers, so adapters do
|
|
21
|
-
not re-render on scroll frames. Read them via `getScrollPosition()`.
|
|
22
|
-
|
|
23
|
-
## Key contracts
|
|
24
|
-
|
|
25
|
-
### `GridOptions<T>`
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
interface GridOptions<T> {
|
|
29
|
-
data?: T[] | null; // row data; null/omitted means initial loading
|
|
30
|
-
columns: ColumnDef<T>[]; // required
|
|
31
|
-
getRowId?: (row: T, index: number) => RowId; // default: index-based
|
|
32
|
-
rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
|
|
33
|
-
rowOverscan?: number; // extra rows above/below viewport; default 5
|
|
34
|
-
columnOverscan?: number; // extra columns beyond horizontal window; default 2
|
|
35
|
-
suppressRowHoverHighlight?: boolean;
|
|
36
|
-
rowStyle?: RowStyle;
|
|
37
|
-
getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
|
|
38
|
-
rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
|
|
39
|
-
getRowClass?: (params: RowRenderParams<T>) => string | undefined;
|
|
40
|
-
rowClassRules?: RowClassRules<T>; // class name → predicate
|
|
41
|
-
plugins?: GridPlugin<T>[]; // plugin instances registered at construction
|
|
42
|
-
loading?: boolean; // active fetch; shows loading even with prior rows
|
|
43
|
-
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
44
|
-
}
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
### `ColumnDef<T>`
|
|
48
|
-
|
|
49
|
-
`ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
|
|
50
|
-
|
|
51
|
-
```ts
|
|
52
|
-
interface ColumnLeafDef<T> {
|
|
53
|
-
id: string; // unique column id (also stable slot key)
|
|
54
|
-
header: string;
|
|
55
|
-
field?: keyof T | string; // value accessor (default cell value source)
|
|
56
|
-
valueGetter?: (row: T) => unknown; // overrides field
|
|
57
|
-
valueFormatter?: (value: unknown) => string;
|
|
58
|
-
width?: number; // fixed px width
|
|
59
|
-
flex?: number; // flex weight; expands to fill remaining space
|
|
60
|
-
minWidth?: number;
|
|
61
|
-
maxWidth?: number;
|
|
62
|
-
hidden?: boolean;
|
|
63
|
-
pinned?: "left" | "right"; // fixed column in horizontal viewport
|
|
64
|
-
sortable?: boolean; // read by SortingPlugin
|
|
65
|
-
sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
|
|
66
|
-
sortIndex?: number; // runtime 1-based priority when multi-sorted
|
|
67
|
-
align?: "left" | "center" | "right";
|
|
68
|
-
cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
|
|
69
|
-
cellStyle?: RowStyle;
|
|
70
|
-
getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
|
|
71
|
-
cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
|
|
72
|
-
getCellClass?: (params: CellRenderParams<T>) => string | undefined;
|
|
73
|
-
cellClassRules?: CellClassRules<T>;
|
|
74
|
-
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
75
|
-
stopRowClick?: boolean;
|
|
76
|
-
stopHeaderClick?: boolean;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
interface ColumnGroupDef<T> {
|
|
80
|
-
id: string;
|
|
81
|
-
header: string;
|
|
82
|
-
children: ColumnDef<T>[]; // nested leaves / groups
|
|
83
|
-
pinned?: "left" | "right";
|
|
84
|
-
collapsible?: boolean;
|
|
85
|
-
defaultExpanded?: boolean;
|
|
86
|
-
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
87
|
-
}
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
### `GridApi<T>`
|
|
91
|
-
|
|
92
|
-
`Grid<T>` implements this interface — the single public surface for adapters and plugins.
|
|
93
|
-
UI code must never touch core internals directly.
|
|
94
|
-
|
|
95
|
-
```ts
|
|
96
|
-
interface GridApi<T> {
|
|
97
|
-
getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
|
|
98
|
-
getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
|
|
99
|
-
getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
|
|
100
|
-
getProcessedData(): T[]; // after all registered data processors
|
|
101
|
-
getRowId(row: T, index: number): RowId;
|
|
102
|
-
setData(data: T[] | null | undefined): void;
|
|
103
|
-
setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
|
|
104
|
-
refresh(): void; // repaint hints (rowClassRules), bumps revision
|
|
105
|
-
subscribe(listener: () => void): () => void;
|
|
106
|
-
on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
|
|
107
|
-
registerPlugin(plugin: GridPlugin<T>): () => void;
|
|
108
|
-
registerDataProcessor(processor: DataProcessor<T>): () => void;
|
|
109
|
-
setColumns(columns: ColumnDef<T>[]): void;
|
|
110
|
-
headerClick(columnId: string, multiSort?: boolean): void;
|
|
111
|
-
rowClick(row: RowClickEvent<T>): void;
|
|
112
|
-
rowHover(row: RowHoverEvent<T>): void;
|
|
113
|
-
readonly slots: SlotManager<T>; // mount headless widgets
|
|
114
|
-
readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
|
|
115
|
-
getSlotMounts(slot: SlotName): SlotMount<T>[];
|
|
116
|
-
showOverlay(options: OverlayOptions): void;
|
|
117
|
-
hideOverlay(): void;
|
|
118
|
-
getOverlayState(): OverlayState;
|
|
119
|
-
setLoading(isLoading: boolean, error?: unknown): void;
|
|
120
|
-
getRevision(): number; // monotonic counter for structural changes
|
|
121
|
-
destroy(): void;
|
|
122
|
-
isDestroyed(): boolean;
|
|
123
|
-
}
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Overlays
|
|
127
|
-
|
|
128
|
-
Overlays are managed in core state, so state transitions notify subscribers only when the
|
|
129
|
-
overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
|
|
130
|
-
loading; an explicit empty array shows the no-rows state. Empty processed results with source
|
|
131
|
-
rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
|
|
132
|
-
through `setLoading(false, error)`; a successful `setData` clears the error.
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
grid.showOverlay({
|
|
136
|
-
type: "error",
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
message: "Could not load records",
|
|
140
|
-
});
|
|
141
|
-
grid.hideOverlay(); // restores automatic loading / empty-state evaluation
|
|
142
|
-
const overlay = grid.getOverlayState();
|
|
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
|
-
const
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
grid
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
1
|
+
# @omnigrid/core
|
|
2
|
+
|
|
3
|
+
Framework-agnostic core engine for OmniGrid — a fast, headless, extensible data grid.
|
|
4
|
+
Pure TypeScript, zero runtime dependencies, **no DOM, no framework imports**. The core owns data,
|
|
5
|
+
state, the data pipeline, 2D virtualization, DOM-pool row mapping, slots, and plugins; an adapter
|
|
6
|
+
(the React adapter in `@omnigrid/react`) renders it into a UI.
|
|
7
|
+
|
|
8
|
+
## What it provides
|
|
9
|
+
|
|
10
|
+
- **`Grid`** — entry point (`new Grid<T>(options)`), implements `GridApi<T>`.
|
|
11
|
+
- **State Store** — observable `GridState<T>`; structural changes notify subscribers and emit `stateChange`.
|
|
12
|
+
- **Data Pipeline** — plugins attach pure transforms (`T[] → T[]`) in registration order: raw → processed → virtualized.
|
|
13
|
+
- **Virtualization Engine (2D)** — visible window of rows *and* columns plus overscan; offsets are absolute table-space coordinates.
|
|
14
|
+
- **Event Bus** — typed `on(event, listener)`; returns an unsubscribe function.
|
|
15
|
+
- **DOM Pool mapping** — the core decides *which* rows are visible; the adapter performs DOM ops via injected `DomPoolBindings`.
|
|
16
|
+
- **Slot Manager / `GridApi.slots`** — headless widgets mounted by plugins into `top | bottom | left | right`.
|
|
17
|
+
- **Icon Registry** — framework-agnostic declarative SVG icons for plugin UI (`api.icons.get(name)`).
|
|
18
|
+
|
|
19
|
+
**Scroll is ephemeral, not state.** `scrollTop`/`scrollLeft` are kept out of the Store:
|
|
20
|
+
scroll-only `setViewport({ scrollTop, scrollLeft })` calls never notify subscribers, so adapters do
|
|
21
|
+
not re-render on scroll frames. Read them via `getScrollPosition()`.
|
|
22
|
+
|
|
23
|
+
## Key contracts
|
|
24
|
+
|
|
25
|
+
### `GridOptions<T>`
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
interface GridOptions<T> {
|
|
29
|
+
data?: T[] | null; // row data; null/omitted means initial loading
|
|
30
|
+
columns: ColumnDef<T>[]; // required
|
|
31
|
+
getRowId?: (row: T, index: number) => RowId; // default: index-based
|
|
32
|
+
rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
|
|
33
|
+
rowOverscan?: number; // extra rows above/below viewport; default 5
|
|
34
|
+
columnOverscan?: number; // extra columns beyond horizontal window; default 2
|
|
35
|
+
suppressRowHoverHighlight?: boolean;
|
|
36
|
+
rowStyle?: RowStyle;
|
|
37
|
+
getRowStyle?: (params: RowRenderParams<T>) => RowStyle | undefined;
|
|
38
|
+
rowClass?: string | ((params: RowRenderParams<T>) => string | undefined);
|
|
39
|
+
getRowClass?: (params: RowRenderParams<T>) => string | undefined;
|
|
40
|
+
rowClassRules?: RowClassRules<T>; // class name → predicate
|
|
41
|
+
plugins?: GridPlugin<T>[]; // plugin instances registered at construction
|
|
42
|
+
loading?: boolean; // active fetch; shows loading even with prior rows
|
|
43
|
+
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### `ColumnDef<T>`
|
|
48
|
+
|
|
49
|
+
`ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>`. Groups nest via `children`; width/visibility/pinning can be combined freely.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
interface ColumnLeafDef<T> {
|
|
53
|
+
id: string; // unique column id (also stable slot key)
|
|
54
|
+
header: string;
|
|
55
|
+
field?: keyof T | string; // value accessor (default cell value source)
|
|
56
|
+
valueGetter?: (row: T) => unknown; // overrides field
|
|
57
|
+
valueFormatter?: (value: unknown) => string;
|
|
58
|
+
width?: number; // fixed px width
|
|
59
|
+
flex?: number; // flex weight; expands to fill remaining space
|
|
60
|
+
minWidth?: number;
|
|
61
|
+
maxWidth?: number;
|
|
62
|
+
hidden?: boolean;
|
|
63
|
+
pinned?: "left" | "right"; // fixed column in horizontal viewport
|
|
64
|
+
sortable?: boolean; // read by SortingPlugin
|
|
65
|
+
sortState?: SortDirection; // "asc" | "desc" — initial sort for SortingPlugin
|
|
66
|
+
sortIndex?: number; // runtime 1-based priority when multi-sorted
|
|
67
|
+
align?: "left" | "center" | "right";
|
|
68
|
+
cellRenderer?: (params: CellRenderParams<T>) => unknown; // opaque content, adapter materializes
|
|
69
|
+
cellStyle?: RowStyle;
|
|
70
|
+
getCellStyle?: (params: CellRenderParams<T>) => RowStyle | undefined;
|
|
71
|
+
cellClass?: string | ((params: CellRenderParams<T>) => string | undefined);
|
|
72
|
+
getCellClass?: (params: CellRenderParams<T>) => string | undefined;
|
|
73
|
+
cellClassRules?: CellClassRules<T>;
|
|
74
|
+
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
75
|
+
stopRowClick?: boolean;
|
|
76
|
+
stopHeaderClick?: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
interface ColumnGroupDef<T> {
|
|
80
|
+
id: string;
|
|
81
|
+
header: string;
|
|
82
|
+
children: ColumnDef<T>[]; // nested leaves / groups
|
|
83
|
+
pinned?: "left" | "right";
|
|
84
|
+
collapsible?: boolean;
|
|
85
|
+
defaultExpanded?: boolean;
|
|
86
|
+
headerRenderer?: (column: ColumnDef<T>) => unknown;
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### `GridApi<T>`
|
|
91
|
+
|
|
92
|
+
`Grid<T>` implements this interface — the single public surface for adapters and plugins.
|
|
93
|
+
UI code must never touch core internals directly.
|
|
94
|
+
|
|
95
|
+
```ts
|
|
96
|
+
interface GridApi<T> {
|
|
97
|
+
getState(): GridState<T>; // { data, columns, viewport, rowHeight, rowOverscan, columnOverscan }
|
|
98
|
+
getScrollPosition(): ScrollPosition; // ephemeral scrollTop/scrollLeft
|
|
99
|
+
getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
|
|
100
|
+
getProcessedData(): T[]; // after all registered data processors
|
|
101
|
+
getRowId(row: T, index: number): RowId;
|
|
102
|
+
setData(data: T[] | null | undefined): void;
|
|
103
|
+
setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
|
|
104
|
+
refresh(): void; // repaint hints (rowClassRules), bumps revision
|
|
105
|
+
subscribe(listener: () => void): () => void;
|
|
106
|
+
on<E extends keyof GridEvents<T>>(event: E, listener: (p: GridEvents<T>[E]) => void): () => void;
|
|
107
|
+
registerPlugin(plugin: GridPlugin<T>): () => void;
|
|
108
|
+
registerDataProcessor(processor: DataProcessor<T>): () => void;
|
|
109
|
+
setColumns(columns: ColumnDef<T>[]): void;
|
|
110
|
+
headerClick(columnId: string, multiSort?: boolean): void;
|
|
111
|
+
rowClick(row: RowClickEvent<T>): void;
|
|
112
|
+
rowHover(row: RowHoverEvent<T>): void;
|
|
113
|
+
readonly slots: SlotManager<T>; // mount headless widgets
|
|
114
|
+
readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
|
|
115
|
+
getSlotMounts(slot: SlotName): SlotMount<T>[];
|
|
116
|
+
showOverlay(options: OverlayOptions): void;
|
|
117
|
+
hideOverlay(): void;
|
|
118
|
+
getOverlayState(): OverlayState;
|
|
119
|
+
setLoading(isLoading: boolean, error?: unknown): void;
|
|
120
|
+
getRevision(): number; // monotonic counter for structural changes
|
|
121
|
+
destroy(): void;
|
|
122
|
+
isDestroyed(): boolean;
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Overlays
|
|
127
|
+
|
|
128
|
+
Overlays are managed in core state, so state transitions notify subscribers only when the
|
|
129
|
+
overlay changes (scroll position stays ephemeral). Initial `data: null` or omitted data shows
|
|
130
|
+
loading; an explicit empty array shows the no-rows state. Empty processed results with source
|
|
131
|
+
rows show no-matching-rows and leave horizontal column inspection enabled. Report fetch failures
|
|
132
|
+
through `setLoading(false, error)`; a successful `setData` clears the error.
|
|
133
|
+
|
|
134
|
+
```ts
|
|
135
|
+
grid.showOverlay({
|
|
136
|
+
type: "error",
|
|
137
|
+
// Errors default to "full"; other overlay types default to "bodyOnly".
|
|
138
|
+
// Set scope explicitly to choose a different placement.
|
|
139
|
+
message: "Could not load records",
|
|
140
|
+
});
|
|
141
|
+
grid.hideOverlay(); // restores automatic loading / empty-state evaluation
|
|
142
|
+
const overlay = grid.getOverlayState();
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Every active overlay locks vertical scrolling while preserving the scrollbar gutter when one
|
|
146
|
+
is present. Horizontal scrolling remains enabled by default and can be locked with
|
|
147
|
+
`blockScroll: true`.
|
|
148
|
+
|
|
149
|
+
`overlayComponents` accepts framework-specific components through the adapter or core render
|
|
150
|
+
callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
|
|
151
|
+
|
|
152
|
+
`GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
|
|
153
|
+
Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
|
|
154
|
+
|
|
155
|
+
### Plugin contract — `GridPlugin<T>`
|
|
156
|
+
|
|
157
|
+
```ts
|
|
158
|
+
interface GridPlugin<T> {
|
|
159
|
+
name: string; // unique, namespaced, e.g. "@omnigrid/sorting-plugin"
|
|
160
|
+
register(api: GridApi<T>): void | (() => void); // returns cleanup
|
|
161
|
+
getRowClass?(params: RowRenderParams<T>): string | undefined;
|
|
162
|
+
getRowStyle?(params: RowRenderParams<T>): RowStyle | undefined;
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
A plugin hooks the grid via `api.on(...)`, `api.registerDataProcessor(...)`, `api.slots.mount(...)`,
|
|
167
|
+
and `api.icons.register(...)`; it must return a cleanup function that tears down everything it created.
|
|
168
|
+
Plugin source must remain framework-agnostic (see [`AI_INSTRUCTIONS.md`](../AI_INSTRUCTIONS.md) and
|
|
169
|
+
[`core/AI_INSTRUCTIONS.md`](AI_INSTRUCTIONS.md) in this repo).
|
|
170
|
+
|
|
171
|
+
## Quick start
|
|
172
|
+
|
|
173
|
+
Headless core only (no UI):
|
|
174
|
+
|
|
175
|
+
```ts
|
|
176
|
+
import { Grid } from "@omnigrid/core";
|
|
177
|
+
import type { ColumnDef } from "@omnigrid/core";
|
|
178
|
+
|
|
179
|
+
interface Row { id: string; name: string }
|
|
180
|
+
|
|
181
|
+
const columns: ColumnDef<Row>[] = [
|
|
182
|
+
{ id: "name", field: "name", header: "Name", width: 220 },
|
|
183
|
+
];
|
|
184
|
+
|
|
185
|
+
const grid = new Grid<Row>({ data: [{ id: "1", name: "Ada" }], columns, getRowId: (row) => row.id });
|
|
186
|
+
|
|
187
|
+
grid.setViewport({ width: 400, height: 300 }); // the adapter normally feeds geometry
|
|
188
|
+
const viewport = grid.getViewportData(); // virtualized rows + columns + offsets
|
|
189
|
+
grid.on("rowClick", (e) => console.log(e.index));
|
|
190
|
+
grid.destroy();
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
With base plugins:
|
|
194
|
+
|
|
195
|
+
```ts
|
|
196
|
+
import { Grid } from "@omnigrid/core";
|
|
197
|
+
import { SortingPlugin } from "@omnigrid/sorting-plugin";
|
|
198
|
+
import { SelectionPlugin } from "@omnigrid/selection-plugin";
|
|
199
|
+
import { PaginationPlugin } from "@omnigrid/pagination-plugin";
|
|
200
|
+
|
|
201
|
+
const grid = new Grid<Row>({
|
|
202
|
+
data,
|
|
203
|
+
columns,
|
|
204
|
+
getRowId: (row) => row.id,
|
|
205
|
+
plugins: [
|
|
206
|
+
new SortingPlugin<Row>(),
|
|
207
|
+
new SelectionPlugin<Row>({ mode: "multiple", showRowCheckboxes: true }),
|
|
208
|
+
new PaginationPlugin<Row>({ pageSize: 50 }),
|
|
209
|
+
],
|
|
210
|
+
});
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
In a UI framework, use the adapter — e.g. `@omnigrid/react`:
|
|
214
|
+
|
|
215
|
+
```tsx
|
|
216
|
+
<OmniGrid columns={columns} data={rows} getRowId={(row) => row.id} plugins={plugins} style={{ height: 480 }} />
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
See [@omnigrid/react](../../adapters/react/README.md).
|
|
220
|
+
|
|
221
|
+
## Exported helpers
|
|
222
|
+
|
|
223
|
+
- `flattenColumns`, `isColumnLeaf`, `isColumnGroup`, `getColumnGroups` — column tree utilities.
|
|
224
|
+
- `Store`, `Virtualizer`, `EventBus`, `DomPool`, `SlotManager`, `IconRegistry` — building blocks
|
|
225
|
+
(mostly used internally; public for advanced integrations/tests).
|
|
226
|
+
|
|
227
|
+
## Links
|
|
228
|
+
|
|
229
|
+
- **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/core
|
|
230
|
+
- **Demo:** https://omnigrid-demo.vercel.app/
|
|
231
|
+
- **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
|
|
232
|
+
|
|
233
|
+
## License
|
|
234
|
+
|
|
235
|
+
MIT © KRZK Apps
|
package/dist/grid.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { IconRegistry } from "./icons";
|
|
2
2
|
import { SlotManager } from "./slots";
|
|
3
3
|
import type { DataProcessor, GridApi, GridEvents, GridOptions, GridPlugin, GridState, RowClickEvent, RowHoverEvent, RowId, ScrollPosition, SlotMount, SlotName, ViewportData, ViewportState } from "./types";
|
|
4
|
-
import type { OverlayOptions, OverlayState
|
|
4
|
+
import type { OverlayOptions, OverlayState } from "./overlays";
|
|
5
5
|
export declare class Grid<T> implements GridApi<T> {
|
|
6
6
|
private readonly store;
|
|
7
7
|
private readonly events;
|
|
@@ -64,8 +64,6 @@ export declare class Grid<T> implements GridApi<T> {
|
|
|
64
64
|
registerPlugin(plugin: GridPlugin<T>): () => void;
|
|
65
65
|
getSlotMounts(slot: SlotName): SlotMount<T>[];
|
|
66
66
|
showOverlay(options: OverlayOptions): void;
|
|
67
|
-
/** @deprecated Use the options-object overload. */
|
|
68
|
-
showOverlay(type: OverlayType, payload?: unknown): void;
|
|
69
67
|
hideOverlay(): void;
|
|
70
68
|
getOverlayState(): OverlayState;
|
|
71
69
|
setLoading(isLoading: boolean, error?: unknown): void;
|
package/dist/grid.js
CHANGED
|
@@ -318,11 +318,14 @@ export class Grid {
|
|
|
318
318
|
getSlotMounts(slot) {
|
|
319
319
|
return this.slots.getMounts(slot);
|
|
320
320
|
}
|
|
321
|
-
showOverlay(
|
|
321
|
+
showOverlay(options) {
|
|
322
322
|
this.assertActive();
|
|
323
|
-
const options = typeof optionsOrType === "string" ? { type: optionsOrType, payload } : optionsOrType;
|
|
324
323
|
this.overlayManual = true;
|
|
325
|
-
this.overlayState = {
|
|
324
|
+
this.overlayState = {
|
|
325
|
+
...options,
|
|
326
|
+
scope: options.scope ?? (options.type === "error" ? "full" : "bodyOnly"),
|
|
327
|
+
blockScroll: options.blockScroll ?? false,
|
|
328
|
+
};
|
|
326
329
|
this.store.setState({ overlay: { ...this.overlayState } });
|
|
327
330
|
this.events.emit("overlayChange", { ...this.overlayState });
|
|
328
331
|
}
|
|
@@ -366,8 +369,9 @@ export class Grid {
|
|
|
366
369
|
const next = type
|
|
367
370
|
? {
|
|
368
371
|
type,
|
|
372
|
+
scope: type === "error" ? "full" : "bodyOnly",
|
|
373
|
+
blockScroll: false,
|
|
369
374
|
...(type === "error" && this.loadError !== undefined ? { payload: this.loadError } : {}),
|
|
370
|
-
...(type === "noMatchingRows" ? { blockScroll: false } : {}),
|
|
371
375
|
}
|
|
372
376
|
: { type };
|
|
373
377
|
if (next.type !== this.overlayState.type ||
|
package/dist/overlays.d.ts
CHANGED
|
@@ -24,9 +24,9 @@ export type OverlayScope = "full" | "bodyOnly";
|
|
|
24
24
|
export interface OverlayOptions {
|
|
25
25
|
/** Overlay state to display. */
|
|
26
26
|
type: OverlayType;
|
|
27
|
-
/** Whether the overlay covers the complete grid or only its data body.
|
|
27
|
+
/** Whether the overlay covers the complete grid or only its data body. Defaults to "full" for errors and "bodyOnly" otherwise. */
|
|
28
28
|
scope?: OverlayScope;
|
|
29
|
-
/** Whether horizontal scrolling is
|
|
29
|
+
/** Whether horizontal scrolling is locked. Vertical scrolling is locked for every active overlay. */
|
|
30
30
|
blockScroll?: boolean;
|
|
31
31
|
/** Optional text displayed by the default overlay or passed to a custom component. */
|
|
32
32
|
message?: string;
|
package/dist/types.d.ts
CHANGED
|
@@ -457,14 +457,12 @@ export interface GridApi<T> {
|
|
|
457
457
|
* Shows an overlay using the supplied options.
|
|
458
458
|
*
|
|
459
459
|
* Manual overlays take precedence over automatic states until `hideOverlay`
|
|
460
|
-
* is called. Vertical scrolling is locked for
|
|
461
|
-
* controls whether horizontal scrolling is locked
|
|
460
|
+
* is called. Vertical scrolling is locked for every active overlay;
|
|
461
|
+
* `blockScroll` controls whether horizontal scrolling is locked.
|
|
462
462
|
* @param options - Overlay type, scope, message, and custom render payload.
|
|
463
463
|
* @api
|
|
464
464
|
*/
|
|
465
465
|
showOverlay(options: OverlayOptions): void;
|
|
466
|
-
/** @deprecated Use the options-object overload. */
|
|
467
|
-
showOverlay(type: OverlayType, payload?: unknown): void;
|
|
468
466
|
/**
|
|
469
467
|
* Hides the current overlay and re-enables automatic overlay evaluation
|
|
470
468
|
* based on the Data Pipeline state.
|