@omnigrid/react 0.1.9 → 0.1.11
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.js +75 -30
- package/dist/overlays.d.ts +13 -0
- package/dist/overlays.js +58 -0
- package/dist/useGrid.js +13 -0
- package/package.json +1 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -6,6 +6,7 @@ import { contentToReactNode } from "./content";
|
|
|
6
6
|
import { computeGroupSegments } from "./groupHeader";
|
|
7
7
|
import { PooledRowPane } from "./pooledRow";
|
|
8
8
|
import { createCellRoot } from "./reactRoot";
|
|
9
|
+
import { renderDefaultOverlay } from "./overlays";
|
|
9
10
|
import { useGrid } from "./useGrid";
|
|
10
11
|
function getCellValue(row, column) {
|
|
11
12
|
if (column.valueGetter)
|
|
@@ -91,6 +92,11 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
91
92
|
// re-allocated on every render cycle.
|
|
92
93
|
const renderContext = useMemo(() => ({ api: grid, state, slot: undefined }), [grid, state]);
|
|
93
94
|
const buildRenderContext = useCallback(() => renderContext, [renderContext]);
|
|
95
|
+
const onGridReadyRef = useRef(options.onGridReady);
|
|
96
|
+
onGridReadyRef.current = options.onGridReady;
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
onGridReadyRef.current?.(grid);
|
|
99
|
+
}, [grid]);
|
|
94
100
|
const autoHeight = style?.height === undefined;
|
|
95
101
|
const rowHeight = grid.getState().rowHeight;
|
|
96
102
|
// Column-group header stack: `headerRowCount` group rows (one per depth) above
|
|
@@ -443,9 +449,14 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
443
449
|
const scrollLeft = element ? element.scrollLeft : frame.left;
|
|
444
450
|
// setViewport with scroll-only updates does NOT notify the Store,
|
|
445
451
|
// so this does NOT trigger a React re-render. The DomPool is
|
|
446
|
-
// updated imperatively below
|
|
447
|
-
|
|
448
|
-
|
|
452
|
+
// updated imperatively below, and both the row-column rebind and the
|
|
453
|
+
// header window update must flush in the same React paint to avoid
|
|
454
|
+
// one-frame horizontal/vertical jumps when custom cell renderers are
|
|
455
|
+
// mounted into pooled DOM nodes.
|
|
456
|
+
flushSync(() => {
|
|
457
|
+
grid.setViewport({ scrollTop, scrollLeft });
|
|
458
|
+
syncPool(true);
|
|
459
|
+
});
|
|
449
460
|
});
|
|
450
461
|
};
|
|
451
462
|
if (!isMeasured) {
|
|
@@ -474,6 +485,32 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
474
485
|
return (_jsx("div", { className: `omnigrid-slot-item-group omnigrid-slot-pos-${position}`, children: group.map((mount) => (_jsx("div", { className: "omnigrid-slot-item", children: resolveSlotContent(mount, context) }, mount.id))) }, position));
|
|
475
486
|
}) }));
|
|
476
487
|
};
|
|
488
|
+
/**
|
|
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.
|
|
494
|
+
*/
|
|
495
|
+
function renderOverlayContent(overlay) {
|
|
496
|
+
if (!overlay || !overlay.type)
|
|
497
|
+
return null;
|
|
498
|
+
const customRenderer = optionsRef.current.overlayComponents?.[overlay.type];
|
|
499
|
+
if (customRenderer) {
|
|
500
|
+
return contentToReactNode(customRenderer(overlay.payload, grid.getState()), {
|
|
501
|
+
registry: slotComponentsRef.current,
|
|
502
|
+
context: buildRenderContext,
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
if (overlay.type === "custom") {
|
|
506
|
+
return contentToReactNode(overlay.payload, {
|
|
507
|
+
registry: slotComponentsRef.current,
|
|
508
|
+
context: buildRenderContext,
|
|
509
|
+
});
|
|
510
|
+
}
|
|
511
|
+
return renderDefaultOverlay(overlay);
|
|
512
|
+
}
|
|
513
|
+
const overlayState = state.overlay;
|
|
477
514
|
const pinnedLeftWidth = viewportData.pinnedLeftColumns.reduce((sum, item) => sum + item.width, 0);
|
|
478
515
|
const pinnedRightWidth = viewportData.pinnedRightColumns.reduce((sum, item) => sum + item.width, 0);
|
|
479
516
|
const scrollableWidth = Math.max(0, viewportData.totalWidth - pinnedLeftWidth - pinnedRightWidth);
|
|
@@ -572,7 +609,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
572
609
|
top: headerHeight,
|
|
573
610
|
width,
|
|
574
611
|
} }));
|
|
575
|
-
return (_jsxs("div", { className: "omnigrid-layout", style: style, children: [renderSlot("top"), _jsxs("div", { className: "omnigrid-layout-body", children: [renderSlot("left"),
|
|
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: {
|
|
576
613
|
...viewportStyle,
|
|
577
614
|
flex: "1 1 0",
|
|
578
615
|
height: autoHeight ? measuredHeight : "100%",
|
|
@@ -583,30 +620,38 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
583
620
|
position: "relative",
|
|
584
621
|
scrollbarGutter: verticalScrollbarGutter,
|
|
585
622
|
width: "100%",
|
|
586
|
-
}, children: _jsxs("div", { style: {
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
623
|
+
}, children: [_jsxs("div", { style: {
|
|
624
|
+
display: "flex",
|
|
625
|
+
height: rowTotalHeight,
|
|
626
|
+
position: "relative",
|
|
627
|
+
width: `max(100%, ${viewportData.totalWidth}px)`,
|
|
628
|
+
}, children: [hasPinnedLeft && (_jsxs("div", { className: "omnigrid-pinned omnigrid-pinned-left", style: {
|
|
629
|
+
height: rowTotalHeight,
|
|
630
|
+
left: 0,
|
|
631
|
+
position: "sticky",
|
|
632
|
+
top: 0,
|
|
633
|
+
width: `${pinnedLeftWidth}px`,
|
|
634
|
+
zIndex: 3,
|
|
635
|
+
}, children: [renderHeader(viewportData.pinnedLeftColumns, 0, `${pinnedLeftWidth}px`, true), renderRowsLayer(pinnedLeftRowsLayerRef, `${pinnedLeftWidth}px`)] })), _jsxs("div", { className: "omnigrid-scrollable", style: {
|
|
636
|
+
flex: hasPins ? `1 0 ${scrollableWidth}px` : "1 1 auto",
|
|
637
|
+
minWidth: 0,
|
|
638
|
+
position: "relative",
|
|
639
|
+
width: centralWidth,
|
|
640
|
+
zIndex: 1,
|
|
641
|
+
}, children: [renderHeader(viewportData.columns, pinnedLeftWidth, "100%", false), renderRowsLayer(rowsLayerRef, "100%")] }), hasPinnedRight && (_jsxs("div", { className: "omnigrid-pinned omnigrid-pinned-right", style: {
|
|
642
|
+
height: rowTotalHeight,
|
|
643
|
+
position: "sticky",
|
|
644
|
+
right: 0,
|
|
645
|
+
top: 0,
|
|
646
|
+
width: `${pinnedRightWidth}px`,
|
|
647
|
+
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,
|
|
650
|
+
left: 0,
|
|
651
|
+
pointerEvents: "auto",
|
|
652
|
+
position: "absolute",
|
|
653
|
+
right: 0,
|
|
654
|
+
top: headerHeight,
|
|
655
|
+
zIndex: 4,
|
|
656
|
+
}, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom")] }));
|
|
612
657
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { OverlayState } from "@omnigrid/core";
|
|
3
|
+
export interface OverlayProps {
|
|
4
|
+
/** Active overlay state (type + optional payload). */
|
|
5
|
+
overlay: OverlayState;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Builds the default overlay content for a given overlay state.
|
|
9
|
+
*
|
|
10
|
+
* For `custom` overlays, this returns null — the payload is rendered
|
|
11
|
+
* directly by `OmniGrid.renderOverlayContent` via `contentToReactNode`.
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderDefaultOverlay(overlay: OverlayState): ReactNode;
|
package/dist/overlays.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
function extractMessage(payload, fallback) {
|
|
3
|
+
if (typeof payload === "string")
|
|
4
|
+
return payload;
|
|
5
|
+
if (payload instanceof Error)
|
|
6
|
+
return payload.message;
|
|
7
|
+
if (payload && typeof payload === "object" && "message" in payload) {
|
|
8
|
+
return String(payload.message);
|
|
9
|
+
}
|
|
10
|
+
return fallback;
|
|
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" })] }));
|
|
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") })] }));
|
|
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") })] }));
|
|
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") })] }));
|
|
23
|
+
}
|
|
24
|
+
const DEFAULT_OVERLAYS = {
|
|
25
|
+
loading: LoadingOverlay,
|
|
26
|
+
noRows: NoRowsOverlay,
|
|
27
|
+
noMatchingRows: NoMatchingRowsOverlay,
|
|
28
|
+
error: ErrorOverlay,
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Builds the default overlay content for a given overlay state.
|
|
32
|
+
*
|
|
33
|
+
* For `custom` overlays, this returns null — the payload is rendered
|
|
34
|
+
* directly by `OmniGrid.renderOverlayContent` via `contentToReactNode`.
|
|
35
|
+
*/
|
|
36
|
+
export function renderDefaultOverlay(overlay) {
|
|
37
|
+
const { type, payload } = overlay;
|
|
38
|
+
if (!type)
|
|
39
|
+
return null;
|
|
40
|
+
if (type === "custom")
|
|
41
|
+
return null;
|
|
42
|
+
const factory = DEFAULT_OVERLAYS[type];
|
|
43
|
+
if (!factory)
|
|
44
|
+
return null;
|
|
45
|
+
return factory(payload);
|
|
46
|
+
}
|
|
47
|
+
/** Inline SVG: empty / document icon. */
|
|
48
|
+
function NoRowsIcon() {
|
|
49
|
+
return (_jsxs("svg", { className: "omnigrid-overlay-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("path", { d: "M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z" }), _jsx("polyline", { points: "14 2 14 8 20 8" }), _jsx("line", { x1: "8", y1: "13", x2: "16", y2: "13" }), _jsx("line", { x1: "8", y1: "17", x2: "16", y2: "17" })] }));
|
|
50
|
+
}
|
|
51
|
+
/** Inline SVG: no results / search icon. */
|
|
52
|
+
function NoMatchingRowsIcon() {
|
|
53
|
+
return (_jsxs("svg", { className: "omnigrid-overlay-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "11", cy: "11", r: "8" }), _jsx("line", { x1: "21", y1: "21", x2: "15.657", y2: "15.657" }), _jsx("circle", { cx: "11", cy: "11", r: "1" }), _jsx("line", { x1: "8", y1: "8", x2: "8.5", y2: "8.5" })] }));
|
|
54
|
+
}
|
|
55
|
+
/** Inline SVG: error / warning icon. */
|
|
56
|
+
function ErrorIcon() {
|
|
57
|
+
return (_jsxs("svg", { className: "omnigrid-overlay-icon", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: [_jsx("circle", { cx: "12", cy: "12", r: "10" }), _jsx("line", { x1: "15", y1: "9", x2: "9", y2: "15" }), _jsx("line", { x1: "9", y1: "9", x2: "15", y2: "15" })] }));
|
|
58
|
+
}
|
package/dist/useGrid.js
CHANGED
|
@@ -72,6 +72,19 @@ export function useGrid(options) {
|
|
|
72
72
|
grid.setColumns(options.columns);
|
|
73
73
|
}
|
|
74
74
|
}, [grid, options.columns]);
|
|
75
|
+
// Sync loading state. When `options.loading` is true, show the loading
|
|
76
|
+
// overlay; when false, hide it (auto-overlays like noRows take over).
|
|
77
|
+
const loadingSyncedRef = useRef(false);
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
if (grid.isDestroyed())
|
|
80
|
+
return;
|
|
81
|
+
if (!loadingSyncedRef.current) {
|
|
82
|
+
loadingSyncedRef.current = true;
|
|
83
|
+
grid.setLoading(!!options.loading);
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
grid.setLoading(!!options.loading);
|
|
87
|
+
}, [grid, options.loading]);
|
|
75
88
|
return {
|
|
76
89
|
grid,
|
|
77
90
|
state,
|