@omnigrid/react 0.1.11 → 0.1.12

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
@@ -22,6 +22,28 @@ const data = [...];
22
22
  <OmniGrid columns={columns} data={data} />;
23
23
  ```
24
24
 
25
+ ## Overlays
26
+
27
+ The adapter renders body-only overlays below the sticky header. While one is active, vertical
28
+ scrolling and its scrollbar are disabled; horizontal scrolling remains available for
29
+ `noMatchingRows` (or when `blockScroll: false`). Use `scope: "full"` to cover the header and
30
+ body as well.
31
+
32
+ ```tsx
33
+ import { OmniGrid, type OverlayComponentProps } from "@omnigrid/react";
34
+
35
+ function LoadError<T>({ message }: OverlayComponentProps<T>) {
36
+ return <div role="alert">{message ?? "Unable to load rows"}</div>;
37
+ }
38
+
39
+ <OmniGrid
40
+ columns={columns}
41
+ data={data}
42
+ overlayComponents={{ error: LoadError }}
43
+ onGridReady={(grid) => grid.showOverlay({ type: "error", message: "Please retry" })}
44
+ />;
45
+ ```
46
+
25
47
  To customize the table's color style, install a compatible `@omnigrid/*-theme`
26
48
  package and import it in the application after `@omnigrid/react`. Theme packages
27
49
  include their own light and dark variants; they are not light/dark mode toggles.
@@ -1,5 +1,5 @@
1
- import { type CSSProperties, type ReactNode } from "react";
2
- import type { GridOptions, SlotRenderContext } from "@omnigrid/core";
1
+ import { type ComponentType, type CSSProperties, type ReactNode } from "react";
2
+ import type { GridOptions, OverlayComponent as CoreOverlayComponent, OverlayComponentProps as CoreOverlayComponentProps, SlotRenderContext } from "@omnigrid/core";
3
3
  /**
4
4
  * Registry of native adapter components for `SlotComponentContent`:
5
5
  * slotComponents={{ ["my-widget"]: (payload, context) => <MyWidget .../> }}
@@ -7,10 +7,13 @@ import type { GridOptions, SlotRenderContext } from "@omnigrid/core";
7
7
  export interface SlotRendererRegistry<T> {
8
8
  [kind: string]: (payload: unknown, context: SlotRenderContext<T>) => ReactNode;
9
9
  }
10
- export interface GridProps<T> extends GridOptions<T> {
10
+ export type OverlayComponentProps<T> = CoreOverlayComponentProps<T>;
11
+ type OverlayComponent<T> = ComponentType<CoreOverlayComponentProps<T>> | CoreOverlayComponent<T>;
12
+ export interface GridProps<T> extends Omit<GridOptions<T>, "overlayComponents"> {
11
13
  className?: string;
12
14
  style?: CSSProperties;
13
15
  slotComponents?: SlotRendererRegistry<T>;
16
+ overlayComponents?: Record<string, OverlayComponent<T>>;
14
17
  }
15
18
  /**
16
19
  * React adapter over the headless core.
@@ -38,3 +41,4 @@ export interface GridProps<T> extends GridOptions<T> {
38
41
  * `slotComponents`.
39
42
  */
40
43
  export declare function OmniGrid<T>({ className, style, slotComponents, ...options }: GridProps<T>): import("react").JSX.Element;
44
+ export {};
package/dist/OmniGrid.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
2
+ import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
3
3
  import { flushSync } from "react-dom";
4
4
  import { DomPool } from "@omnigrid/core";
5
5
  import { contentToReactNode } from "./content";
@@ -125,6 +125,12 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
125
125
  const viewportStyle = { ...style, height: autoHeight ? measuredHeight : style?.height };
126
126
  const suppressRowHoverHighlight = options.suppressRowHoverHighlight ?? false;
127
127
  const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null].filter(Boolean).join(" ");
128
+ const overlayState = state.overlay;
129
+ const overlayScope = overlayState.type ? (overlayState.scope ?? "bodyOnly") : undefined;
130
+ const overlayBlocksHorizontalScroll = overlayState.type
131
+ ? (overlayState.blockScroll ?? overlayState.type !== "noMatchingRows")
132
+ : false;
133
+ const isFullOverlay = overlayScope === "full";
128
134
  /**
129
135
  * Bridge between the core's headless content and React: a factory for the
130
136
  * current render context (the registry is read live via the ref).
@@ -383,10 +389,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
383
389
  useLayoutEffect(() => {
384
390
  if (!isMeasured || autoHeight)
385
391
  return;
386
- // Gutter changes alter clientWidth; sync it before paint so columns
387
- // cannot render underneath a newly visible vertical scrollbar.
392
+ // Scrollbar and gutter changes alter clientWidth; sync it before paint
393
+ // so columns remain aligned when an overlay locks vertical scrolling.
388
394
  measureViewport();
389
- }, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport]);
395
+ }, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport, overlayScope]);
390
396
  /**
391
397
  * Sync the DomPool after every structural re-render.
392
398
  * This runs only when React actually re-renders (data / columns /
@@ -486,23 +492,35 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
486
492
  }) }));
487
493
  };
488
494
  /**
489
- * Resolves the active overlay content: a custom renderer (if registered)
490
- * takes precedence; otherwise the built-in default overlay is used.
491
- *
492
- * Custom renderers return headless content (SlotContent) materialized via
493
- * `contentToReactNode` — the same protocol as cell/slot renderers.
495
+ * Resolves a React component, legacy headless renderer, or built-in overlay
496
+ * for the active state.
494
497
  */
