@omnigrid/core 0.1.8 → 0.1.10

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 CHANGED
@@ -26,7 +26,7 @@ not re-render on scroll frames. Read them via `getScrollPosition()`.
26
26
 
27
27
  ```ts
28
28
  interface GridOptions<T> {
29
- data?: T[]; // row data; omit when a plugin provides it (server pagination)
29
+ data?: T[] | null; // row data; null/omitted means initial loading
30
30
  columns: ColumnDef<T>[]; // required
31
31
  getRowId?: (row: T, index: number) => RowId; // default: index-based
32
32
  rowHeight?: number; // fixed px row height; default 32 (offset math is O(1))
@@ -39,6 +39,8 @@ interface GridOptions<T> {
39
39
  getRowClass?: (params: RowRenderParams<T>) => string | undefined;
40
40
  rowClassRules?: RowClassRules<T>; // class name → predicate
41
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>>;
42
44
  }
43
45
  ```
44
46
 
@@ -97,7 +99,7 @@ interface GridApi<T> {
97
99
  getViewportData(): ViewportData<T>; // virtualized window: rows/columns + absolute offsets
98
100
  getProcessedData(): T[]; // after all registered data processors
99
101
  getRowId(row: T, index: number): RowId;
100
- setData(data: T[]): void;
102
+ setData(data: T[] | null | undefined): void;
101
103
  setViewport(viewport: Partial<ViewportState>): void; // width/height/scrollTop/scrollLeft; scroll-only ⇒ no Store notify
102
104
  refresh(): void; // repaint hints (rowClassRules), bumps revision
103
105
  subscribe(listener: () => void): () => void;
@@ -111,12 +113,38 @@ interface GridApi<T> {
111
113
  readonly slots: SlotManager<T>; // mount headless widgets
112
114
  readonly icons: IconRegistry<T>; // declarative SVG icons for plugin UI
113
115
  getSlotMounts(slot: SlotName): SlotMount<T>[];
116
+ showOverlay(options: OverlayOptions): void;
117
+ hideOverlay(): void;
118
+ getOverlayState(): OverlayState;
119
+ setLoading(isLoading: boolean, error?: unknown): void;
114
120
  getRevision(): number; // monotonic counter for structural changes
115
121
  destroy(): void;
116
122
  isDestroyed(): boolean;
117
123
  }
118
124
  ```
119
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
+ scope: "bodyOnly", // or "full" to cover the complete grid
138
+ blockScroll: false, // keep horizontal scrolling; body overlays always lock vertical scroll
139
+ message: "Could not load records",
140
+ });
141
+ grid.hideOverlay(); // restores automatic loading / empty-state evaluation
142
+ const overlay = grid.getOverlayState();
143
+ ```
144
+
145
+ `overlayComponents` accepts framework-specific components through the adapter or core render
146
+ callbacks. Component props include `type`, `message`, `payload`, and the current `state`.
147
+
120
148
  `GridEvents<T>`: `stateChange` | `viewportChange` | `dataChange` | `headerClick` | `rowClick` | `rowHover` | `slotsChange`.
121
149
  Example: `grid.on("rowClick", (e) => console.log(e.id, e.index, e.data))`.
122
150
 
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 { OverlayState, OverlayType } from "./overlays";
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;
@@ -22,6 +22,8 @@ export declare class Grid<T> implements GridApi<T> {
22
22
  * disables auto-evaluation until hideOverlay re-enables it.
23
23
  */
24
24
  private loading;
25
+ private hasData;
26
+ private loadError;
25
27
  private overlayState;
26
28
  private overlayManual;
27
29
  /**
@@ -42,7 +44,7 @@ export declare class Grid<T> implements GridApi<T> {
42
44
  getViewportData(): ViewportData<T>;
43
45
  getProcessedData(): T[];
44
46
  getRowId(row: T, index: number): RowId;
45
- setData(data: T[]): void;
47
+ setData(data: T[] | null | undefined): void;
46
48
  setViewport(viewport: Partial<ViewportState>): void;
47
49
  /**
48
50
  * Repaints the current viewport: notifies Store subscribers that
@@ -61,10 +63,10 @@ export declare class Grid<T> implements GridApi<T> {
61
63
  emit<EventName extends keyof GridEvents<T>>(event: EventName, payload: GridEvents<T>[EventName]): void;
62
64
  registerPlugin(plugin: GridPlugin<T>): () => void;
63
65
  getSlotMounts(slot: SlotName): SlotMount<T>[];
64
- showOverlay(type: OverlayType, payload?: unknown): void;
66
+ showOverlay(options: OverlayOptions): void;
65
67
  hideOverlay(): void;
66
68
  getOverlayState(): OverlayState;
67
- setLoading(isLoading: boolean): void;
69
+ setLoading(isLoading: boolean, error?: unknown): void;
68
70
  /**
69
71
  * Re-evaluates the overlay based on the current Data Pipeline state.
70
72
  *
package/dist/grid.js CHANGED
@@ -22,6 +22,7 @@ export class Grid {
22
22
  * disables auto-evaluation until hideOverlay re-enables it.
23
23
  */
24
24
  this.loading = false;
25
+ this.hasData = true;
25
26
  this.overlayState = { type: null };
26
27
  this.overlayManual = false;
27
28
  /**
@@ -45,6 +46,7 @@ export class Grid {
45
46
  this.store = new Store(state);
46
47
  this.resolveRowId = options.getRowId ?? ((_row, index) => index);
47
48
  this.loading = options.loading ?? false;
49
+ this.hasData = options.data !== undefined && options.data !== null;
48
50
  this.virtualizer = new Virtualizer({
49
51
  rowHeight: state.rowHeight,
50
52
  rowOverscan: state.rowOverscan,
@@ -194,10 +196,13 @@ export class Grid {
194
196
  }
195
197
  setData(data) {
196
198
  this.assertActive();
199
+ this.loadError = undefined;
200
+ this.hasData = data !== undefined && data !== null;
201
+ const nextData = data ?? [];
197
202
  this.processedDataCache = null;
198
203
  this.revision += 1;
199
- this.store.setState({ data });
200
- this.events.emit("dataChange", data);
204
+ this.store.setState({ data: nextData });
205
+ this.events.emit("dataChange", nextData);
201
206
  this.recomputeOverlay();
202
207
  }
203
208
  setViewport(viewport) {
@@ -313,10 +318,10 @@ export class Grid {
313
318
  getSlotMounts(slot) {
314
319
  return this.slots.getMounts(slot);
315
320
  }
316
- showOverlay(type, payload) {
321
+ showOverlay(options) {
317
322
  this.assertActive();
318
323
  this.overlayManual = true;
319
- this.overlayState = { type, payload };
324
+ this.overlayState = { ...options };
320
325
  this.store.setState({ overlay: { ...this.overlayState } });
321
326
  this.events.emit("overlayChange", { ...this.overlayState });
322
327
  }
@@ -328,11 +333,13 @@ export class Grid {
328
333
  getOverlayState() {
329
334
  return { ...this.overlayState };
330
335
  }
331
- setLoading(isLoading) {
336
+ setLoading(isLoading, error) {
332
337
  this.assertActive();
333
- if (this.loading === isLoading)
338
+ const nextError = isLoading ? undefined : error;
339
+ if (this.loading === isLoading && this.loadError === nextError)
334
340
  return;
335
341
  this.loading = isLoading;
342
+ this.loadError = nextError;
336
343
  this.recomputeOverlay();
337
344
  }
338
345
  /**
@@ -350,12 +357,24 @@ export class Grid {
350
357
  const state = this.store.getState();
351
358
  const processedData = this.getProcessedData();
352
359
  const type = evaluateAutoOverlay({
353
- loading: this.loading,
360
+ loading: this.loading || !this.hasData,
361
+ error: this.loadError,
354
362
  rawData: state.data,
355
363
  processedData,
356
364
  });
357
- const next = { type };
358
- if (next.type !== this.overlayState.type || next.payload !== this.overlayState.payload) {
365
+ const next = type
366
+ ? {
367
+ type,
368
+ ...(type === "error" && this.loadError !== undefined ? { payload: this.loadError } : {}),
369
+ ...(type === "noMatchingRows" ? { blockScroll: false } : {}),
370
+ }
371
+ : { type };
372
+ if (next.type !== this.overlayState.type ||
373
+ next.payload !== this.overlayState.payload ||
374
+ next.scope !== this.overlayState.scope ||
375
+ next.blockScroll !== this.overlayState.blockScroll ||
376
+ next.message !== this.overlayState.message ||
377
+ next.component !== this.overlayState.component) {
359
378
  this.overlayState = next;
360
379
  this.store.setState({ overlay: { ...next } });
361
380
  this.events.emit("overlayChange", { ...next });
package/dist/index.d.ts CHANGED
@@ -7,7 +7,7 @@ export { Grid } from "./grid";
7
7
  export { Grid as GridCore } from "./grid";
8
8
  export { SlotManager } from "./slots";
9
9
  export { Store } from "./store";
10
- export type { OverlayState, OverlayType } from "./overlays";
11
- export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
10
+ export type { OverlayOptions, OverlayScope, OverlayState, OverlayType } from "./overlays";
11
+ export type { BlockConfig, CellAlign, CellRenderParams, CellClassRules, CheckboxControl, CheckboxRenderParams, ColumnDef, ColumnGroupDef, ColumnGroupViewport, ColumnLeafDef, DataProcessor, DomPoolBindings, DomPoolUpdate, GridApi, GridEvents, GridOptions, GridPlugin, GridState, OverlayComponent, OverlayComponentProps, PooledRow, Range, RowClassRules, RowClickEvent, RowHost, RowHoverEvent, RowId, RowRenderParams, RowStyle, ScrollPosition, SlotComponentContent, SlotContent, SlotHtmlContent, SlotMount, SlotMountOptions, SlotName, SlotNodeContent, SlotNodeEvent, SlotNodeEventName, SlotPosition, SlotProvider, SlotRenderContext, SortDirection, ViewportData, ViewportState, VirtualItem, } from "./types";
12
12
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf } from "./columns";
13
13
  export { Virtualizer } from "./virtualizer";
@@ -1,9 +1,8 @@
1
1
  /**
2
2
  * @file Core overlay management types and evaluation logic.
3
3
  *
4
- * Overlays are full-body UI states shown over the grid's data viewport
5
- * (below the sticky header). They communicate transient states to the user:
6
- * data fetching, empty results, errors, and arbitrary custom content.
4
+ * Overlays communicate transient states to the user: data fetching, empty
5
+ * results, errors, and arbitrary custom content.
7
6
  */
8
7
  /**
9
8
  * Supported overlay types shown over the grid body viewport.
@@ -12,19 +11,44 @@
12
11
  */
13
12
  export type OverlayType = "loading" | "noRows" | "noMatchingRows" | "error" | "custom";
14
13
  /**
15
- * Ephemeral overlay state — which overlay (if any) is active and its payload.
14
+ * Portion of the grid covered by an overlay.
16
15
  *
17
16
  * @api
18
17
  */
19
- export interface OverlayState {
18
+ export type OverlayScope = "full" | "bodyOnly";
19
+ /**
20
+ * Configuration for a manually displayed overlay.
21
+ *
22
+ * @api
23
+ */
24
+ export interface OverlayOptions {
25
+ /** Overlay state to display. */
26
+ type: OverlayType;
27
+ /** Whether the overlay covers the complete grid or only its data body. @default "bodyOnly" */
28
+ scope?: OverlayScope;
29
+ /** Whether horizontal scrolling is also locked. Vertical scrolling is always locked by an active body overlay. */
30
+ blockScroll?: boolean;
31
+ /** Optional text displayed by the default overlay or passed to a custom component. */
32
+ message?: string;
33
+ /** Custom renderer or adapter-specific renderer identifier. */
34
+ component?: unknown;
35
+ /** Optional data passed to a custom overlay or used to derive the default message. */
36
+ payload?: unknown;
37
+ }
38
+ /**
39
+ * Active overlay type, placement, scroll policy, and optional renderer payload.
40
+ *
41
+ * @api
42
+ */
43
+ export interface OverlayState extends Omit<OverlayOptions, "type"> {
20
44
  /** Active overlay type, or null when no overlay is shown. */
21
45
  type: OverlayType | null;
22
- /** Optional payload (e.g. error details, or data for a custom overlay). */
23
- payload?: unknown;
24
46
  }
25
47
  interface EvaluateAutoOverlayParams<T> {
26
48
  /** Whether the grid is currently fetching / loading data. */
27
49
  loading: boolean;
50
+ /** Error raised by the most recent data load, if any. */
51
+ error?: unknown;
28
52
  /** The raw data array held by the grid (before pipeline processors). */
29
53
  rawData: T[];
30
54
  /** The data array after all pipeline processors (sorting, filtering, pagination). */
@@ -33,11 +57,7 @@ interface EvaluateAutoOverlayParams<T> {
33
57
  /**
34
58
  * Evaluates which overlay should be automatically shown based on Data Pipeline state.
35
59
  *
36
- * Priority order:
37
- * 1. `loading` → `"loading"` (fetch in progress, shown regardless of data)
38
- * 2. `processedData` empty + `rawData` empty → `"noRows"` (no data at all)
39
- * 3. `processedData` empty + `rawData` non-empty → `"noMatchingRows"` (filters excluded everything)
40
- * 4. otherwise → `null` (no overlay)
60
+ * Priority order is loading, load error, no rows, no matching rows, then no overlay.
41
61
  *
42
62
  * @param params - The current pipeline state.
43
63
  * @returns The overlay type to show, or null when no overlay is needed.
package/dist/overlays.js CHANGED
@@ -1,18 +1,13 @@
1
1
  /**
2
2
  * @file Core overlay management types and evaluation logic.
3
3
  *
4
- * Overlays are full-body UI states shown over the grid's data viewport
5
- * (below the sticky header). They communicate transient states to the user:
6
- * data fetching, empty results, errors, and arbitrary custom content.
4
+ * Overlays communicate transient states to the user: data fetching, empty
5
+ * results, errors, and arbitrary custom content.
7
6
  */
8
7
  /**
9
8
  * Evaluates which overlay should be automatically shown based on Data Pipeline state.
10
9
  *
11
- * Priority order:
12
- * 1. `loading` → `"loading"` (fetch in progress, shown regardless of data)
13
- * 2. `processedData` empty + `rawData` empty → `"noRows"` (no data at all)
14
- * 3. `processedData` empty + `rawData` non-empty → `"noMatchingRows"` (filters excluded everything)
15
- * 4. otherwise → `null` (no overlay)
10
+ * Priority order is loading, load error, no rows, no matching rows, then no overlay.
16
11
  *
17
12
  * @param params - The current pipeline state.
18
13
  * @returns The overlay type to show, or null when no overlay is needed.
@@ -21,6 +16,8 @@
21
16
  export function evaluateAutoOverlay(params) {
22
17
  if (params.loading)
23
18
  return "loading";
19
+ if (params.error !== undefined)
20
+ return "error";
24
21
  if (params.processedData.length === 0) {
25
22
  return params.rawData.length === 0 ? "noRows" : "noMatchingRows";
26
23
  }
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { OverlayState, OverlayType } from "./overlays";
1
+ import type { OverlayOptions, OverlayState, OverlayType } from "./overlays";
2
2
  import type { SlotManager } from "./slots";
3
3
  import type { IconRegistry } from "./icons";
4
4
  export type RowId = string | number;
@@ -118,8 +118,30 @@ export interface ColumnGroupDef<T> extends BaseColumnDef<T> {
118
118
  }
119
119
  /** Leaf or grouped column definition accepted by the grid. */
120
120
  export type ColumnDef<T> = ColumnLeafDef<T> | ColumnGroupDef<T>;
121
+ /**
122
+ * Props supplied to a framework-specific overlay renderer.
123
+ *
124
+ * @api
125
+ */
126
+ export interface OverlayComponentProps<T> {
127
+ /** The active overlay state. */
128
+ type: OverlayType;
129
+ /** Optional display text override. */
130
+ message?: string;
131
+ /** Custom overlay payload. */
132
+ payload?: unknown;
133
+ /** Latest public grid state. */
134
+ state: GridState<T>;
135
+ }
136
+ /**
137
+ * Framework-neutral custom overlay renderer.
138
+ *
139
+ * @api
140
+ */
141
+ export type OverlayComponent<T> = ((props: OverlayComponentProps<T>) => unknown) | ((payload: unknown, state: GridState<T>) => unknown);
121
142
  export interface GridOptions<T> {
122
- data?: T[];
143
+ /** Row data; omitted or null means an initial load is pending. */
144
+ data?: T[] | null;
123
145
  columns: ColumnDef<T>[];
124
146
  getRowId?: (row: T, index: number) => RowId;
125
147
  rowHeight?: number;
@@ -132,15 +154,14 @@ export interface GridOptions<T> {
132
154
  getRowClass?: (params: RowRenderParams<T>) => string | undefined;
133
155
  rowClassRules?: RowClassRules<T>;
134
156
  plugins?: GridPlugin<T>[];
135
- /** Whether data is currently being fetched. Triggers an automatic "loading" overlay. @default false */
157
+ /** Whether data is currently being fetched. Triggers a loading overlay. @default false when data is supplied */
136
158
  loading?: boolean;
137
159
  /**
138
- * Custom overlay content keyed by overlay type. Each function receives an
139
- * optional payload and the current grid state, and returns headless content
140
- * (SlotContent) materialized by the adapter — the same protocol used by
141
- * `cellRenderer` / slot content.
160
+ * Custom overlay renderers keyed by overlay type or renderer identifier.
161
+ * A one-argument function receives `OverlayComponentProps`; the legacy
162
+ * two-argument form receives `(payload, state)`.
142
163
  */
143
- overlayComponents?: Partial<Record<OverlayType, (payload: unknown, state: GridState<T>) => unknown>>;
164
+ overlayComponents?: Record<string, unknown>;
144
165
  /**
145
166
  * Called with the grid API instance when the grid is ready.
146
167
  * Use this to programmatically control overlays, sorting, scrolling, etc.
@@ -416,7 +437,7 @@ export interface GridApi<T> {
416
437
  getColumnWidth(columnId: string): number | undefined;
417
438
  getProcessedData(): T[];
418
439
  getRowId(row: T, index: number): RowId;
419
- setData(data: T[]): void;
440
+ setData(data: T[] | null | undefined): void;
420
441
  setViewport(viewport: Partial<ViewportState>): void;
421
442
  refresh(): void;
422
443
  subscribe(listener: () => void): () => void;
@@ -433,14 +454,15 @@ export interface GridApi<T> {
433
454
  readonly icons: IconRegistry<T>;
434
455
  getSlotMounts(slot: SlotName): SlotMount<T>[];
435
456
  /**
436
- * Shows an overlay of the given type, optionally with a payload.
457
+ * Shows an overlay using the supplied options.
437
458
  *
438
- * Calling this disables automatic overlay evaluation until `hideOverlay`
439
- * is called — the manual overlay takes precedence over auto-triggered
440
- * states (loading, noRows, etc.).
459
+ * Manual overlays take precedence over automatic states until `hideOverlay`
460
+ * is called. Vertical scrolling is locked for body overlays; `blockScroll`
461
+ * controls whether horizontal scrolling is locked as well.
462
+ * @param options - Overlay type, scope, message, and custom render payload.
441
463
  * @api
442
464
  */
443
- showOverlay(type: OverlayType, payload?: unknown): void;
465
+ showOverlay(options: OverlayOptions): void;
444
466
  /**
445
467
  * Hides the current overlay and re-enables automatic overlay evaluation
446
468
  * based on the Data Pipeline state.
@@ -454,11 +476,12 @@ export interface GridApi<T> {
454
476
  getOverlayState(): OverlayState;
455
477
  /**
456
478
  * Marks the grid as loading or not — triggers automatic overlay
457
- * re-evaluation. When `true`, the "loading" overlay is shown regardless
458
- * of the current data.
479
+ * re-evaluation. When loading completes with an error, pass it as the
480
+ * second argument to show the automatic error overlay. A subsequent
481
+ * successful `setData` clears the error.
459
482
  * @api
460
483
  */
461
- setLoading(isLoading: boolean): void;
484
+ setLoading(isLoading: boolean, error?: unknown): void;
462
485
  /** Monotonic counter for structural changes (refresh / data / columns). */
463
486
  getRevision(): number;
464
487
  destroy(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.8",
3
+ "version": "0.1.10",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",