@omnigrid/core 0.1.7 → 0.1.8

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/dist/grid.d.ts CHANGED
@@ -1,6 +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
5
  export declare class Grid<T> implements GridApi<T> {
5
6
  private readonly store;
6
7
  private readonly events;
@@ -13,6 +14,16 @@ export declare class Grid<T> implements GridApi<T> {
13
14
  private processedDataCache;
14
15
  private revision;
15
16
  private destroyed;
17
+ /**
18
+ * Overlay management state:
19
+ * - `loading`: whether the grid is fetching data (set via setLoading / options.loading)
20
+ * - `overlayState`: the current active overlay (type + payload)
21
+ * - `overlayManual`: whether the overlay was set manually (showOverlay), which
22
+ * disables auto-evaluation until hideOverlay re-enables it.
23
+ */
24
+ private loading;
25
+ private overlayState;
26
+ private overlayManual;
16
27
  /**
17
28
  * Separate ephemeral scroll position that is NOT stored in the Store.
18
29
  *
@@ -50,6 +61,18 @@ export declare class Grid<T> implements GridApi<T> {
50
61
  emit<EventName extends keyof GridEvents<T>>(event: EventName, payload: GridEvents<T>[EventName]): void;
51
62
  registerPlugin(plugin: GridPlugin<T>): () => void;
52
63
  getSlotMounts(slot: SlotName): SlotMount<T>[];
64
+ showOverlay(type: OverlayType, payload?: unknown): void;
65
+ hideOverlay(): void;
66
+ getOverlayState(): OverlayState;
67
+ setLoading(isLoading: boolean): void;
68
+ /**
69
+ * Re-evaluates the overlay based on the current Data Pipeline state.
70
+ *
71
+ * Skipped when a manual overlay is active (set via `showOverlay`). The
72
+ * Store is only updated when the overlay type actually changes — identical
73
+ * evaluations are a no-op to avoid spurious React re-renders.
74
+ */
75
+ private recomputeOverlay;
53
76
  /** Monotonic counter for structural changes (refresh / data / columns). */
54
77
  getRevision(): number;
55
78
  destroy(): void;
package/dist/grid.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { flattenColumns, getColumnGroups } from "./columns";
2
2
  import { EventBus } from "./events";
3
+ import { evaluateAutoOverlay } from "./overlays";
3
4
  import { IconRegistry } from "./icons";
4
5
  import { SlotManager } from "./slots";
5
6
  import { Store } from "./store";
@@ -13,6 +14,16 @@ export class Grid {
13
14
  this.processedDataCache = null;
14
15
  this.revision = 0;
15
16
  this.destroyed = false;
17
+ /**
18
+ * Overlay management state:
19
+ * - `loading`: whether the grid is fetching data (set via setLoading / options.loading)
20
+ * - `overlayState`: the current active overlay (type + payload)
21
+ * - `overlayManual`: whether the overlay was set manually (showOverlay), which
22
+ * disables auto-evaluation until hideOverlay re-enables it.
23
+ */
24
+ this.loading = false;
25
+ this.overlayState = { type: null };
26
+ this.overlayManual = false;
16
27
  /**
17
28
  * Separate ephemeral scroll position that is NOT stored in the Store.
18
29
  *
@@ -29,9 +40,11 @@ export class Grid {
29
40
  rowHeight: options.rowHeight ?? 32,
30
41
  rowOverscan: options.rowOverscan ?? 5,
31
42
  columnOverscan: options.columnOverscan ?? 2,
43
+ overlay: { type: null },
32
44
  };
33
45
  this.store = new Store(state);
34
46
  this.resolveRowId = options.getRowId ?? ((_row, index) => index);
47
+ this.loading = options.loading ?? false;
35
48
  this.virtualizer = new Virtualizer({
36
49
  rowHeight: state.rowHeight,
37
50
  rowOverscan: state.rowOverscan,
@@ -45,6 +58,7 @@ export class Grid {
45
58
  });
46
59
  this.store.subscribe(() => this.events.emit("stateChange", this.store.getState()));
47
60
  options.plugins?.forEach((plugin) => this.registerPlugin(plugin));
61
+ this.recomputeOverlay();
48
62
  }
49
63
  /** Returns the calculated width for a visible column, including off-screen columns. */
50
64
  getColumnWidth(columnId) {
@@ -184,6 +198,7 @@ export class Grid {
184
198
  this.revision += 1;
185
199
  this.store.setState({ data });
186
200
  this.events.emit("dataChange", data);
201
+ this.recomputeOverlay();
187
202
  }
188
203
  setViewport(viewport) {
189
204
  this.assertActive();
@@ -245,14 +260,18 @@ export class Grid {
245
260
  this.processedDataCache = null;
246
261
  this.revision += 1;
247
262
  this.store.setState({ columns });
263
+ this.recomputeOverlay();
248
264
  }
249
265
  registerDataProcessor(processor) {
250
266
  this.assertActive();
251
267
  this.dataProcessors.add(processor);
252
268
  this.processedDataCache = null;
269
+ this.recomputeOverlay();
253
270
  const unregister = () => {
254
271
  this.dataProcessors.delete(processor);
255
272
  this.processedDataCache = null;
273
+ if (!this.destroyed)
274
+ this.recomputeOverlay();
256
275
  };
257
276
  return unregister;
258
277
  }
@@ -294,6 +313,54 @@ export class Grid {
294
313
  getSlotMounts(slot) {
295
314
  return this.slots.getMounts(slot);
296
315
  }
316
+ showOverlay(type, payload) {
317
+ this.assertActive();
318
+ this.overlayManual = true;
319
+ this.overlayState = { type, payload };
320
+ this.store.setState({ overlay: { ...this.overlayState } });
321
+ this.events.emit("overlayChange", { ...this.overlayState });
322
+ }
323
+ hideOverlay() {
324
+ this.assertActive();
325
+ this.overlayManual = false;
326
+ this.recomputeOverlay();
327
+ }
328
+ getOverlayState() {
329
+ return { ...this.overlayState };
330
+ }
331
+ setLoading(isLoading) {
332
+ this.assertActive();
333
+ if (this.loading === isLoading)
334
+ return;
335
+ this.loading = isLoading;
336
+ this.recomputeOverlay();
337
+ }
338
+ /**
339
+ * Re-evaluates the overlay based on the current Data Pipeline state.
340
+ *
341
+ * Skipped when a manual overlay is active (set via `showOverlay`). The
342
+ * Store is only updated when the overlay type actually changes — identical
343
+ * evaluations are a no-op to avoid spurious React re-renders.
344
+ */
345
+ recomputeOverlay() {
346
+ if (this.destroyed)
347
+ return;
348
+ if (this.overlayManual)
349
+ return;
350
+ const state = this.store.getState();
351
+ const processedData = this.getProcessedData();
352
+ const type = evaluateAutoOverlay({
353
+ loading: this.loading,
354
+ rawData: state.data,
355
+ processedData,
356
+ });
357
+ const next = { type };
358
+ if (next.type !== this.overlayState.type || next.payload !== this.overlayState.payload) {
359
+ this.overlayState = next;
360
+ this.store.setState({ overlay: { ...next } });
361
+ this.events.emit("overlayChange", { ...next });
362
+ }
363
+ }
297
364
  /** Monotonic counter for structural changes (refresh / data / columns). */
298
365
  getRevision() {
299
366
  return this.revision;
@@ -305,6 +372,8 @@ export class Grid {
305
372
  this.cleanupPlugins.clear();
306
373
  this.dataProcessors.clear();
307
374
  this.processedDataCache = null;
375
+ this.overlayState = { type: null };
376
+ this.overlayManual = false;
308
377
  this.slots.clear();
309
378
  this.store.clear();
310
379
  this.events.clear();
package/dist/index.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  export { DomPool } from "./dom-pool";
2
2
  export { EventBus } from "./events";
3
+ export { evaluateAutoOverlay } from "./overlays";
3
4
  export { IconRegistry } from "./icons";
4
5
  export type { IconDefinition, IconName } from "./icons";
5
6
  export { Grid } from "./grid";
6
7
  export { Grid as GridCore } from "./grid";
7
8
  export { SlotManager } from "./slots";
8
9
  export { Store } from "./store";
10
+ export type { OverlayState, OverlayType } from "./overlays";
9
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
12
  export { getColumnGroups, flattenColumns, isColumnGroup, isColumnLeaf } from "./columns";
11
13
  export { Virtualizer } from "./virtualizer";
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export { DomPool } from "./dom-pool";
2
2
  export { EventBus } from "./events";
3
+ export { evaluateAutoOverlay } from "./overlays";
3
4
  export { IconRegistry } from "./icons";
4
5
  export { Grid } from "./grid";
5
6
  export { Grid as GridCore } from "./grid";
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @file Core overlay management types and evaluation logic.
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.
7
+ */
8
+ /**
9
+ * Supported overlay types shown over the grid body viewport.
10
+ *
11
+ * @api
12
+ */
13
+ export type OverlayType = "loading" | "noRows" | "noMatchingRows" | "error" | "custom";
14
+ /**
15
+ * Ephemeral overlay state — which overlay (if any) is active and its payload.
16
+ *
17
+ * @api
18
+ */
19
+ export interface OverlayState {
20
+ /** Active overlay type, or null when no overlay is shown. */
21
+ type: OverlayType | null;
22
+ /** Optional payload (e.g. error details, or data for a custom overlay). */
23
+ payload?: unknown;
24
+ }
25
+ interface EvaluateAutoOverlayParams<T> {
26
+ /** Whether the grid is currently fetching / loading data. */
27
+ loading: boolean;
28
+ /** The raw data array held by the grid (before pipeline processors). */
29
+ rawData: T[];
30
+ /** The data array after all pipeline processors (sorting, filtering, pagination). */
31
+ processedData: T[];
32
+ }
33
+ /**
34
+ * Evaluates which overlay should be automatically shown based on Data Pipeline state.
35
+ *
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)
41
+ *
42
+ * @param params - The current pipeline state.
43
+ * @returns The overlay type to show, or null when no overlay is needed.
44
+ * @internal
45
+ */
46
+ export declare function evaluateAutoOverlay<T>(params: EvaluateAutoOverlayParams<T>): OverlayType | null;
47
+ export {};
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @file Core overlay management types and evaluation logic.
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.
7
+ */
8
+ /**
9
+ * Evaluates which overlay should be automatically shown based on Data Pipeline state.
10
+ *
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)
16
+ *
17
+ * @param params - The current pipeline state.
18
+ * @returns The overlay type to show, or null when no overlay is needed.
19
+ * @internal
20
+ */
21
+ export function evaluateAutoOverlay(params) {
22
+ if (params.loading)
23
+ return "loading";
24
+ if (params.processedData.length === 0) {
25
+ return params.rawData.length === 0 ? "noRows" : "noMatchingRows";
26
+ }
27
+ return null;
28
+ }
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { OverlayState, OverlayType } from "./overlays";
1
2
  import type { SlotManager } from "./slots";
2
3
  import type { IconRegistry } from "./icons";
3
4
  export type RowId = string | number;
@@ -131,6 +132,21 @@ export interface GridOptions<T> {
131
132
  getRowClass?: (params: RowRenderParams<T>) => string | undefined;
132
133
  rowClassRules?: RowClassRules<T>;
133
134
  plugins?: GridPlugin<T>[];
135
+ /** Whether data is currently being fetched. Triggers an automatic "loading" overlay. @default false */
136
+ loading?: boolean;
137
+ /**
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.
142
+ */
143
+ overlayComponents?: Partial<Record<OverlayType, (payload: unknown, state: GridState<T>) => unknown>>;
144
+ /**
145
+ * Called with the grid API instance when the grid is ready.
146
+ * Use this to programmatically control overlays, sorting, scrolling, etc.
147
+ * @api
148
+ */
149
+ onGridReady?: (grid: GridApi<T>) => void;
134
150
  }
135
151
  export interface ViewportState {
136
152
  width: number;
@@ -229,6 +245,8 @@ export interface GridState<T> {
229
245
  rowHeight: number;
230
246
  rowOverscan: number;
231
247
  columnOverscan: number;
248
+ /** Active overlay state — updated automatically by the grid's overlay manager. */
249
+ overlay: OverlayState;
232
250
  }
233
251
  export interface GridEvents<T> {
234
252
  stateChange: GridState<T>;
@@ -248,6 +266,7 @@ export interface GridEvents<T> {
248
266
  slot: SlotName;
249
267
  mounts: SlotMount<T>[];
250
268
  };
269
+ overlayChange: OverlayState;
251
270
  }
252
271
  /** Opaque token for a row node owned by the adapter. */
253
272
  export type RowHost<T> = object;
@@ -413,6 +432,33 @@ export interface GridApi<T> {
413
432
  readonly slots: SlotManager<T>;
414
433
  readonly icons: IconRegistry<T>;
415
434
  getSlotMounts(slot: SlotName): SlotMount<T>[];
435
+ /**
436
+ * Shows an overlay of the given type, optionally with a payload.
437
+ *
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.).
441
+ * @api
442
+ */
443
+ showOverlay(type: OverlayType, payload?: unknown): void;
444
+ /**
445
+ * Hides the current overlay and re-enables automatic overlay evaluation
446
+ * based on the Data Pipeline state.
447
+ * @api
448
+ */
449
+ hideOverlay(): void;
450
+ /**
451
+ * Returns the current overlay state (a copy).
452
+ * @api
453
+ */
454
+ getOverlayState(): OverlayState;
455
+ /**
456
+ * 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.
459
+ * @api
460
+ */
461
+ setLoading(isLoading: boolean): void;
416
462
  /** Monotonic counter for structural changes (refresh / data / columns). */
417
463
  getRevision(): number;
418
464
  destroy(): void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/core",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "Framework-agnostic core engine for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",