@omnigrid/react 0.1.11 → 0.1.13

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
@@ -1,37 +1,62 @@
1
- # @omnigrid/react
2
-
3
- React adapter and renderer for OmniGrid. Renders the headless core engine into the DOM using React.
4
-
5
- ## What it provides
6
-
7
- - **`<OmniGrid />`** — React component that accepts `GridOptions` and renders a fully virtualized, 2D scrolled data grid
8
- - **`useGrid()`** — hook that creates and manages a `GridCore` instance with full lifecycle handling
9
- - **Cell / Row pooling** — reusable React content via DOM-pool integration for minimal re-renders
10
- - **Styles and default theme** — required structural styles and light/dark default colors are included automatically
11
- - **`transpilePackages`-ready** — works out of the box with Next.js and other bundlers
12
-
13
- ## Usage
14
-
15
- ```tsx
16
- import { OmniGrid } from "@omnigrid/react";
17
- import { useMemo } from "react";
18
-
19
- const columns = useMemo(() => [...], []);
20
- const data = [...];
21
-
22
- <OmniGrid columns={columns} data={data} />;
23
- ```
24
-
25
- To customize the table's color style, install a compatible `@omnigrid/*-theme`
26
- package and import it in the application after `@omnigrid/react`. Theme packages
27
- include their own light and dark variants; they are not light/dark mode toggles.
28
-
29
- ## Links
30
-
31
- - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react
32
- - **Demo:** https://omnigrid-demo.vercel.app/
33
- - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
34
-
35
- ## License
36
-
37
- MIT © KRZK Apps
1
+ # @omnigrid/react
2
+
3
+ React adapter and renderer for OmniGrid. Renders the headless core engine into the DOM using React.
4
+
5
+ ## What it provides
6
+
7
+ - **`<OmniGrid />`** — React component that accepts `GridOptions` and renders a fully virtualized, 2D scrolled data grid
8
+ - **`useGrid()`** — hook that creates and manages a `GridCore` instance with full lifecycle handling
9
+ - **Cell / Row pooling** — reusable React content via DOM-pool integration for minimal re-renders
10
+ - **Styles and default theme** — required structural styles and light/dark default colors are included automatically
11
+ - **`transpilePackages`-ready** — works out of the box with Next.js and other bundlers
12
+
13
+ ## Usage
14
+
15
+ ```tsx
16
+ import { OmniGrid } from "@omnigrid/react";
17
+ import { useMemo } from "react";
18
+
19
+ const columns = useMemo(() => [...], []);
20
+ const data = [...];
21
+
22
+ <OmniGrid columns={columns} data={data} />;
23
+ ```
24
+
25
+ ## Overlays
26
+
27
+ Automatic loading, no-rows, and no-matching-rows overlays cover the body below the sticky
28
+ header. They hide vertical scrolling while preserving its gutter, so columns do not shift;
29
+ horizontal scrolling remains available. Automatic error overlays cover the full grid.
30
+ Any active overlay hides vertical scrolling and preserves its gutter, regardless of scope.
31
+ Manual overlays default to body-only, except errors default to full-grid; set `scope` to
32
+ `"bodyOnly"` or `"full"` to choose the placement. `blockScroll: true` locks horizontal
33
+ scrolling; vertical scrolling is always locked while an overlay is active.
34
+
35
+ ```tsx
36
+ import { OmniGrid, type OverlayComponentProps } from "@omnigrid/react";
37
+
38
+ function LoadError<T>({ message }: OverlayComponentProps<T>) {
39
+ return <div role="alert">{message ?? "Unable to load rows"}</div>;
40
+ }
41
+
42
+ <OmniGrid
43
+ columns={columns}
44
+ data={data}
45
+ overlayComponents={{ error: LoadError }}
46
+ onGridReady={(grid) => grid.showOverlay({ type: "error", message: "Please retry" })}
47
+ />;
48
+ ```
49
+
50
+ To customize the table's color style, install a compatible `@omnigrid/*-theme`
51
+ package and import it in the application after `@omnigrid/react`. Theme packages
52
+ include their own light and dark variants; they are not light/dark mode toggles.
53
+
54
+ ## Links
55
+
56
+ - **Source:** https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react
57
+ - **Demo:** https://omnigrid-demo.vercel.app/
58
+ - **Issues:** https://github.com/KRZK-Apps/omnigrid/issues
59
+
60
+ ## License
61
+
62
+ MIT © KRZK Apps
@@ -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,14 @@ 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
130
+ ? (overlayState.scope ?? (overlayState.type === "error" ? "full" : "bodyOnly"))
131
+ : undefined;
132
+ const overlayBlocksHorizontalScroll = overlayState.type
133
+ ? (overlayState.blockScroll ?? false)
134
+ : false;
135
+ const isFullOverlay = overlayScope === "full";
128
136
  /**
129
137
  * Bridge between the core's headless content and React: a factory for the
130
138
  * current render context (the registry is read live via the ref).
@@ -383,10 +391,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
383
391
  useLayoutEffect(() => {
384
392
  if (!isMeasured || autoHeight)
385
393
  return;
386
- // Gutter changes alter clientWidth; sync it before paint so columns
387
- // cannot render underneath a newly visible vertical scrollbar.
394
+ // Scrollbar and gutter changes alter clientWidth; sync it before paint
395
+ // so columns remain aligned when an overlay locks vertical scrolling.
388
396
  measureViewport();
389
- }, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport]);
397
+ }, [autoHeight, hasVerticalOverflow, isMeasured, measureViewport, overlayScope]);
390
398
  /**
391
399
  * Sync the DomPool after every structural re-render.
392
400
  * This runs only when React actually re-renders (data / columns /
@@ -486,23 +494,35 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
486
494
  }) }));
487
495
  };
488
496
  /**
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.
497
+ * Resolves a React component, legacy headless renderer, or built-in overlay
498
+ * for the active state.
494
499
  */
