@omnigrid/react 0.1.25 → 0.1.27
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/OmniGrid.d.ts +1 -28
- package/dist/OmniGrid.js +90 -36
- package/dist/content.d.ts +3 -11
- package/dist/controls.d.ts +3 -4
- package/dist/groupCell.d.ts +53 -0
- package/dist/groupCell.js +201 -0
- package/dist/index.d.ts +5 -4
- package/dist/pooledRow.d.ts +2 -48
- package/dist/pooledRow.js +6 -2
- package/dist/popup.d.ts +1 -4
- package/dist/reactColumnDef.d.ts +39 -0
- package/dist/reactColumnDef.js +1 -0
- package/dist/styling.d.ts +2 -12
- package/dist/types.d.ts +108 -0
- package/dist/types.js +1 -0
- package/dist/useGrid.d.ts +3 -8
- package/package.json +54 -54
package/dist/OmniGrid.d.ts
CHANGED
|
@@ -1,30 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { GridOptions, OverlayComponent as CoreOverlayComponent, OverlayComponentProps as CoreOverlayComponentProps, SlotRenderContext } from "@omnigrid/core";
|
|
3
|
-
/**
|
|
4
|
-
* Registry of native adapter components for `SlotComponentContent`:
|
|
5
|
-
* slotComponents={{ ["my-widget"]: (payload, context) => <MyWidget .../> }}
|
|
6
|
-
*/
|
|
7
|
-
export interface SlotRendererRegistry<T> {
|
|
8
|
-
[kind: string]: (payload: unknown, context: SlotRenderContext<T>) => ReactNode;
|
|
9
|
-
}
|
|
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"> {
|
|
13
|
-
className?: string;
|
|
14
|
-
style?: CSSProperties;
|
|
15
|
-
/**
|
|
16
|
-
* Minimum grid height in rows when `style.height` is not set (auto-height
|
|
17
|
-
* mode). The viewport will be at least `headerHeight + minHeight *
|
|
18
|
-
* rowHeight` tall so the grid does not collapse when it has few or no
|
|
19
|
-
* rows. Set to `0` to disable.
|
|
20
|
-
*
|
|
21
|
-
* @api
|
|
22
|
-
* @default 3
|
|
23
|
-
*/
|
|
24
|
-
minHeight?: number;
|
|
25
|
-
slotComponents?: SlotRendererRegistry<T>;
|
|
26
|
-
overlayComponents?: Record<string, OverlayComponent<T>>;
|
|
27
|
-
}
|
|
1
|
+
import type { GridProps } from "./types";
|
|
28
2
|
/**
|
|
29
3
|
* React adapter over the headless core.
|
|
30
4
|
*
|
|
@@ -51,4 +25,3 @@ export interface GridProps<T> extends Omit<GridOptions<T>, "overlayComponents">
|
|
|
51
25
|
* `slotComponents`.
|
|
52
26
|
*/
|
|
53
27
|
export declare function OmniGrid<T>({ className, style, slotComponents, ...options }: GridProps<T>): import("react").JSX.Element;
|
|
54
|
-
export {};
|
package/dist/OmniGrid.js
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { createElement, 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, isActiveCondition } from "@omnigrid/core";
|
|
5
5
|
import { contentToReactNode, hasRenderableContent } from "./content";
|
|
6
6
|
import { computeGroupSegments } from "./groupHeader";
|
|
7
|
+
import { getCollapsedGroupDisplay, getGroupColumnRole, poolGetRowId, renderGroupCellContent, renderGroupCellPlaceholder } from "./groupCell";
|
|
7
8
|
import { PooledRowPane } from "./pooledRow";
|
|
8
9
|
import { createCellRoot } from "./reactRoot";
|
|
9
10
|
import { renderDefaultOverlay } from "./overlays";
|
|
10
11
|
import { PopupHost } from "./popup";
|
|
11
12
|
import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
|
12
13
|
import { useGrid } from "./useGrid";
|
|
14
|
+
function getRowRenderParams(row) {
|
|
15
|
+
if (row.type === "group") {
|
|
16
|
+
return { id: row.rowId, index: row.index, rowType: "group" };
|
|
17
|
+
}
|
|
18
|
+
return { id: row.rowId, index: row.index, rowType: "leaf", data: row.data };
|
|
19
|
+
}
|
|
13
20
|
function getCellValue(row, column) {
|
|
14
21
|
if (column.valueGetter)
|
|
15
22
|
return column.valueGetter(row);
|
|
@@ -18,6 +25,10 @@ function getCellValue(row, column) {
|
|
|
18
25
|
return row[column.field];
|
|
19
26
|
return undefined;
|
|
20
27
|
}
|
|
28
|
+
/** Returns the flat row array the virtualizer pools against: grouped rows when grouping, else raw data. */
|
|
29
|
+
function getPoolData(grid) {
|
|
30
|
+
return grid.getRows();
|
|
31
|
+
}
|
|
21
32
|
const SLOT_POSITIONS = ["start", "center", "end"];
|
|
22
33
|
/**
|
|
23
34
|
* Scroll velocity (px/ms) above which a scroll is treated as "fast".
|
|
@@ -83,7 +94,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
83
94
|
const pinnedRightRowsLayerRef = useRef(null);
|
|
84
95
|
/** Space taken by the viewport's native scrollbars; body slots stay clear of it. */
|
|
85
96
|
const [scrollbarInsets, setScrollbarInsets] = useState({ right: 0, bottom: 0 });
|
|
86
|
-
const scrollFrameRef = useRef({
|
|
97
|
+
const scrollFrameRef = useRef({
|
|
98
|
+
id: 0,
|
|
99
|
+
top: 0,
|
|
100
|
+
left: 0,
|
|
101
|
+
lastTop: 0,
|
|
102
|
+
lastTime: 0,
|
|
103
|
+
});
|
|
87
104
|
const scrollVelocityRef = useRef(0);
|
|
88
105
|
/** Timestamp of the last processed scroll frame — used to age out the velocity. */
|
|
89
106
|
const lastScrollTimeRef = useRef(0);
|
|
@@ -231,9 +248,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
231
248
|
const overlayScope = overlayState.type
|
|
232
249
|
? (overlayState.scope ?? (overlayState.type === "error" ? "full" : "bodyOnly"))
|
|
233
250
|
: undefined;
|
|
234
|
-
const overlayBlocksHorizontalScroll = overlayState.type
|
|
235
|
-
? (overlayState.blockScroll ?? false)
|
|
236
|
-
: false;
|
|
251
|
+
const overlayBlocksHorizontalScroll = overlayState.type ? (overlayState.blockScroll ?? false) : false;
|
|
237
252
|
const isFullOverlay = overlayScope === "full";
|
|
238
253
|
/**
|
|
239
254
|
* Bridge between the core's headless content and React: a factory for the
|
|
@@ -524,30 +539,49 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
524
539
|
scheduleHeightFlush();
|
|
525
540
|
},
|
|
526
541
|
renderCellContent: (info) => {
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
542
|
+
const groupContent = renderGroupCellContent(info, bridgeArg, grid);
|
|
543
|
+
if (groupContent !== undefined) {
|
|
544
|
+
return groupContent;
|
|
545
|
+
}
|
|
546
|
+
const rawData = (info.data && typeof info.data === "object" && "data" in info.data
|
|
547
|
+
? info.data.data
|
|
548
|
+
: info.data);
|
|
549
|
+
// When a leaf row is displayed as a collapsed single-child group,
|
|
550
|
+
// show the grouping field's value in the group column instead of
|
|
551
|
+
// the row's own field value.
|
|
552
|
+
const collapsedGroupDisplay = getCollapsedGroupDisplay(info.data, info.column, grid.getState().groupBy ?? [], grid.getState().groupColumnMode ?? "single");
|
|
553
|
+
const value = collapsedGroupDisplay !== undefined ? collapsedGroupDisplay.value : getCellValue(rawData, info.column);
|
|
554
|
+
const content = info.column.cellRenderer
|
|
555
|
+
? info.column.cellRenderer({ value, data: rawData, column: info.column, id: info.rowId, index: info.rowIndex })
|
|
556
|
+
: info.column.valueFormatter
|
|
557
|
+
? info.column.valueFormatter(value)
|
|
558
|
+
: String(value ?? "");
|
|
559
|
+
if (collapsedGroupDisplay && grid.getState().groupColumnMode === "single") {
|
|
560
|
+
return createElement("span", { style: { paddingLeft: collapsedGroupDisplay.level * 20 } }, contentToReactNode(content, bridgeArg));
|
|
531
561
|
}
|
|
532
|
-
return
|
|
562
|
+
return content;
|
|
533
563
|
},
|
|
534
564
|
renderCellPlaceholder: (info) => {
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
565
|
+
const groupPlaceholder = renderGroupCellPlaceholder(info, grid);
|
|
566
|
+
if (groupPlaceholder !== undefined) {
|
|
567
|
+
return groupPlaceholder;
|
|
568
|
+
}
|
|
569
|
+
const rawData = (info.data && typeof info.data === "object" && "data" in info.data
|
|
570
|
+
? info.data.data
|
|
571
|
+
: info.data);
|
|
572
|
+
const collapsedGroupDisplay = getCollapsedGroupDisplay(info.data, info.column, grid.getState().groupBy ?? [], grid.getState().groupColumnMode ?? "single");
|
|
573
|
+
const value = collapsedGroupDisplay !== undefined ? collapsedGroupDisplay.value : getCellValue(rawData, info.column);
|
|
574
|
+
if (info.column.valueFormatter)
|
|
575
|
+
return info.column.valueFormatter(value);
|
|
544
576
|
const valueType = typeof value;
|
|
545
577
|
if (valueType === "string" || valueType === "number" || valueType === "boolean")
|
|
546
578
|
return String(value);
|
|
547
579
|
return null;
|
|
548
580
|
},
|
|
549
581
|
resolveRowClasses: (row) => {
|
|
550
|
-
const
|
|
582
|
+
const isGroup = row.type === "group";
|
|
583
|
+
const base = isGroup ? "omnigrid-row omnigrid-row-group" : "omnigrid-row";
|
|
584
|
+
const rowParams = getRowRenderParams(row);
|
|
551
585
|
const currentOptions = current();
|
|
552
586
|
const rowClass = typeof currentOptions.rowClass === "function" ? currentOptions.rowClass(rowParams) : currentOptions.rowClass;
|
|
553
587
|
const dynamicRowClass = currentOptions.getRowClass?.(rowParams);
|
|
@@ -557,10 +591,10 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
557
591
|
const pluginClasses = (currentOptions.plugins ?? [])
|
|
558
592
|
.map((plugin) => plugin.getRowClass?.(rowParams))
|
|
559
593
|
.filter((rowClass) => Boolean(rowClass));
|
|
560
|
-
return [
|
|
594
|
+
return [base, rowClass, ...ruleClasses, dynamicRowClass, ...pluginClasses].filter(Boolean).join(" ");
|
|
561
595
|
},
|
|
562
596
|
resolveRowStyle: (row) => {
|
|
563
|
-
const rowParams =
|
|
597
|
+
const rowParams = getRowRenderParams(row);
|
|
564
598
|
const currentOptions = current();
|
|
565
599
|
const baseRowStyle = {
|
|
566
600
|
...(currentOptions.rowStyle ?? {}),
|
|
@@ -602,24 +636,40 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
602
636
|
const columnPresentation = getColumnPresentation(info.column);
|
|
603
637
|
return resolveCellStyle(info.column, cellParams, columnPresentation.style);
|
|
604
638
|
},
|
|
605
|
-
onRowClick: (row, modifiers) =>
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
639
|
+
onRowClick: (row, modifiers) => {
|
|
640
|
+
if (row.type === "group") {
|
|
641
|
+
if (row.group && typeof grid.toggleGroup === "function") {
|
|
642
|
+
grid.toggleGroup(row.group.id);
|
|
643
|
+
}
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
grid.rowClick({
|
|
647
|
+
id: row.rowId,
|
|
648
|
+
index: row.index,
|
|
649
|
+
rowType: "leaf",
|
|
650
|
+
data: row.data,
|
|
651
|
+
ctrlKey: modifiers.ctrlKey,
|
|
652
|
+
shiftKey: modifiers.shiftKey,
|
|
653
|
+
});
|
|
654
|
+
},
|
|
612
655
|
onRowHover: (row, hovered) => {
|
|
613
656
|
const rowElements = viewportRef.current?.querySelectorAll(`[data-row-index="${row.index}"]`);
|
|
614
657
|
rowElements?.forEach((element) => element.classList.toggle("omnigrid-row-hover", hovered));
|
|
615
|
-
grid.rowHover({
|
|
658
|
+
grid.rowHover({ ...getRowRenderParams(row), hovered });
|
|
616
659
|
},
|
|
617
660
|
onCellClick: (row, column, modifiers) => {
|
|
618
661
|
if (column.stopRowClick)
|
|
619
662
|
return;
|
|
663
|
+
if (row.type === "group") {
|
|
664
|
+
if (row.group && typeof grid.toggleGroup === "function") {
|
|
665
|
+
grid.toggleGroup(row.group.id);
|
|
666
|
+
}
|
|
667
|
+
return;
|
|
668
|
+
}
|
|
620
669
|
grid.rowClick({
|
|
621
670
|
id: row.rowId,
|
|
622
671
|
index: row.index,
|
|
672
|
+
rowType: "leaf",
|
|
623
673
|
data: row.data,
|
|
624
674
|
ctrlKey: modifiers.ctrlKey,
|
|
625
675
|
shiftKey: modifiers.shiftKey,
|
|
@@ -645,7 +695,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
645
695
|
const { paneMap, panes } = layer;
|
|
646
696
|
layer.pool = new DomPool({
|
|
647
697
|
rowHeight,
|
|
648
|
-
getRowId: (row, index) => grid
|
|
698
|
+
getRowId: (row, index) => poolGetRowId(grid, row, index),
|
|
649
699
|
bindings: {
|
|
650
700
|
createRow: () => {
|
|
651
701
|
const element = document.createElement("div");
|
|
@@ -714,7 +764,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
714
764
|
if (!pool || grid.isDestroyed())
|
|
715
765
|
return;
|
|
716
766
|
const state = grid.getState();
|
|
717
|
-
const processed = grid
|
|
767
|
+
const processed = getPoolData(grid);
|
|
718
768
|
const changed = layer.revision !== grid.getRevision() || layer.totalWidth !== viewportData.totalWidth || layer.processed !== processed;
|
|
719
769
|
if (changed) {
|
|
720
770
|
layer.revision = grid.getRevision();
|
|
@@ -1067,7 +1117,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
1067
1117
|
if (groups.every((group) => group === null))
|
|
1068
1118
|
return null;
|
|
1069
1119
|
const slotClass = slot === "down" ? "omnigrid-slot omnigrid-slot-bottom omnigrid-slot-down" : `omnigrid-slot omnigrid-slot-${slot}`;
|
|
1070
|
-
return
|
|
1120
|
+
return _jsx("div", { className: slotClass, children: groups });
|
|
1071
1121
|
};
|
|
1072
1122
|
/** Renders slots that overlay the table body (absolute positioning, no layout shift). */
|
|
1073
1123
|
const renderBodySlot = (slot) => {
|
|
@@ -1172,9 +1222,13 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
1172
1222
|
}, tabIndex: 0, style: headerCellLayout, children: item.column.headerRenderer ? (contentToReactNode(item.column.headerRenderer(item.column), {
|
|
1173
1223
|
registry: slotComponentsRef.current,
|
|
1174
1224
|
context: buildRenderContext,
|
|
1175
|
-
})) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "omnigrid-header-label", children: item.column
|
|
1176
|
-
|
|
1177
|
-
|
|
1225
|
+
})) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "omnigrid-header-label", children: getGroupColumnRole(item.column, grid.getState().groupBy, grid.getState().groupColumnMode).isGroupColumn &&
|
|
1226
|
+
grid.getState().groupColumnMode === "single"
|
|
1227
|
+
? grid.getState().groupColumnHeader
|
|
1228
|
+
: (item.column.header ?? item.column.id) }), _jsxs("span", { className: "omnigrid-header-tools", children: [item.column.sortState && (_jsxs("span", { className: "omnigrid-sort-indicator", "aria-hidden": "true", children: [contentToReactNode(item.column.sortState === "asc" ? grid.icons.get("arrow-up") : grid.icons.get("arrow-down"), {
|
|
1229
|
+
registry: slotComponentsRef.current,
|
|
1230
|
+
context: buildRenderContext,
|
|
1231
|
+
}), item.column.sortIndex !== undefined && _jsx("span", { className: "omnigrid-sort-priority", children: item.column.sortIndex })] })), grid.hasFilterMenu() && item.column.filterable !== false && (_jsx("button", { type: "button", className: "omnigrid-filter-trigger", "data-omnigrid-filter-trigger": "", "data-active": isColumnFiltered(item.column) ? "true" : undefined, "aria-label": `Filter ${item.column.header ?? item.column.id}`, "aria-haspopup": "dialog", tabIndex: -1, onClick: (event) => {
|
|
1178
1232
|
event.stopPropagation();
|
|
1179
1233
|
const rect = event.currentTarget.getBoundingClientRect();
|
|
1180
1234
|
const layoutRect = layoutRef.current?.getBoundingClientRect() ?? { left: 0, top: 0, width: 0, height: 0 };
|
package/dist/content.d.ts
CHANGED
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type { CheckboxControl, SlotNodeContent
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* `registry` — registry of React components for `SlotComponentContent`;
|
|
6
|
-
* `context()` — factory for the current render context so providers see
|
|
7
|
-
* up-to-date grid state at render time.
|
|
8
|
-
*/
|
|
9
|
-
export interface ContentBridge<T> {
|
|
10
|
-
registry: Record<string, (payload: unknown, context: SlotRenderContext<T>) => ReactNode>;
|
|
11
|
-
context: () => SlotRenderContext<T>;
|
|
12
|
-
}
|
|
2
|
+
import type { CheckboxControl, SlotNodeContent } from "@omnigrid/core";
|
|
3
|
+
import type { ContentBridge } from "./types";
|
|
4
|
+
export type { ContentBridge };
|
|
13
5
|
export declare function isCheckboxControl(value: unknown): value is CheckboxControl;
|
|
14
6
|
export declare function isSlotHtmlContent(value: unknown): value is {
|
|
15
7
|
type: "html";
|
package/dist/controls.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type { UIControlDescriptor
|
|
2
|
+
import type { UIControlDescriptor } from "@omnigrid/core";
|
|
3
|
+
import type { DebouncedInputProps } from "./types";
|
|
4
|
+
export type { DebouncedInputProps };
|
|
3
5
|
/** Type guard for core `UIControlDescriptor` objects. */
|
|
4
6
|
export declare function isUIControlDescriptor(value: unknown): value is UIControlDescriptor;
|
|
5
|
-
export interface DebouncedInputProps {
|
|
6
|
-
descriptor: UIInputControl;
|
|
7
|
-
}
|
|
8
7
|
/**
|
|
9
8
|
* Text/number input that keeps typing in local state and forwards the value to
|
|
10
9
|
* the descriptor callback after `debounceMs` of inactivity. Pending input is
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { ColumnLeafDef, GridApi, GroupRowNode, RowId } from "@omnigrid/core";
|
|
3
|
+
import { type ContentBridge } from "./content";
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether an arbitrary row node represents a grouping tree node.
|
|
6
|
+
*
|
|
7
|
+
* @api
|
|
8
|
+
*/
|
|
9
|
+
export declare function isGroupRowNode<T>(row: unknown): row is GroupRowNode<T>;
|
|
10
|
+
/**
|
|
11
|
+
* Stable row id resolver for pooled rows: tree nodes expose their stable `id` path,
|
|
12
|
+
* whereas regular data rows resolve via `grid.getRowId`.
|
|
13
|
+
*
|
|
14
|
+
* @api
|
|
15
|
+
*/
|
|
16
|
+
export declare function poolGetRowId<T>(grid: GridApi<T>, row: unknown, index: number): RowId;
|
|
17
|
+
/**
|
|
18
|
+
* Determines whether a column functions as the group column for a row level.
|
|
19
|
+
*/
|
|
20
|
+
export declare function getGroupColumnRole<T>(column: ColumnLeafDef<T>, groupBy: string[], mode: "single" | "perLevel"): {
|
|
21
|
+
isGroupColumn: boolean;
|
|
22
|
+
level: number | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Returns the grouping value for a leaf row collapsed from a single-child group
|
|
26
|
+
* when the current column is the appropriate display column for the mode.
|
|
27
|
+
*
|
|
28
|
+
* @api
|
|
29
|
+
*/
|
|
30
|
+
export declare function getCollapsedGroupDisplay<T>(row: unknown, column: ColumnLeafDef<T>, groupBy: string[], mode: "single" | "perLevel"): {
|
|
31
|
+
value: string;
|
|
32
|
+
level: number;
|
|
33
|
+
} | undefined;
|
|
34
|
+
export interface CellRenderInfo<T> {
|
|
35
|
+
rowId: RowId;
|
|
36
|
+
rowIndex: number;
|
|
37
|
+
column: ColumnLeafDef<T>;
|
|
38
|
+
data: unknown;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Renders cell content when grouping is active (either group header row or indented leaf).
|
|
42
|
+
* Returns undefined when cell does not require grouping-specific rendering.
|
|
43
|
+
*
|
|
44
|
+
* @api
|
|
45
|
+
*/
|
|
46
|
+
export declare function renderGroupCellContent<T>(info: CellRenderInfo<T>, bridgeArg: ContentBridge<T>, grid: GridApi<T>): ReactNode | undefined;
|
|
47
|
+
/**
|
|
48
|
+
* Generates placeholder text for group rows during fast scrolling.
|
|
49
|
+
* Returns undefined when standard placeholder should be used.
|
|
50
|
+
*
|
|
51
|
+
* @api
|
|
52
|
+
*/
|
|
53
|
+
export declare function renderGroupCellPlaceholder<T>(info: CellRenderInfo<T>, grid: GridApi<T>): string | undefined;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { createElement } from "react";
|
|
2
|
+
import { contentToReactNode } from "./content";
|
|
3
|
+
/**
|
|
4
|
+
* Checks whether an arbitrary row node represents a grouping tree node.
|
|
5
|
+
*
|
|
6
|
+
* @api
|
|
7
|
+
*/
|
|
8
|
+
export function isGroupRowNode(row) {
|
|
9
|
+
return Boolean(row && typeof row === "object" && "type" in row && row.type === "group");
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Stable row id resolver for pooled rows: tree nodes expose their stable `id` path,
|
|
13
|
+
* whereas regular data rows resolve via `grid.getRowId`.
|
|
14
|
+
*
|
|
15
|
+
* @api
|
|
16
|
+
*/
|
|
17
|
+
export function poolGetRowId(grid, row, index) {
|
|
18
|
+
if (row && typeof row === "object" && "id" in row && "type" in row) {
|
|
19
|
+
return row.id;
|
|
20
|
+
}
|
|
21
|
+
return grid.getRowId(row, index);
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Determines whether a column functions as the group column for a row level.
|
|
25
|
+
*/
|
|
26
|
+
export function getGroupColumnRole(column, groupBy, mode) {
|
|
27
|
+
if (!groupBy || groupBy.length === 0)
|
|
28
|
+
return { isGroupColumn: false, level: null };
|
|
29
|
+
const match = (field) => column.id === field || column.field === field;
|
|
30
|
+
if (mode === "single") {
|
|
31
|
+
return match(groupBy[0]) ? { isGroupColumn: true, level: null } : { isGroupColumn: false, level: null };
|
|
32
|
+
}
|
|
33
|
+
for (let level = 0; level < groupBy.length; level += 1) {
|
|
34
|
+
if (match(groupBy[level]))
|
|
35
|
+
return { isGroupColumn: true, level };
|
|
36
|
+
}
|
|
37
|
+
return { isGroupColumn: false, level: null };
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns the grouping value for a leaf row collapsed from a single-child group
|
|
41
|
+
* when the current column is the appropriate display column for the mode.
|
|
42
|
+
*
|
|
43
|
+
* @api
|
|
44
|
+
*/
|
|
45
|
+
export function getCollapsedGroupDisplay(row, column, groupBy, mode) {
|
|
46
|
+
if (!row || typeof row !== "object" || !("collapsedGroup" in row))
|
|
47
|
+
return undefined;
|
|
48
|
+
const collapsedGroup = row.collapsedGroup;
|
|
49
|
+
if (!collapsedGroup)
|
|
50
|
+
return undefined;
|
|
51
|
+
const displayValue = mode === "single"
|
|
52
|
+
? getGroupColumnRole(column, groupBy, mode).isGroupColumn
|
|
53
|
+
: column.id === collapsedGroup.field || column.field === collapsedGroup.field;
|
|
54
|
+
return displayValue ? { value: collapsedGroup.key, level: collapsedGroup.level } : undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Renders cell content when grouping is active (either group header row or indented leaf).
|
|
58
|
+
* Returns undefined when cell does not require grouping-specific rendering.
|
|
59
|
+
*
|
|
60
|
+
* @api
|
|
61
|
+
*/
|
|
62
|
+
export function renderGroupCellContent(info, bridgeArg, grid) {
|
|
63
|
+
const column = info.column;
|
|
64
|
+
const node = info.data;
|
|
65
|
+
const state = grid.getState();
|
|
66
|
+
const groupBy = state.groupBy ?? [];
|
|
67
|
+
const mode = state.groupColumnMode ?? "single";
|
|
68
|
+
const showGroupValues = false;
|
|
69
|
+
const showChildCount = state.showChildCount ?? true;
|
|
70
|
+
const groupRowRenderer = state.groupRowRenderer;
|
|
71
|
+
if (isGroupRowNode(node)) {
|
|
72
|
+
const role = getGroupColumnRole(column, groupBy, mode);
|
|
73
|
+
if (role.isGroupColumn) {
|
|
74
|
+
const level = node.level;
|
|
75
|
+
if (mode !== "single" && role.level !== node.level)
|
|
76
|
+
return null;
|
|
77
|
+
const chevronName = node.expanded ? "chevron-down" : "chevron-right";
|
|
78
|
+
const icon = contentToReactNode(bridgeArg.context().api.icons.get(chevronName), bridgeArg);
|
|
79
|
+
if (groupRowRenderer) {
|
|
80
|
+
const rendered = groupRowRenderer({
|
|
81
|
+
node: node,
|
|
82
|
+
column,
|
|
83
|
+
id: info.rowId,
|
|
84
|
+
index: info.rowIndex,
|
|
85
|
+
api: grid,
|
|
86
|
+
state,
|
|
87
|
+
});
|
|
88
|
+
return contentToReactNode(rendered, bridgeArg);
|
|
89
|
+
}
|
|
90
|
+
if (showChildCount) {
|
|
91
|
+
return createElement("span", {
|
|
92
|
+
style: { paddingLeft: mode === "single" ? level * 20 : 0, display: "flex", alignItems: "center", gap: 6 },
|
|
93
|
+
title: String(node.key),
|
|
94
|
+
}, icon, " ", node.key, " (", node.childrenCount, ")");
|
|
95
|
+
}
|
|
96
|
+
return createElement("span", {
|
|
97
|
+
style: { paddingLeft: mode === "single" ? level * 20 : 0, display: "flex", alignItems: "center", gap: 6 },
|
|
98
|
+
title: String(node.key),
|
|
99
|
+
}, icon, " ", node.key);
|
|
100
|
+
}
|
|
101
|
+
if (column.cellRenderer) {
|
|
102
|
+
const value = node.aggregations[column.id];
|
|
103
|
+
const rendered = column.cellRenderer({
|
|
104
|
+
value,
|
|
105
|
+
data: undefined,
|
|
106
|
+
column,
|
|
107
|
+
id: info.rowId,
|
|
108
|
+
index: info.rowIndex,
|
|
109
|
+
});
|
|
110
|
+
const content = contentToReactNode(rendered, bridgeArg);
|
|
111
|
+
if (column.valueFormatter && typeof value === "number") {
|
|
112
|
+
const formatted = column.valueFormatter(value);
|
|
113
|
+
// For numeric aggregations, prefer formatted output if renderer returns simple value
|
|
114
|
+
}
|
|
115
|
+
return content;
|
|
116
|
+
}
|
|
117
|
+
// Non-group column within a group row: show pre-computed aggregate.
|
|
118
|
+
const value = node.aggregations[column.id];
|
|
119
|
+
return column.valueFormatter ? column.valueFormatter(value) : String(value ?? "");
|
|
120
|
+
}
|
|
121
|
+
if (getCollapsedGroupDisplay(node, column, groupBy, mode) !== undefined)
|
|
122
|
+
return undefined;
|
|
123
|
+
if (groupBy.length > 0 && mode === "single") {
|
|
124
|
+
const role = getGroupColumnRole(column, groupBy, mode);
|
|
125
|
+
if (role.isGroupColumn) {
|
|
126
|
+
return createElement("span", { style: { paddingLeft: node.level * 20 } });
|
|
127
|
+
}
|
|
128
|
+
const isGroupField = groupBy.some((g) => column.id === g || column.field === g);
|
|
129
|
+
if (isGroupField) {
|
|
130
|
+
return createElement("span");
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (groupBy.length > 0 && mode === "perLevel") {
|
|
134
|
+
const role = getGroupColumnRole(column, groupBy, mode);
|
|
135
|
+
if (role.isGroupColumn && !showGroupValues) {
|
|
136
|
+
return createElement("span");
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Generates placeholder text for group rows during fast scrolling.
|
|
143
|
+
* Returns undefined when standard placeholder should be used.
|
|
144
|
+
*
|
|
145
|
+
* @api
|
|
146
|
+
*/
|
|
147
|
+
export function renderGroupCellPlaceholder(info, grid) {
|
|
148
|
+
const column = info.column;
|
|
149
|
+
const node = info.data;
|
|
150
|
+
const state = grid.getState();
|
|
151
|
+
const groupBy = state.groupBy ?? [];
|
|
152
|
+
const mode = state.groupColumnMode ?? "single";
|
|
153
|
+
const showGroupValues = false;
|
|
154
|
+
const showChildCount = state.showChildCount ?? true;
|
|
155
|
+
const groupRowRenderer = state.groupRowRenderer;
|
|
156
|
+
if (isGroupRowNode(node)) {
|
|
157
|
+
const role = getGroupColumnRole(column, groupBy, mode);
|
|
158
|
+
if (role.isGroupColumn) {
|
|
159
|
+
const level = node.level;
|
|
160
|
+
if (mode !== "single" && role.level !== node.level)
|
|
161
|
+
return "";
|
|
162
|
+
if (groupRowRenderer) {
|
|
163
|
+
const rendered = groupRowRenderer({
|
|
164
|
+
node: node,
|
|
165
|
+
column,
|
|
166
|
+
id: info.rowId,
|
|
167
|
+
index: info.rowIndex,
|
|
168
|
+
api: grid,
|
|
169
|
+
state,
|
|
170
|
+
});
|
|
171
|
+
if (typeof rendered === "string" || typeof rendered === "number" || typeof rendered === "boolean") {
|
|
172
|
+
return String(rendered);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (showChildCount) {
|
|
176
|
+
return `${node.expanded ? "▼" : "▶"} ${node.key} (${node.childrenCount})`;
|
|
177
|
+
}
|
|
178
|
+
return `${node.expanded ? "▼" : "▶"} ${node.key}`;
|
|
179
|
+
}
|
|
180
|
+
if (column.cellRenderer)
|
|
181
|
+
return undefined;
|
|
182
|
+
const value = node.aggregations[column.id];
|
|
183
|
+
return column.valueFormatter ? column.valueFormatter(value) : String(value ?? "");
|
|
184
|
+
}
|
|
185
|
+
if (getCollapsedGroupDisplay(node, column, groupBy, mode) !== undefined)
|
|
186
|
+
return undefined;
|
|
187
|
+
if (groupBy.length > 0 && mode === "single") {
|
|
188
|
+
const role = getGroupColumnRole(column, groupBy, mode);
|
|
189
|
+
if (role.isGroupColumn)
|
|
190
|
+
return "";
|
|
191
|
+
const isGroupField = groupBy.some((g) => column.id === g || column.field === g);
|
|
192
|
+
if (isGroupField)
|
|
193
|
+
return "";
|
|
194
|
+
}
|
|
195
|
+
if (groupBy.length > 0 && mode === "perLevel") {
|
|
196
|
+
const role = getGroupColumnRole(column, groupBy, mode);
|
|
197
|
+
if (role.isGroupColumn && !showGroupValues)
|
|
198
|
+
return "";
|
|
199
|
+
}
|
|
200
|
+
return undefined;
|
|
201
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import "@omnigrid/style";
|
|
2
2
|
import "@omnigrid/default-theme";
|
|
3
3
|
export * from "@omnigrid/core";
|
|
4
|
+
export type { ReactCellRenderer, ReactColumnDef, ReactColumnDef as ColumnDef, ReactColumnGroupDef, ReactColumnGroupDef as ColumnGroupDef, ReactColumnLeafDef, ReactColumnLeafDef as ColumnLeafDef, ReactGridOptions, ReactGridOptions as GridOptions, } from "./reactColumnDef";
|
|
4
5
|
export { PooledRowPane } from "./pooledRow";
|
|
5
|
-
export type { PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./
|
|
6
|
+
export type { ContentBridge, PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowModifiers } from "./types";
|
|
6
7
|
export { OmniGrid } from "./OmniGrid";
|
|
7
|
-
export type { GridProps, OverlayComponentProps, SlotRendererRegistry } from "./
|
|
8
|
+
export type { GridProps, OverlayComponent, OverlayComponentProps, SlotRendererRegistry } from "./types";
|
|
8
9
|
export { useGrid } from "./useGrid";
|
|
9
10
|
export { DebouncedInput, isUIControlDescriptor, renderControl } from "./controls";
|
|
10
11
|
export type { DebouncedInputProps } from "./controls";
|
|
11
12
|
export { PopupHost } from "./popup";
|
|
12
|
-
export type { PopupHostProps } from "./
|
|
13
|
-
export type { UseGridResult } from "./
|
|
13
|
+
export type { PopupHostProps } from "./types";
|
|
14
|
+
export type { UseGridResult } from "./types";
|
|
14
15
|
export { type ResolvedColumnPresentation, resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
package/dist/pooledRow.d.ts
CHANGED
|
@@ -1,52 +1,6 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { PooledRow, RowSpanLayout } from "@omnigrid/core";
|
|
2
2
|
import { type ContentBridge } from "./content";
|
|
3
|
-
import type {
|
|
4
|
-
/** Column within the pool: definition + geometry from the virtual window. */
|
|
5
|
-
export type PooledColumn<T> = ViewportData<T>["columns"][number];
|
|
6
|
-
export interface PooledCellRenderInfo<T> {
|
|
7
|
-
data: T;
|
|
8
|
-
column: ColumnLeafDef<T>;
|
|
9
|
-
columnIndex: number;
|
|
10
|
-
rowId: RowId;
|
|
11
|
-
rowIndex: number;
|
|
12
|
-
/**
|
|
13
|
-
* Normalized horizontal span of this cell (`1` = plain cell).
|
|
14
|
-
* Span origins render the merged width; covered cells are skipped.
|
|
15
|
-
*/
|
|
16
|
-
colSpan: number;
|
|
17
|
-
}
|
|
18
|
-
export interface PooledRowModifiers {
|
|
19
|
-
ctrlKey: boolean;
|
|
20
|
-
shiftKey: boolean;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Injected back-channel: the row panel does NOT know about grid/adapter —
|
|
24
|
-
* it only fires these callbacks. This allows the panel to be reused across
|
|
25
|
-
* any adapter with a DOM environment.
|
|
26
|
-
*/
|
|
27
|
-
export interface PooledRowCallbacks<T> {
|
|
28
|
-
rowHeight: number;
|
|
29
|
-
renderCellContent(info: PooledCellRenderInfo<T>): unknown;
|
|
30
|
-
resolveRowClasses(row: PooledRow<T>): string | undefined;
|
|
31
|
-
resolveRowStyle(row: PooledRow<T>): RowStyle | undefined;
|
|
32
|
-
resolveCellClasses(cellInfo: PooledCellRenderInfo<T>): string | undefined;
|
|
33
|
-
resolveCellStyle(cellInfo: PooledCellRenderInfo<T>): RowStyle | undefined;
|
|
34
|
-
onRowClick(row: PooledRow<T>, modifiers: PooledRowModifiers): void;
|
|
35
|
-
onRowHover(row: PooledRow<T>, hovered: boolean): void;
|
|
36
|
-
onCellClick(row: PooledRow<T>, column: ColumnLeafDef<T>, modifiers: PooledRowModifiers): void;
|
|
37
|
-
createRoot(container: HTMLDivElement): CellRoot;
|
|
38
|
-
onRowHeightChange?(rowIndex: number, height: number): void;
|
|
39
|
-
/**
|
|
40
|
-
* Returns a cheap scalar preview of the cell value, painted synchronously
|
|
41
|
-
* into a blank cell while its first React commit (complex content) is
|
|
42
|
-
* pending — keeps the grid from showing empty cells during fast scroll
|
|
43
|
-
* ("staging" placeholder; React's first commit replaces it entirely).
|
|
44
|
-
* Return `null` to skip staging for this cell.
|
|
45
|
-
*
|
|
46
|
-
* @api
|
|
47
|
-
*/
|
|
48
|
-
renderCellPlaceholder?(info: PooledCellRenderInfo<T>): string | null;
|
|
49
|
-
}
|
|
3
|
+
import type { PooledColumn, PooledRowCallbacks } from "./types";
|
|
50
4
|
/**
|
|
51
5
|
* Reusable row panel: holds a fixed set of cells, lays them out for the
|
|
52
6
|
* horizontal column window via `translateX`, and updates content in-place
|
package/dist/pooledRow.js
CHANGED
|
@@ -342,6 +342,7 @@ export class PooledRowPane {
|
|
|
342
342
|
for (const key of cell.appliedStyleKeys)
|
|
343
343
|
cell.element.style.removeProperty(cssPropertyName(key));
|
|
344
344
|
cell.appliedStyleKeys.length = 0;
|
|
345
|
+
cell.element.style.padding = "";
|
|
345
346
|
const style = this.callbacks.resolveCellStyle(cellInfo);
|
|
346
347
|
if (style) {
|
|
347
348
|
for (const [key, value] of Object.entries(style)) {
|
|
@@ -351,6 +352,9 @@ export class PooledRowPane {
|
|
|
351
352
|
cell.appliedStyleKeys.push(key);
|
|
352
353
|
}
|
|
353
354
|
}
|
|
355
|
+
const flushLayout = cellInfo.column.cellLayout === "flush";
|
|
356
|
+
if (flushLayout)
|
|
357
|
+
cell.element.style.padding = "0";
|
|
354
358
|
if (cell.column?.wrapText) {
|
|
355
359
|
// Wrapping cell: the text breaks into several lines and the cell
|
|
356
360
|
// grows with it. The theme owns the horizontal padding and the
|
|
@@ -360,7 +364,7 @@ export class PooledRowPane {
|
|
|
360
364
|
cell.element.style.wordBreak = "break-word";
|
|
361
365
|
cell.element.style.overflow = "visible";
|
|
362
366
|
cell.element.style.textOverflow = "clip";
|
|
363
|
-
cell.element.style.paddingBlock = "4px";
|
|
367
|
+
cell.element.style.paddingBlock = flushLayout ? "0" : "4px";
|
|
364
368
|
cell.element.style.alignItems = "flex-start";
|
|
365
369
|
}
|
|
366
370
|
else {
|
|
@@ -369,7 +373,7 @@ export class PooledRowPane {
|
|
|
369
373
|
cell.element.style.whiteSpace = "nowrap";
|
|
370
374
|
cell.element.style.overflow = "hidden";
|
|
371
375
|
cell.element.style.textOverflow = "ellipsis";
|
|
372
|
-
cell.element.style.paddingBlock = "";
|
|
376
|
+
cell.element.style.paddingBlock = flushLayout ? "0" : "";
|
|
373
377
|
cell.element.style.alignItems = "";
|
|
374
378
|
}
|
|
375
379
|
}
|
package/dist/popup.d.ts
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
export interface PopupHostProps<T> {
|
|
4
|
-
grid: GridApi<T>;
|
|
5
|
-
}
|
|
2
|
+
import type { PopupHostProps } from "./types";
|
|
6
3
|
/**
|
|
7
4
|
* Renders the grid's active `UIPopupDescriptor`. Popup state lives here, so
|
|
8
5
|
* opening or updating a popup never re-renders the grid body. The popup is
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { CellRenderParams, ColumnGroupDef, ColumnLeafDef, GridOptions } from "@omnigrid/core";
|
|
3
|
+
/**
|
|
4
|
+
* React cell renderer accepted by the React adapter.
|
|
5
|
+
*
|
|
6
|
+
* @api
|
|
7
|
+
*/
|
|
8
|
+
export type ReactCellRenderer<T> = (params: CellRenderParams<T>) => ReactNode;
|
|
9
|
+
/**
|
|
10
|
+
* Leaf column definition with a renderer typed for React content.
|
|
11
|
+
*
|
|
12
|
+
* @api
|
|
13
|
+
*/
|
|
14
|
+
export type ReactColumnLeafDef<T> = Omit<ColumnLeafDef<T>, "cellRenderer"> & {
|
|
15
|
+
/** Replaces the default cell content with a React node. */
|
|
16
|
+
cellRenderer?: ReactCellRenderer<T>;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Column group definition whose children use React-specific column types.
|
|
20
|
+
*
|
|
21
|
+
* @api
|
|
22
|
+
*/
|
|
23
|
+
export type ReactColumnGroupDef<T> = Omit<ColumnGroupDef<T>, "children"> & {
|
|
24
|
+
children: ReactColumnDef<T>[];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Leaf or grouped column definition accepted by the React adapter.
|
|
28
|
+
*
|
|
29
|
+
* @api
|
|
30
|
+
*/
|
|
31
|
+
export type ReactColumnDef<T> = ReactColumnLeafDef<T> | ReactColumnGroupDef<T>;
|
|
32
|
+
/**
|
|
33
|
+
* Core grid options with React-specific column definitions.
|
|
34
|
+
*
|
|
35
|
+
* @api
|
|
36
|
+
*/
|
|
37
|
+
export type ReactGridOptions<T> = Omit<GridOptions<T>, "columns"> & {
|
|
38
|
+
columns: ReactColumnDef<T>[];
|
|
39
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/styling.d.ts
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import type { CellRenderParams, ColumnGroupDef, ColumnLeafDef, ColumnStyle, ColumnStyleParams, HeaderGroupRenderParams, HeaderRenderParams, HeaderStyle, RowStyle } from "@omnigrid/core";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* Evaluated once per column across the dataset, then applied to each rendered cell in O(1).
|
|
5
|
-
*
|
|
6
|
-
* @api
|
|
7
|
-
*/
|
|
8
|
-
export interface ResolvedColumnPresentation {
|
|
9
|
-
/** Space-separated CSS class names for the column body. */
|
|
10
|
-
classes: string;
|
|
11
|
-
/** Combined inline styles for the column body. */
|
|
12
|
-
style: ColumnStyle;
|
|
13
|
-
}
|
|
2
|
+
import type { ResolvedColumnPresentation } from "./types";
|
|
3
|
+
export type { ResolvedColumnPresentation };
|
|
14
4
|
/**
|
|
15
5
|
* Resolves column-level presentation once for the entire column across the entire dataset.
|
|
16
6
|
*
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { SlotRenderContext, UIInputControl } from "@omnigrid/core";
|
|
3
|
+
import type { CellRoot } from "./reactRoot";
|
|
4
|
+
import type { ReactGridOptions } from "./reactColumnDef";
|
|
5
|
+
/**
|
|
6
|
+
* Bridge between the core's headless content and native adapter values.
|
|
7
|
+
* `registry` — registry of React components for `SlotComponentContent`;
|
|
8
|
+
* `context()` — factory for the current render context so providers see
|
|
9
|
+
* up-to-date grid state at render time.
|
|
10
|
+
*/
|
|
11
|
+
export interface ContentBridge<T> {
|
|
12
|
+
registry: Record<string, (payload: unknown, context: SlotRenderContext<T>) => ReactNode>;
|
|
13
|
+
context: () => SlotRenderContext<T>;
|
|
14
|
+
}
|
|
15
|
+
/** Column within the pool: definition + geometry from the virtual window. */
|
|
16
|
+
export type PooledColumn<T> = import("@omnigrid/core").ViewportData<T>["columns"][number];
|
|
17
|
+
export interface PooledCellRenderInfo<T> {
|
|
18
|
+
data: T;
|
|
19
|
+
column: import("@omnigrid/core").ColumnLeafDef<T>;
|
|
20
|
+
columnIndex: number;
|
|
21
|
+
rowId: import("@omnigrid/core").RowId;
|
|
22
|
+
rowIndex: number;
|
|
23
|
+
/**
|
|
24
|
+
* Normalized horizontal span of this cell (`1` = plain cell).
|
|
25
|
+
* Span origins render the merged width; covered cells are skipped.
|
|
26
|
+
*/
|
|
27
|
+
colSpan: number;
|
|
28
|
+
}
|
|
29
|
+
export interface PooledRowModifiers {
|
|
30
|
+
ctrlKey: boolean;
|
|
31
|
+
shiftKey: boolean;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Injected back-channel: the row panel does NOT know about grid/adapter —
|
|
35
|
+
* it only fires these callbacks. This allows the panel to be reused across
|
|
36
|
+
* any adapter with a DOM environment.
|
|
37
|
+
*/
|
|
38
|
+
export interface PooledRowCallbacks<T> {
|
|
39
|
+
rowHeight: number;
|
|
40
|
+
renderCellContent(info: PooledCellRenderInfo<T>): unknown;
|
|
41
|
+
resolveRowClasses(row: import("@omnigrid/core").PooledRow<T>): string | undefined;
|
|
42
|
+
resolveRowStyle(row: import("@omnigrid/core").PooledRow<T>): import("@omnigrid/core").RowStyle | undefined;
|
|
43
|
+
resolveCellClasses(cellInfo: PooledCellRenderInfo<T>): string | undefined;
|
|
44
|
+
resolveCellStyle(cellInfo: PooledCellRenderInfo<T>): import("@omnigrid/core").RowStyle | undefined;
|
|
45
|
+
onRowClick(row: import("@omnigrid/core").PooledRow<T>, modifiers: PooledRowModifiers): void;
|
|
46
|
+
onRowHover(row: import("@omnigrid/core").PooledRow<T>, hovered: boolean): void;
|
|
47
|
+
onCellClick(row: import("@omnigrid/core").PooledRow<T>, column: import("@omnigrid/core").ColumnLeafDef<T>, modifiers: PooledRowModifiers): void;
|
|
48
|
+
createRoot(container: HTMLDivElement): CellRoot;
|
|
49
|
+
onRowHeightChange?(rowIndex: number, height: number): void;
|
|
50
|
+
/**
|
|
51
|
+
* Returns a cheap scalar preview of the cell value, painted synchronously
|
|
52
|
+
* into a blank cell while its first React commit (complex content) is
|
|
53
|
+
* pending — keeps the grid from showing empty cells during fast scroll
|
|
54
|
+
* ("staging" placeholder; React's first commit replaces it entirely).
|
|
55
|
+
* Return `null` to skip staging for this cell.
|
|
56
|
+
*
|
|
57
|
+
* @api
|
|
58
|
+
*/
|
|
59
|
+
renderCellPlaceholder?(info: PooledCellRenderInfo<T>): string | null;
|
|
60
|
+
}
|
|
61
|
+
export interface DebouncedInputProps {
|
|
62
|
+
descriptor: UIInputControl;
|
|
63
|
+
}
|
|
64
|
+
export interface PopupHostProps<T> {
|
|
65
|
+
grid: import("@omnigrid/core").GridApi<T>;
|
|
66
|
+
}
|
|
67
|
+
export interface UseGridResult<T> {
|
|
68
|
+
grid: import("@omnigrid/core").Grid<T>;
|
|
69
|
+
state: import("@omnigrid/core").GridState<T>;
|
|
70
|
+
viewportData: import("@omnigrid/core").ViewportData<T>;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Registry of native adapter components for `SlotComponentContent`:
|
|
74
|
+
* slotComponents={{ ["my-widget"]: (payload, context) => <MyWidget .../> }}
|
|
75
|
+
*/
|
|
76
|
+
export interface SlotRendererRegistry<T> {
|
|
77
|
+
[kind: string]: (payload: unknown, context: SlotRenderContext<T>) => ReactNode;
|
|
78
|
+
}
|
|
79
|
+
export type OverlayComponentProps<T> = import("@omnigrid/core").OverlayComponentProps<T>;
|
|
80
|
+
export type OverlayComponent<T> = import("react").ComponentType<import("@omnigrid/core").OverlayComponentProps<T>> | import("@omnigrid/core").OverlayComponent<T>;
|
|
81
|
+
export interface GridProps<T> extends Omit<ReactGridOptions<T>, "overlayComponents"> {
|
|
82
|
+
className?: string;
|
|
83
|
+
style?: import("react").CSSProperties;
|
|
84
|
+
/**
|
|
85
|
+
* Minimum grid height in rows when `style.height` is not set (auto-height
|
|
86
|
+
* mode). The viewport will be at least `headerHeight + minHeight *
|
|
87
|
+
* rowHeight` tall so the grid does not collapse when it has few or no
|
|
88
|
+
* rows. Set to `0` to disable.
|
|
89
|
+
*
|
|
90
|
+
* @api
|
|
91
|
+
* @default 3
|
|
92
|
+
*/
|
|
93
|
+
minHeight?: number;
|
|
94
|
+
slotComponents?: SlotRendererRegistry<T>;
|
|
95
|
+
overlayComponents?: Record<string, import("@omnigrid/core").OverlayComponent<T>>;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Pre-resolved presentation (classes and inline styles) for a column data body.
|
|
99
|
+
* Evaluated once per column across the dataset, then applied to each rendered cell in O(1).
|
|
100
|
+
*
|
|
101
|
+
* @api
|
|
102
|
+
*/
|
|
103
|
+
export interface ResolvedColumnPresentation {
|
|
104
|
+
/** Space-separated CSS class names for the column body. */
|
|
105
|
+
classes: string;
|
|
106
|
+
/** Combined inline styles for the column body. */
|
|
107
|
+
style: import("@omnigrid/core").ColumnStyle;
|
|
108
|
+
}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/useGrid.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
export interface UseGridResult<T> {
|
|
4
|
-
grid: Grid<T>;
|
|
5
|
-
state: GridState<T>;
|
|
6
|
-
viewportData: ViewportData<T>;
|
|
7
|
-
}
|
|
1
|
+
import type { UseGridResult } from "./types";
|
|
2
|
+
import type { ReactGridOptions } from "./reactColumnDef";
|
|
8
3
|
/**
|
|
9
4
|
* Binds the Grid instance from @omnigrid/core to the React lifecycle.
|
|
10
5
|
*
|
|
@@ -23,4 +18,4 @@ export interface UseGridResult<T> {
|
|
|
23
18
|
* entirely, so useSyncExternalStore does NOT trigger a React re-render on
|
|
24
19
|
* every scroll frame. The DOM Pool handles scroll imperatively.
|
|
25
20
|
*/
|
|
26
|
-
export declare function useGrid<T>(options:
|
|
21
|
+
export declare function useGrid<T>(options: ReactGridOptions<T>): UseGridResult<T>;
|
package/package.json
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
2
|
+
"name": "@omnigrid/react",
|
|
3
|
+
"version": "0.1.27",
|
|
4
|
+
"description": "React adapter and renderer for OmniGrid",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"omnigrid",
|
|
7
|
+
"grid",
|
|
8
|
+
"table",
|
|
9
|
+
"react",
|
|
10
|
+
"react-component"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "https://github.com/KRZK-Apps/omnigrid.git",
|
|
15
|
+
"directory": "react"
|
|
16
|
+
},
|
|
17
|
+
"homepage": "https://github.com/KRZK-Apps/omnigrid/tree/main/adapters/react#readme",
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/KRZK-Apps/omnigrid/issues"
|
|
20
|
+
},
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"type": "module",
|
|
23
|
+
"main": "dist/index.js",
|
|
24
|
+
"types": "dist/index.d.ts",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"types": "./dist/index.d.ts",
|
|
28
|
+
"import": "./dist/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"files": [
|
|
32
|
+
"dist"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
36
|
+
"lint": "npx tsc --noEmit -p tsconfig.json",
|
|
37
|
+
"test": "vitest run",
|
|
38
|
+
"prebuild": "npm --workspace @omnigrid/core run build && npm --workspace @omnigrid/style run build && npm --workspace @omnigrid/default-theme run build && npm run clean",
|
|
39
|
+
"build": "npx tsc -p tsconfig.json",
|
|
40
|
+
"prepublishOnly": "npm run build"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@omnigrid/core": "^0.1.0",
|
|
44
|
+
"@omnigrid/style": "^0.1.0",
|
|
45
|
+
"@omnigrid/default-theme": "^0.1.0"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@omnigrid/column-filter-plugin": "*",
|
|
49
|
+
"@omnigrid/quick-filter-plugin": "*",
|
|
50
|
+
"@types/react": "^19.0.0",
|
|
51
|
+
"@types/react-dom": "^19.0.0"
|
|
52
|
+
},
|
|
53
|
+
"peerDependencies": {
|
|
54
|
+
"react": ">=18",
|
|
55
|
+
"react-dom": ">=18"
|
|
29
56
|
}
|
|
30
|
-
},
|
|
31
|
-
"files": [
|
|
32
|
-
"dist"
|
|
33
|
-
],
|
|
34
|
-
"scripts": {
|
|
35
|
-
"clean": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\"",
|
|
36
|
-
"lint": "npx tsc --noEmit -p tsconfig.json",
|
|
37
|
-
"test": "vitest run",
|
|
38
|
-
"prebuild": "npm --workspace @omnigrid/core run build && npm --workspace @omnigrid/style run build && npm --workspace @omnigrid/default-theme run build && npm run clean",
|
|
39
|
-
"build": "npx tsc -p tsconfig.json",
|
|
40
|
-
"prepublishOnly": "npm run build"
|
|
41
|
-
},
|
|
42
|
-
"dependencies": {
|
|
43
|
-
"@omnigrid/core": "^0.1.0",
|
|
44
|
-
"@omnigrid/style": "^0.1.0",
|
|
45
|
-
"@omnigrid/default-theme": "^0.1.0"
|
|
46
|
-
},
|
|
47
|
-
"devDependencies": {
|
|
48
|
-
"@omnigrid/column-filter-plugin": "*",
|
|
49
|
-
"@omnigrid/quick-filter-plugin": "*",
|
|
50
|
-
"@types/react": "^19.0.0",
|
|
51
|
-
"@types/react-dom": "^19.0.0"
|
|
52
|
-
},
|
|
53
|
-
"peerDependencies": {
|
|
54
|
-
"react": ">=18",
|
|
55
|
-
"react-dom": ">=18"
|
|
56
|
-
}
|
|
57
57
|
}
|