495
498
  function renderOverlayContent(overlay) {
496
499
  if (!overlay || !overlay.type)
497
500
  return null;
498
- const customRenderer = optionsRef.current.overlayComponents?.[overlay.type];
499
- if (customRenderer) {
501
+ const registeredRenderer = typeof overlay.component === "string"
502
+ ? optionsRef.current.overlayComponents?.[overlay.component]
503
+ : optionsRef.current.overlayComponents?.[overlay.type];
504
+ const component = typeof overlay.component === "function" || (typeof overlay.component === "object" && overlay.component !== null)
505
+ ? overlay.component
506
+ : registeredRenderer;
507
+ const isLegacyRenderer = typeof component === "function" && component.length >= 2;
508
+ if (component && !isLegacyRenderer) {
509
+ return createElement(component, {
510
+ type: overlay.type,
511
+ message: overlay.message,
512
+ payload: overlay.payload,
513
+ state: grid.getState(),
514
+ });
515
+ }
516
+ const customRenderer = component ?? registeredRenderer;
517
+ if (isLegacyRenderer && typeof customRenderer === "function") {
500
518
  return contentToReactNode(customRenderer(overlay.payload, grid.getState()), {
501
519
  registry: slotComponentsRef.current,
502
520
  context: buildRenderContext,
503
521
  });
504
522
  }
505
- if (overlay.type === "custom") {
523
+ if (overlay.component !== undefined) {
506
524
  return contentToReactNode(overlay.payload, {
507
525
  registry: slotComponentsRef.current,
508
526
  context: buildRenderContext,
@@ -510,7 +528,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
510
528
  }
511
529
  return renderDefaultOverlay(overlay);
512
530
  }
513
- const overlayState = state.overlay;
514
531
  const pinnedLeftWidth = viewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
515
532
  const pinnedRightWidth = viewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
516
533
  const scrollableWidth = Math.max(0, viewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
@@ -528,6 +545,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
528
545
  // correctly on the horizontal axis because sticky positioning is not
529
546
  // affected by the clip.
530
547
  const needsHorizontalScroll = viewportData.totalWidth > grid.getState().viewport.width;
548
+ const overlayHeight = Math.max(0, (autoHeight ? measuredHeight : state.viewport.height) - headerHeight);
531
549
  const renderHeaderCells = (columns, originX) => columns.map((item) => {
532
550
  const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
533
551
  const gapRows = headerRowCount - 1 - deepestDepth;
@@ -609,16 +627,16 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
609
627
  top: headerHeight,
610
628
  width,
611
629
  } }));
612
- return (_jsxs("div", { className: "omnigrid-layout", style: style, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { ref: viewportRef, className: viewportClassName, onScroll: handleScroll, style: {
630
+ return (_jsxs("div", { className: "omnigrid-layout", style: { ...style, position: "relative", ...(isFullOverlay ? { overflow: "hidden" } : {}) }, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { ref: viewportRef, className: viewportClassName, onScroll: handleScroll, style: {
613
631
  ...viewportStyle,
614
632
  flex: "1 1 0",
615
633
  height: autoHeight ? measuredHeight : "100%",
616
634
  minHeight: 0,
617
635
  minWidth: 0,
618
- overflowX: needsHorizontalScroll ? "auto" : "hidden",
619
- overflowY: autoHeight ? "hidden" : "auto",
636
+ overflowX: isFullOverlay || (overlayScope === "bodyOnly" && overlayBlocksHorizontalScroll) ? "hidden" : needsHorizontalScroll ? "auto" : "hidden",
637
+ overflowY: isFullOverlay || overlayScope === "bodyOnly" || autoHeight ? "hidden" : "auto",
620
638
  position: "relative",
621
- scrollbarGutter: verticalScrollbarGutter,
639
+ scrollbarGutter: overlayScope === "bodyOnly" ? "auto" : verticalScrollbarGutter,
622
640
  width: "100%",
623
641
  }, children: [_jsxs("div", { style: {
624
642
  display: "flex",
@@ -645,13 +663,19 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
645
663
  top: 0,
646
664
  width: `${pinnedRightWidth}px`,
647
665
  zIndex: 3,
648
- }, children: [renderHeader(viewportData.pinnedRightColumns, pinnedLeftWidth + scrollableWidth, `${pinnedRightWidth}px`, true), renderRowsLayer(pinnedRightRowsLayerRef, `${pinnedRightWidth}px`)] }))] }), overlayState?.type && (_jsx("div", { className: "omnigrid-overlay", role: "status", style: {
649
- bottom: 0,
666
+ }, children: [renderHeader(viewportData.pinnedRightColumns, pinnedLeftWidth + scrollableWidth, `${pinnedRightWidth}px`, true), renderRowsLayer(pinnedRightRowsLayerRef, `${pinnedRightWidth}px`)] }))] }), overlayState.type && overlayScope === "bodyOnly" && (
667
+ // Keep the sticky overlay anchored to the body viewport without adding
668
+ // its height to the scrollable content's natural dimensions.
669
+ _jsx("div", { className: "omnigrid-overlay omnigrid-overlay-body", role: "status", style: {
670
+ height: overlayHeight,
650
671
  left: 0,
672
+ marginBottom: -overlayHeight,
673
+ marginTop: -rowTotalHeight,
651
674
  pointerEvents: "auto",
652
- position: "absolute",
675
+ position: "sticky",
653
676
  right: 0,
654
677
  top: headerHeight,
678
+ width: "100%",
655
679
  zIndex: 4,
656
- }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom")] }));
680
+ }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
657
681
  }
package/dist/index.d.ts CHANGED
@@ -4,6 +4,6 @@ export * from "@omnigrid/core";
4
4
  export { PooledRowPane } from "./pooledRow";
5
5
  export type { PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./pooledRow";
6
6
  export { OmniGrid } from "./OmniGrid";
7
- export type { GridProps, SlotRendererRegistry } from "./OmniGrid";
7
+ export type { GridProps, OverlayComponentProps, SlotRendererRegistry } from "./OmniGrid";
8
8
  export { useGrid } from "./useGrid";
9
9
  export type { UseGridResult } from "./useGrid";
package/dist/overlays.js CHANGED
@@ -9,17 +9,17 @@ function extractMessage(payload, fallback) {
9
9
  }
10
10
  return fallback;
11
11
  }
12
- function LoadingOverlay() {
13
- return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx("div", { className: "omnigrid-overlay-spinner", "aria-label": "Loading" }), _jsx("span", { className: "omnigrid-overlay-text", children: "Loading\u2026" })] }));
12
+ function LoadingOverlay(_payload, message) {
13
+ return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx("div", { className: "omnigrid-overlay-spinner", "aria-label": "Loading" }), _jsx("span", { className: "omnigrid-overlay-text", children: message ?? "Loading…" })] }));
14
14
  }