495
500
  function renderOverlayContent(overlay) {
496
501
  if (!overlay || !overlay.type)
497
502
  return null;
498
- const customRenderer = optionsRef.current.overlayComponents?.[overlay.type];
499
- if (customRenderer) {
503
+ const registeredRenderer = typeof overlay.component === "string"
504
+ ? optionsRef.current.overlayComponents?.[overlay.component]
505
+ : optionsRef.current.overlayComponents?.[overlay.type];
506
+ const component = typeof overlay.component === "function" || (typeof overlay.component === "object" && overlay.component !== null)
507
+ ? overlay.component
508
+ : registeredRenderer;
509
+ const isLegacyRenderer = typeof component === "function" && component.length >= 2;
510
+ if (component && !isLegacyRenderer) {
511
+ return createElement(component, {
512
+ type: overlay.type,
513
+ message: overlay.message,
514
+ payload: overlay.payload,
515
+ state: grid.getState(),
516
+ });
517
+ }
518
+ const customRenderer = component ?? registeredRenderer;
519
+ if (isLegacyRenderer && typeof customRenderer === "function") {
500
520
  return contentToReactNode(customRenderer(overlay.payload, grid.getState()), {
501
521
  registry: slotComponentsRef.current,
502
522
  context: buildRenderContext,
503
523
  });
504
524
  }
505
- if (overlay.type === "custom") {
525
+ if (overlay.component !== undefined) {
506
526
  return contentToReactNode(overlay.payload, {
507
527
  registry: slotComponentsRef.current,
508
528
  context: buildRenderContext,
@@ -510,7 +530,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
510
530
  }
511
531
  return renderDefaultOverlay(overlay);
512
532
  }
513
- const overlayState = state.overlay;
514
533
  const pinnedLeftWidth = viewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
515
534
  const pinnedRightWidth = viewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
516
535
  const scrollableWidth = Math.max(0, viewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
@@ -528,6 +547,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
528
547
  // correctly on the horizontal axis because sticky positioning is not
529
548
  // affected by the clip.
530
549
  const needsHorizontalScroll = viewportData.totalWidth > grid.getState().viewport.width;
550
+ const overlayHeight = Math.max(0, (autoHeight ? measuredHeight : state.viewport.height) - headerHeight);
531
551
  const renderHeaderCells = (columns, originX) => columns.map((item) => {
532
552
  const deepestDepth = hasGroups ? (viewportData.columnGroupDepth.get(item.index) ?? -1) : -1;
533
553
  const gapRows = headerRowCount - 1 - deepestDepth;
@@ -609,14 +629,14 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
609
629
  top: headerHeight,
610
630
  width,
611
631
  } }));
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: {
632
+ 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
633
  ...viewportStyle,
614
634
  flex: "1 1 0",
615
635
  height: autoHeight ? measuredHeight : "100%",
616
636
  minHeight: 0,
617
637
  minWidth: 0,
618
- overflowX: needsHorizontalScroll ? "auto" : "hidden",
619
- overflowY: autoHeight ? "hidden" : "auto",
638
+ overflowX: overlayBlocksHorizontalScroll ? "hidden" : needsHorizontalScroll ? "auto" : "hidden",
639
+ overflowY: overlayScope || autoHeight ? "hidden" : "auto",
620
640
  position: "relative",
621
641
  scrollbarGutter: verticalScrollbarGutter,
622
642
  width: "100%",
@@ -645,13 +665,19 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
645
665
  top: 0,
646
666
  width: `${pinnedRightWidth}px`,
647
667
  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,
668
+ }, children: [renderHeader(viewportData.pinnedRightColumns, pinnedLeftWidth + scrollableWidth, `${pinnedRightWidth}px`, true), renderRowsLayer(pinnedRightRowsLayerRef, `${pinnedRightWidth}px`)] }))] }), overlayState.type && overlayScope === "bodyOnly" && (
669
+ // Keep the sticky overlay anchored to the body viewport without adding
670
+ // its height to the scrollable content's natural dimensions.
671
+ _jsx("div", { className: "omnigrid-overlay omnigrid-overlay-body", role: "status", style: {
672
+ height: overlayHeight,
650
673
  left: 0,
674
+ marginBottom: -overlayHeight,
675
+ marginTop: -rowTotalHeight,
651
676
  pointerEvents: "auto",
652
- position: "absolute",
677
+ position: "sticky",
653
678
  right: 0,
654
679
  top: headerHeight,
680
+ width: "100%",
655
681
  zIndex: 4,
656
- }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom")] }));
682
+ }, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
657
683
  }
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.13",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",