@omnigrid/react 0.1.37 → 0.1.38

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,42 @@ const data = [...];
22
22
  <OmniGrid columns={columns} data={data} />;
23
23
  ```
24
24
 
25
+ `columns` is optional. When omitted, the core creates one leaf column for each
26
+ own property of the first data row. If there are no rows yet, it waits for data.
27
+ The inferred schema stays fixed; call `grid.setColumns` when the schema changes.
28
+ By default, each header is the property key. Set
29
+ `autoColumnHeaderMode="title-case"` to split camel-case keys into capitalized
30
+ words. For custom formatting, use the core's `getColumnHeader` option:
31
+
32
+ ```tsx
33
+ <OmniGrid
34
+ data={data}
35
+ autoColumnHeaderMode="title-case"
36
+ />
37
+ <OmniGrid
38
+ data={data}
39
+ getColumnHeader={(field) => field.toUpperCase()}
40
+ />
41
+ ```
42
+
43
+ The grid fills its parent's available height by default. Give the parent a
44
+ constrained height (for example, in a flex layout) and the adapter measures the
45
+ actual viewport with `ResizeObserver`. Use `height` for a fixed grid height, or
46
+ set `sizingMode="auto"` to grow the grid with its rows. Supplying `height`
47
+ without `sizingMode` selects fixed sizing; explicitly setting
48
+ `sizingMode="fixed"` requires `height`:
49
+
50
+ ```tsx
51
+ <OmniGrid columns={columns} data={data} height={480} />
52
+ <OmniGrid columns={columns} data={data} sizingMode="auto" />
53
+ ```
54
+
55
+ `minHeight` applies only to auto-height grids. Auto-height renders the full row
56
+ content and should be avoided for large datasets when vertical virtualization
57
+ is needed. `style` remains available for CSS customization; use `height` and
58
+ `sizingMode` to select the grid's sizing behavior. A legacy `style.height` can
59
+ still size the outer element in fill mode, but it no longer selects auto-height.
60
+
25
61
  Set `animateRows` to animate visible rows when filtering or sorting changes their
26
62
  positions. Row animation uses a separate CSS transform component, so virtualized
27
63
  positioning and scrolling remain independent. It is disabled by default; provide
@@ -24,4 +24,4 @@ import type { GridProps } from "./types.js";
24
24
  * core's headless content; React components in slots are connected via
25
25
  * `slotComponents`.
26
26
  */
27
- export declare function OmniGrid<T>({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }: GridProps<T>): import("react").JSX.Element;
27
+ export declare function OmniGrid<T>({ className, style, height, sizingMode: sizingModeProp, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }: GridProps<T>): import("react").JSX.Element;
package/dist/OmniGrid.js CHANGED
@@ -76,7 +76,7 @@ function createRowLayerState() {
76
76
  * core's headless content; React components in slots are connected via
77
77
  * `slotComponents`.
78
78
  */
79
- export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }) {
79
+ export function OmniGrid({ className, style, height, sizingMode: sizingModeProp, slotComponents, cellTooltipRenderer, cellTooltipClassName, ...options }) {
80
80
  const { grid, state, viewportData } = useGrid(options);
81
81
  const columnTooltipOptions = useMemo(() => {
82
82
  const result = new Map();
@@ -179,7 +179,15 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
179
179
  grid.refresh();
180
180
  }
181
181
  }, [grid, options.rowClassRules]);
182
- const autoHeight = style?.height === undefined;
182
+ const sizingMode = sizingModeProp ?? (height !== undefined ? "fixed" : "fill");
183
+ if (sizingMode === "fixed" && height === undefined) {
184
+ throw new Error('OmniGrid requires the "height" prop when sizingMode is "fixed".');
185
+ }
186
+ const autoHeight = sizingMode === "auto";
187
+ const styleHeight = style?.height;
188
+ const gridStyle = { ...style };
189
+ delete gridStyle.height;
190
+ const layoutHeight = sizingMode === "fixed" ? height : sizingMode === "fill" ? (styleHeight ?? "100%") : undefined;
183
191
  const rowHeight = grid.getState().rowHeight;
184
192
  // Column-group header stack: `headerRowCount` group rows (one per depth) above
185
193
  // the leaf header row. Without groups `headerRowCount` is 0 and `columnGroupDepth`
@@ -241,8 +249,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
241
249
  const cellFlashRaw = options.cellFlash;
242
250
  const cellFlashDurationMs = cellFlashRaw === true ? 1000 : typeof cellFlashRaw === "number" && cellFlashRaw > 0 ? cellFlashRaw : false;
243
251
  const viewportStyle = {
244
- ...style,
245
- height: autoHeight ? measuredHeight : style?.height,
252
+ ...gridStyle,
246
253
  ...(cellFlashDurationMs !== false ? { "--omnigrid-flash-duration": `${cellFlashDurationMs}ms` } : {}),
247
254
  };
248
255
  const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null, suppressColumnBorders ? "omnigrid-no-column-borders" : null]
@@ -1019,7 +1026,7 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1019
1026
  // back to minWidth) and only snap to the correct size after the
1020
1027
  // ResizeObserver-driven useEffect runs — a visible flash on first load.
1021
1028
  measureViewport();
1022
- }, [autoHeight, hasVerticalOverflow, measureViewport, overlayScope]);
1029
+ }, [autoHeight, hasVerticalOverflow, height, measureViewport, overlayScope, sizingMode, styleHeight]);
1023
1030
  useEffect(() => {
1024
1031
  const unsubscribe = grid.on("scrollTo", (position) => {
1025
1032
  const element = viewportRef.current;
@@ -1440,6 +1447,10 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1440
1447
  top: 0,
1441
1448
  zIndex: isPinned ? 4 : 2,
1442
1449
  width,
1450
+ // Force own compositing layer to fix Edge 1px sticky shift during scroll
1451
+ transform: "translateZ(0)",
1452
+ willChange: "transform",
1453
+ backfaceVisibility: "hidden",
1443
1454
  }, children: _jsxs("div", { role: "rowgroup", children: [Array.from({ length: headerRowCount }, (_, depth) => (_jsx("div", { role: "row", className: "omnigrid-header-row omnigrid-header-group-row", style: {
1444
1455
  height: rowHeight,
1445
1456
  left: 0,
@@ -1465,8 +1476,18 @@ export function OmniGrid({ className, style, slotComponents, cellTooltipRenderer
1465
1476
  top: headerHeight,
1466
1477
  visibility: isViewportMeasured ? undefined : "hidden",
1467
1478
  width,
1479
+ // Force own compositing layer to fix Edge 1px sticky shift during scroll
1480
+ transform: "translateZ(0)",
1481
+ willChange: "transform",
1482
+ backfaceVisibility: "hidden",
1468
1483
  } }));
1469
- return (_jsxs("div", { className: "omnigrid-layout", ref: layoutRef, style: { ...style, position: "relative", ...(isFullOverlay ? { overflow: "hidden" } : {}) }, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { className: "omnigrid-viewport-container", style: {
1484
+ return (_jsxs("div", { className: "omnigrid-layout", ref: layoutRef, style: {
1485
+ ...gridStyle,
1486
+ height: layoutHeight,
1487
+ ...(sizingMode === "fill" ? { flex: "1 1 0", minHeight: 0 } : {}),
1488
+ position: "relative",
1489
+ ...(isFullOverlay ? { overflow: "hidden" } : {}),
1490
+ }, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"), _jsxs("div", { className: "omnigrid-viewport-container", style: {
1470
1491
  flex: "1 1 0",
1471
1492
  minHeight: 0,
1472
1493
  minWidth: 0,
package/dist/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type { CellTooltipRenderer, CellTooltipRenderContext, ReactCellRenderer,
5
5
  export { PooledRowPane } from "./pooledRow.js";
6
6
  export type { ContentBridge, PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./types.js";
7
7
  export { OmniGrid } from "./OmniGrid.js";
8
- export type { GridProps, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types.js";
8
+ export type { GridProps, GridSizingMode, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types.js";
9
9
  export { useGrid } from "./useGrid.js";
10
10
  export { DebouncedInput, isUIControlDescriptor, renderControl } from "./controls.js";
11
11
  export type { DebouncedInputProps } from "./controls.js";
@@ -65,6 +65,7 @@ export type ReactColumnDef<T> = ReactColumnLeafDef<T> | ReactColumnGroupDef<T>;
65
65
  * @api
66
66
  */
67
67
  export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns" | "defaultColumnDef"> & {
68
- columns: ReactColumnDef<T>[];
68
+ /** Column definitions; inferred from the first data row when omitted. @api */
69
+ columns?: ReactColumnDef<T>[];
69
70
  defaultColumnDef?: Partial<Omit<ReactColumnLeafDef<T>, "id" | "header">>;
70
71
  };
package/dist/types.d.ts CHANGED
@@ -85,14 +85,28 @@ export interface SlotRendererRegistry<T> {
85
85
  }
86
86
  export type OverlayComponentProps<T> = import("@omnigrid/core").OverlayComponentProps<T>;
87
87
  export type OverlayComponent<T> = import("react").ComponentType<import("@omnigrid/core").OverlayComponentProps<T>> | import("@omnigrid/core").OverlayComponent<T>;
88
- export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponents"> {
88
+ interface GridPropsBase<T> extends Omit<ReactGridOptions<T>, "overlayComponents"> {
89
89
  className?: string;
90
90
  style?: import("react").CSSProperties;
91
91
  /**
92
- * Minimum grid height in rows when `style.height` is not set (auto-height
93
- * mode). The viewport will be at least `headerHeight + minHeight *
94
- * rowHeight` tall so the grid does not collapse when it has few or no
95
- * rows. Set to `0` to disable.
92
+ * Height behavior. Defaults to `fill`, unless `height` is provided without
93
+ * an explicit mode, which selects `fixed`.
94
+ *
95
+ * @api
96
+ * @default "fill"
97
+ */
98
+ sizingMode?: GridSizingMode;
99
+ /**
100
+ * Explicit height for `fixed` sizing. When provided without `sizingMode`,
101
+ * the grid uses `fixed` sizing.
102
+ *
103
+ * @api
104
+ */
105
+ height?: import("react").CSSProperties["height"];
106
+ /**
107
+ * Minimum grid height in rows in `auto` sizing mode. The viewport will be
108
+ * at least `headerHeight + minHeight * rowHeight` tall so it does not
109
+ * collapse when it has few or no rows. Set to `0` to disable.
96
110
  *
97
111
  * @api
98
112
  * @default 3
@@ -113,6 +127,27 @@ export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponen
113
127
  slotComponents?: SlotRendererRegistry<T>;
114
128
  overlayComponents?: Record<string, import("@omnigrid/core").OverlayComponent<T>>;
115
129
  }
130
+ /**
131
+ * Controls how the grid obtains its height.
132
+ *
133
+ * @api
134
+ */
135
+ export type GridSizingMode = "fixed" | "fill" | "auto";
136
+ /**
137
+ * React adapter props with explicit grid sizing.
138
+ *
139
+ * @api
140
+ */
141
+ export type GridProps<T> = GridPropsBase<T> & ({
142
+ sizingMode: "fixed";
143
+ height: NonNullable<import("react").CSSProperties["height"]>;
144
+ } | {
145
+ sizingMode: "fill" | "auto";
146
+ height?: never;
147
+ } | {
148
+ sizingMode?: undefined;
149
+ height?: import("react").CSSProperties["height"];
150
+ });
116
151
  /**
117
152
  * Pre-resolved presentation (classes and inline styles) for a column data body.
118
153
  * Evaluated once per column across the dataset, then applied to each rendered cell in O(1).
@@ -125,3 +160,4 @@ export interface ResolvedColumnPresentation {
125
160
  /** Combined inline styles for the column body. */
126
161
  style: import("@omnigrid/core").ColumnStyle;
127
162
  }
163
+ export {};
package/dist/useGrid.js CHANGED
@@ -1,4 +1,4 @@
1
- import { isColumnGroup } from '@omnigrid/core';
1
+ import { inferColumns, isColumnGroup } from '@omnigrid/core';
2
2
  import { Grid } from '@omnigrid/core';
3
3
  import { useCallback, useEffect, useRef, useSyncExternalStore } from 'react';
4
4
  /**
@@ -29,6 +29,12 @@ export function useGrid(options) {
29
29
  const subscribe = useCallback((listener) => grid.subscribe(listener), [grid]);
30
30
  const getSnapshot = useCallback(() => grid.getState(), [grid]);
31
31
  const state = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
32
+ const autoColumnIdsRef = useRef(new Set());
33
+ useEffect(() => {
34
+ if (options.columns !== undefined || autoColumnIdsRef.current.size > 0 || state.data.length === 0)
35
+ return;
36
+ autoColumnIdsRef.current = new Set(inferColumns(state.data, options.getColumnHeader).map((column) => column.id));
37
+ }, [options.columns, options.getColumnHeader, state.data]);
32
38
  // Reconcile plugins when the plugin list changes. Plugins removed from the
33
39
  // list are unregistered (their cleanup restores default behavior); new ones
34
40
  // are registered. Declared before the data sync so that, on a switch, the
@@ -62,8 +68,8 @@ export function useGrid(options) {
62
68
  // Sync columns when the columns reference changes (e.g. dynamic column
63
69
  // definitions). Skip on the first run — plugins may have prepended
64
70
  // selection/sorting columns during registerPlugin() in the Grid
65
- // constructor, and calling setColumns here would overwrite those injected
66
- // columns. Only sync on subsequent changes to options.columns.
71
+ // constructor, and calling grid.setColumns here would overwrite those
72
+ // injected columns. Only sync on subsequent changes to options.columns.
67
73
  //
68
74
  // StrictMode note: `options.columns` is a new array reference on every
69
75
  // render, but its entries are usually the same column objects (a new
@@ -89,6 +95,7 @@ export function useGrid(options) {
89
95
  const columnsChanged = prev.length !== next.length || prev.some((column, index) => column !== next[index]);
90
96
  const defaultColumnDefChanged = lastSyncedDefaultColumnDefRef.current !== options.defaultColumnDef;
91
97
  if (columnsChanged || defaultColumnDefChanged) {
98
+ const previousColumnsWereAuto = lastSyncedColumnsRef.current === undefined;
92
99
  lastSyncedColumnsRef.current = options.columns;
93
100
  lastSyncedDefaultColumnDefRef.current = options.defaultColumnDef;
94
101
  // Merge the user's column definitions into the current (plugin-enriched)
@@ -97,6 +104,11 @@ export function useGrid(options) {
97
104
  // not part of the user's column definitions; replacing columns with the
98
105
  // raw definitions would strip them and break e.g. column resize handles.
99
106
  const current = grid.getState().columns;
107
+ const autoColumnIds = previousColumnsWereAuto && options.columns !== undefined
108
+ ? autoColumnIdsRef.current.size > 0
109
+ ? autoColumnIdsRef.current
110
+ : new Set(inferColumns(grid.getState().data, options.getColumnHeader).map((column) => column.id))
111
+ : new Set();
100
112
  // Merge the user's column definitions INTO the current (plugin-enriched)
101
113
  // columns instead of replacing them wholesale. Iterating over `current`
102
114
  // preserves plugin-injected columns (e.g. the selection column prepended
@@ -111,7 +123,8 @@ export function useGrid(options) {
111
123
  current.forEach((currentColumn) => {
112
124
  const userColumn = next.find((c) => c.id === currentColumn.id);
113
125
  if (!userColumn) {
114
- merged.push(currentColumn);
126
+ if (!autoColumnIds.has(currentColumn.id))
127
+ merged.push(currentColumn);
115
128
  return;
116
129
  }
117
130
  const enriched = { ...userColumn };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnigrid/react",
3
- "version": "0.1.37",
3
+ "version": "0.1.38",
4
4
  "description": "React adapter and renderer for OmniGrid",
5
5
  "keywords": [
6
6
  "omnigrid",