15
- function NoRowsOverlay(payload) {
16
- return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(NoRowsIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", children: extractMessage(payload, "No data to display") })] }));
15
+ function NoRowsOverlay(payload, message) {
16
+ return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(NoRowsIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", children: message ?? extractMessage(payload, "No data to display") })] }));
17
17
  }
18
- function NoMatchingRowsOverlay(payload) {
19
- return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(NoMatchingRowsIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", children: extractMessage(payload, "No matching rows found") })] }));
18
+ function NoMatchingRowsOverlay(payload, message) {
19
+ return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(NoMatchingRowsIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", children: message ?? extractMessage(payload, "No matching rows found") })] }));
20
20
  }
21
- function ErrorOverlay(payload) {
22
- return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(ErrorIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", role: "alert", children: extractMessage(payload, "An error occurred") })] }));
21
+ function ErrorOverlay(payload, message) {
22
+ return (_jsxs("div", { className: "omnigrid-overlay-content", children: [_jsx(ErrorIcon, {}), _jsx("span", { className: "omnigrid-overlay-text", role: "alert", children: message ?? extractMessage(payload, "An error occurred") })] }));
23
23
  }
24
24
  const DEFAULT_OVERLAYS = {
25
25
  loading: LoadingOverlay,
@@ -34,7 +34,7 @@ const DEFAULT_OVERLAYS = {
34
34
  * directly by `OmniGrid.renderOverlayContent` via `contentToReactNode`.
35
35
  */
36
36
  export function renderDefaultOverlay(overlay) {
37
- const { type, payload } = overlay;
37
+ const { type, payload, message } = overlay;
38
38
  if (!type)
39
39
  return null;
40
40
  if (type === "custom")
@@ -42,7 +42,7 @@ export function renderDefaultOverlay(overlay) {
42
42
  const factory = DEFAULT_OVERLAYS[type];
43
43
  if (!factory)
44
44
  return null;
45
- return factory(payload);
45
+ return factory(payload, message);
46
46
  }
47
47
  /** Inline SVG: empty / document icon. */
48
48
  function NoRowsIcon() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",