@omnigrid/react 0.1.18 → 0.1.20
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 +27 -21
- package/dist/content.d.ts +3 -0
- package/dist/content.js +19 -0
- package/dist/controls.d.ts +21 -0
- package/dist/controls.js +385 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +2 -0
- package/dist/popup.d.ts +11 -0
- package/dist/popup.js +81 -0
- package/dist/useGrid.js +13 -0
- package/package.json +2 -1
package/dist/OmniGrid.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
3
3
|
import { flushSync } from "react-dom";
|
|
4
|
-
import { DomPool } from "@omnigrid/core";
|
|
4
|
+
import { DomPool, isActiveCondition } from "@omnigrid/core";
|
|
5
5
|
import { contentToReactNode, hasRenderableContent } from "./content";
|
|
6
6
|
import { computeGroupSegments } from "./groupHeader";
|
|
7
7
|
import { PooledRowPane } from "./pooledRow";
|
|
8
8
|
import { createCellRoot } from "./reactRoot";
|
|
9
9
|
import { renderDefaultOverlay } from "./overlays";
|
|
10
|
+
import { PopupHost } from "./popup";
|
|
10
11
|
import { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
|
11
12
|
import { useGrid } from "./useGrid";
|
|
12
13
|
function getCellValue(row, column) {
|
|
@@ -60,10 +61,10 @@ function createRowLayerState() {
|
|
|
60
61
|
export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
61
62
|
const { grid, state, viewportData } = useGrid(options);
|
|
62
63
|
const viewportRef = useRef(null);
|
|
64
|
+
const layoutRef = useRef(null);
|
|
63
65
|
const rowsLayerRef = useRef(null);
|
|
64
66
|
const pinnedLeftRowsLayerRef = useRef(null);
|
|
65
67
|
const pinnedRightRowsLayerRef = useRef(null);
|
|
66
|
-
const [isMeasured, setIsMeasured] = useState(false);
|
|
67
68
|
/** Space taken by the viewport's native scrollbars; body slots stay clear of it. */
|
|
68
69
|
const [scrollbarInsets, setScrollbarInsets] = useState({ right: 0, bottom: 0 });
|
|
69
70
|
const scrollFrameRef = useRef({ id: 0, top: 0, left: 0, lastTop: 0, lastTime: 0 });
|
|
@@ -130,6 +131,11 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
130
131
|
const suppressRowHoverHighlight = options.suppressRowHoverHighlight ?? false;
|
|
131
132
|
const viewportClassName = ["omnigrid", className, suppressRowHoverHighlight ? "omnigrid-no-row-hover" : null].filter(Boolean).join(" ");
|
|
132
133
|
const overlayState = state.overlay;
|
|
134
|
+
const filterModelSnapshot = grid.getFilterModel();
|
|
135
|
+
const isColumnFiltered = (column) => {
|
|
136
|
+
const entry = filterModelSnapshot[column.id] ?? (column.field ? filterModelSnapshot[column.field] : undefined);
|
|
137
|
+
return entry !== undefined && entry.conditions.some(isActiveCondition);
|
|
138
|
+
};
|
|
133
139
|
const overlayScope = overlayState.type
|
|
134
140
|
? (overlayState.scope ?? (overlayState.type === "error" ? "full" : "bodyOnly"))
|
|
135
141
|
: undefined;
|
|
@@ -446,7 +452,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
446
452
|
if (width === 0 || height === 0)
|
|
447
453
|
return;
|
|
448
454
|
grid.setViewport({ width, height });
|
|
449
|
-
setIsMeasured(true);
|
|
450
455
|
}, [grid, syncScrollbarInsets]);
|
|
451
456
|
useEffect(() => {
|
|
452
457
|
const element = viewportRef.current;
|
|
@@ -464,7 +469,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
464
469
|
if (width === 0 || height === 0)
|
|
465
470
|
return;
|
|
466
471
|
grid.setViewport({ width, height });
|
|
467
|
-
setIsMeasured(true);
|
|
468
472
|
});
|
|
469
473
|
observer.observe(element, { box: "content-box" });
|
|
470
474
|
measureViewport();
|
|
@@ -476,12 +480,12 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
476
480
|
syncScrollbarInsets(viewportRef.current);
|
|
477
481
|
});
|
|
478
482
|
useLayoutEffect(() => {
|
|
479
|
-
if (
|
|
483
|
+
if (autoHeight)
|
|
480
484
|
return;
|
|
481
485
|
// Scrollbar and gutter changes alter clientWidth; sync it before paint
|
|
482
486
|
// so columns remain aligned when an overlay locks vertical scrolling.
|
|
483
487
|
measureViewport();
|
|
484
|
-
}, [autoHeight, hasVerticalOverflow,
|
|
488
|
+
}, [autoHeight, hasVerticalOverflow, measureViewport, overlayScope]);
|
|
485
489
|
useEffect(() => {
|
|
486
490
|
const unsubscribe = grid.on("scrollTo", (position) => {
|
|
487
491
|
const element = viewportRef.current;
|
|
@@ -577,15 +581,6 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
577
581
|
syncPool(true, skipContentBind);
|
|
578
582
|
});
|
|
579
583
|
};
|
|
580
|
-
if (!isMeasured) {
|
|
581
|
-
return (_jsx("div", { ref: viewportRef, className: viewportClassName, style: {
|
|
582
|
-
...viewportStyle,
|
|
583
|
-
overflowX: "auto",
|
|
584
|
-
overflowY: autoHeight ? "hidden" : "auto",
|
|
585
|
-
position: "relative",
|
|
586
|
-
scrollbarGutter: verticalScrollbarGutter,
|
|
587
|
-
} }));
|
|
588
|
-
}
|
|
589
584
|
/** Resolves headless slot content into a ReactNode (see contentToReactNode). */
|
|
590
585
|
const resolveSlotContent = (mount, context) => {
|
|
591
586
|
const raw = typeof mount.content === "function" ? mount.content(context) : mount.content;
|
|
@@ -608,7 +603,8 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
608
603
|
const groups = renderSlotGroups(mounts, context);
|
|
609
604
|
if (groups.every((group) => group === null))
|
|
610
605
|
return null;
|
|
611
|
-
|
|
606
|
+
const slotClass = slot === "down" ? "omnigrid-slot omnigrid-slot-bottom omnigrid-slot-down" : `omnigrid-slot omnigrid-slot-${slot}`;
|
|
607
|
+
return (_jsx("div", { className: slotClass, children: groups }));
|
|
612
608
|
};
|
|
613
609
|
/** Renders slots that overlay the table body (absolute positioning, no layout shift). */
|
|
614
610
|
const renderBodySlot = (slot) => {
|
|
@@ -713,9 +709,19 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
713
709
|
}, tabIndex: 0, style: headerCellLayout, children: item.column.headerRenderer ? (contentToReactNode(item.column.headerRenderer(item.column), {
|
|
714
710
|
registry: slotComponentsRef.current,
|
|
715
711
|
context: buildRenderContext,
|
|
716
|
-
})) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "omnigrid-header-label", children: item.column.header ?? item.column.id }),
|
|
717
|
-
|
|
718
|
-
|
|
712
|
+
})) : (_jsxs(_Fragment, { children: [_jsx("span", { className: "omnigrid-header-label", children: 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"
|
|
713
|
+
? grid.icons.get("arrow-up")
|
|
714
|
+
: grid.icons.get("arrow-down"), { registry: slotComponentsRef.current, context: buildRenderContext }), 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) => {
|
|
715
|
+
event.stopPropagation();
|
|
716
|
+
const rect = event.currentTarget.getBoundingClientRect();
|
|
717
|
+
const layoutRect = layoutRef.current?.getBoundingClientRect() ?? { left: 0, top: 0, width: 0, height: 0 };
|
|
718
|
+
grid.requestFilterMenu(item.column.id, {
|
|
719
|
+
x: rect.left - layoutRect.left,
|
|
720
|
+
y: rect.top - layoutRect.top,
|
|
721
|
+
width: rect.width,
|
|
722
|
+
height: rect.height,
|
|
723
|
+
});
|
|
724
|
+
}, onKeyDown: (event) => event.stopPropagation(), children: _jsx("svg", { viewBox: "0 0 24 24", width: "12", height: "12", fill: "currentColor", "aria-hidden": "true", children: _jsx("path", { d: "M3 4h18l-7 8.5V20l-4-2v-5.5z" }) }) }))] })] })) }, item.column.id));
|
|
719
725
|
});
|
|
720
726
|
const renderGroupCells = (depth, columns, originX) => computeGroupSegments(viewportData.columnGroups, columns, depth, originX).map((segment, index) => {
|
|
721
727
|
const groupParams = {
|
|
@@ -781,7 +787,7 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
781
787
|
top: headerHeight,
|
|
782
788
|
width,
|
|
783
789
|
} }));
|
|
784
|
-
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", { className: "omnigrid-viewport-container", style: {
|
|
790
|
+
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: {
|
|
785
791
|
flex: "1 1 0",
|
|
786
792
|
minHeight: 0,
|
|
787
793
|
minWidth: 0,
|
|
@@ -832,5 +838,5 @@ export function OmniGrid({ className, style, slotComponents, ...options }) {
|
|
|
832
838
|
top: headerHeight,
|
|
833
839
|
width: "100%",
|
|
834
840
|
zIndex: 4,
|
|
835
|
-
}, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
|
|
841
|
+
}, children: renderOverlayContent(overlayState) }))] }), renderSlot("right")] }), renderSlot("bottom"), _jsx(PopupHost, { grid: grid }), overlayState.type && isFullOverlay && (_jsx("div", { className: "omnigrid-overlay omnigrid-overlay-full", role: "status", children: renderOverlayContent(overlayState) }))] }));
|
|
836
842
|
}
|
package/dist/content.d.ts
CHANGED
|
@@ -26,9 +26,12 @@ export declare function hasRenderableContent(content: ReactNode): boolean;
|
|
|
26
26
|
* Materialises the core's headless content into a ReactNode:
|
|
27
27
|
* - `string | number | boolean` → scalar;
|
|
28
28
|
* - CheckboxControl → `<input type="checkbox">`;
|
|
29
|
+
* - `UIControlDescriptor` → native control (see `controls.ts`);
|
|
29
30
|
* - `SlotNodeContent` → declarative node (buttons etc.);
|
|
30
31
|
* - `SlotComponentContent` → component from the adapter registry;
|
|
31
32
|
* - `SlotHtmlContent` → `<div dangerouslySetInnerHTML>`;
|
|
32
33
|
* - anything else → passthrough (ReactNode from cellRenderer).
|
|
34
|
+
*
|
|
35
|
+
* Control `icon` names are resolved through the grid's icon registry.
|
|
33
36
|
*/
|
|
34
37
|
export declare function contentToReactNode<T>(content: unknown, bridge: ContentBridge<T>): ReactNode;
|
package/dist/content.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { cloneElement, createElement, Fragment, isValidElement } from "react";
|
|
2
|
+
import { isUIControlDescriptor, renderControl } from "./controls";
|
|
2
3
|
export function isCheckboxControl(value) {
|
|
3
4
|
return typeof value === "object" && value !== null && value.type === "@omnigrid/checkbox";
|
|
4
5
|
}
|
|
@@ -125,14 +126,30 @@ function slotNodeToReact(node, bridge) {
|
|
|
125
126
|
});
|
|
126
127
|
return createElement(node.tag, props, children);
|
|
127
128
|
}
|
|
129
|
+
/**
|
|
130
|
+
* Builds an icon resolver backed by the grid's `IconRegistry` so control
|
|
131
|
+
* descriptors can declare `icon: "filter"` (and friends) as plain names.
|
|
132
|
+
* Unknown names resolve to `null` instead of throwing, keeping slot renders stable.
|
|
133
|
+
*/
|
|
134
|
+
function createIconResolver(bridge) {
|
|
135
|
+
return (name) => {
|
|
136
|
+
const context = bridge.context();
|
|
137
|
+
if (!context.api.icons.has(name))
|
|
138
|
+
return null;
|
|
139
|
+
return slotNodeToReact(context.api.icons.get(name), bridge);
|
|
140
|
+
};
|
|
141
|
+
}
|
|
128
142
|
/**
|
|
129
143
|
* Materialises the core's headless content into a ReactNode:
|
|
130
144
|
* - `string | number | boolean` → scalar;
|
|
131
145
|
* - CheckboxControl → `<input type="checkbox">`;
|
|
146
|
+
* - `UIControlDescriptor` → native control (see `controls.ts`);
|
|
132
147
|
* - `SlotNodeContent` → declarative node (buttons etc.);
|
|
133
148
|
* - `SlotComponentContent` → component from the adapter registry;
|
|
134
149
|
* - `SlotHtmlContent` → `<div dangerouslySetInnerHTML>`;
|
|
135
150
|
* - anything else → passthrough (ReactNode from cellRenderer).
|
|
151
|
+
*
|
|
152
|
+
* Control `icon` names are resolved through the grid's icon registry.
|
|
136
153
|
*/
|
|
137
154
|
export function contentToReactNode(content, bridge) {
|
|
138
155
|
if (content == null)
|
|
@@ -141,6 +158,8 @@ export function contentToReactNode(content, bridge) {
|
|
|
141
158
|
return content;
|
|
142
159
|
if (isCheckboxControl(content))
|
|
143
160
|
return renderCheckboxControl(content);
|
|
161
|
+
if (isUIControlDescriptor(content))
|
|
162
|
+
return renderControl(content, createIconResolver(bridge));
|
|
144
163
|
if (isSlotNodeContent(content))
|
|
145
164
|
return slotNodeToReact(content, bridge);
|
|
146
165
|
if (isSlotComponentContent(content)) {
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { UIControlDescriptor, UIInputControl } from "@omnigrid/core";
|
|
3
|
+
/** Type guard for core `UIControlDescriptor` objects. */
|
|
4
|
+
export declare function isUIControlDescriptor(value: unknown): value is UIControlDescriptor;
|
|
5
|
+
export interface DebouncedInputProps {
|
|
6
|
+
descriptor: UIInputControl;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Text/number input that keeps typing in local state and forwards the value to
|
|
10
|
+
* the descriptor callback after `debounceMs` of inactivity. Pending input is
|
|
11
|
+
* flushed on Enter, blur and unmount so it is never lost.
|
|
12
|
+
*/
|
|
13
|
+
export declare function DebouncedInput({ descriptor }: DebouncedInputProps): ReactNode;
|
|
14
|
+
/**
|
|
15
|
+
* Renders one framework-agnostic control descriptor with native HTML elements.
|
|
16
|
+
* Descriptor `id`s become React keys, so re-describing a popup updates
|
|
17
|
+
* elements in place instead of remounting them.
|
|
18
|
+
* @param descriptor - Control descriptor to materialise.
|
|
19
|
+
* @param resolveIcon - Optional resolver mapping `descriptor.icon` names to nodes; backed by the grid icon registry.
|
|
20
|
+
*/
|
|
21
|
+
export declare function renderControl(descriptor: UIControlDescriptor, resolveIcon?: (name: string) => ReactNode): ReactNode;
|
package/dist/controls.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { createElement, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
+
import { createPortal } from "react-dom";
|
|
3
|
+
const CONTROL_TYPES = new Set(["text", "number", "date", "select", "checkbox", "button", "label", "multi-select", "group"]);
|
|
4
|
+
/** Type guard for core `UIControlDescriptor` objects. */
|
|
5
|
+
export function isUIControlDescriptor(value) {
|
|
6
|
+
if (typeof value !== "object" || value === null)
|
|
7
|
+
return false;
|
|
8
|
+
const candidate = value;
|
|
9
|
+
return typeof candidate.type === "string" && CONTROL_TYPES.has(candidate.type) && typeof candidate.id === "string";
|
|
10
|
+
}
|
|
11
|
+
const DEFAULT_DEBOUNCE_MS = 250;
|
|
12
|
+
/**
|
|
13
|
+
* Text/number input that keeps typing in local state and forwards the value to
|
|
14
|
+
* the descriptor callback after `debounceMs` of inactivity. Pending input is
|
|
15
|
+
* flushed on Enter, blur and unmount so it is never lost.
|
|
16
|
+
*/
|
|
17
|
+
export function DebouncedInput({ descriptor }) {
|
|
18
|
+
const [local, setLocal] = useState(descriptor.value);
|
|
19
|
+
const timerRef = useRef(null);
|
|
20
|
+
const pendingRef = useRef(null);
|
|
21
|
+
const onChangeRef = useRef(descriptor.onChange);
|
|
22
|
+
onChangeRef.current = descriptor.onChange;
|
|
23
|
+
const flush = () => {
|
|
24
|
+
if (timerRef.current !== null) {
|
|
25
|
+
clearTimeout(timerRef.current);
|
|
26
|
+
timerRef.current = null;
|
|
27
|
+
}
|
|
28
|
+
if (pendingRef.current !== null) {
|
|
29
|
+
const value = pendingRef.current;
|
|
30
|
+
pendingRef.current = null;
|
|
31
|
+
onChangeRef.current(value);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
// Adopt external value changes (e.g. clearFilters) unless the user has unsent input.
|
|
35
|
+
useEffect(() => {
|
|
36
|
+
if (pendingRef.current === null)
|
|
37
|
+
setLocal(descriptor.value);
|
|
38
|
+
}, [descriptor.value]);
|
|
39
|
+
useEffect(() => flush, []);
|
|
40
|
+
const handleChange = (event) => {
|
|
41
|
+
const next = event.target.value;
|
|
42
|
+
setLocal(next);
|
|
43
|
+
pendingRef.current = next;
|
|
44
|
+
if (timerRef.current !== null)
|
|
45
|
+
clearTimeout(timerRef.current);
|
|
46
|
+
timerRef.current = setTimeout(flush, descriptor.debounceMs ?? DEFAULT_DEBOUNCE_MS);
|
|
47
|
+
};
|
|
48
|
+
const handleKeyDown = (event) => {
|
|
49
|
+
if (event.key === "Enter") {
|
|
50
|
+
descriptor.onEnter?.();
|
|
51
|
+
flush();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
const handleClear = () => {
|
|
55
|
+
setLocal("");
|
|
56
|
+
pendingRef.current = "";
|
|
57
|
+
flush();
|
|
58
|
+
};
|
|
59
|
+
return createElement("div", { className: "omnigrid-control-input-wrapper" }, createElement("input", {
|
|
60
|
+
className: ["omnigrid-control-input", descriptor.className].filter(Boolean).join(" "),
|
|
61
|
+
type: descriptor.type === "number" ? "number" : descriptor.type === "date" ? "date" : "text",
|
|
62
|
+
value: local,
|
|
63
|
+
placeholder: descriptor.placeholder,
|
|
64
|
+
disabled: descriptor.disabled,
|
|
65
|
+
"aria-label": descriptor.ariaLabel ?? descriptor.label ?? descriptor.placeholder,
|
|
66
|
+
onChange: handleChange,
|
|
67
|
+
onBlur: flush,
|
|
68
|
+
onKeyDown: handleKeyDown,
|
|
69
|
+
}), local.length > 0 &&
|
|
70
|
+
createElement("button", {
|
|
71
|
+
type: "button",
|
|
72
|
+
className: "omnigrid-control-clear",
|
|
73
|
+
"aria-label": "Clear",
|
|
74
|
+
onClick: handleClear,
|
|
75
|
+
}, "×"));
|
|
76
|
+
}
|
|
77
|
+
function withLabel(descriptor, field, inline = false, resolveIcon) {
|
|
78
|
+
const className = ["omnigrid-control", `omnigrid-control-${descriptor.type}`].join(" ");
|
|
79
|
+
const icon = descriptor.icon && resolveIcon ? resolveIcon(descriptor.icon) : null;
|
|
80
|
+
const body = icon ? createElement("div", { className: "omnigrid-control-body" }, icon, field) : field;
|
|
81
|
+
if (!descriptor.label)
|
|
82
|
+
return createElement("div", { key: descriptor.id, className }, body);
|
|
83
|
+
const label = createElement("span", { className: "omnigrid-control-label" }, descriptor.label);
|
|
84
|
+
return inline ? createElement("label", { key: descriptor.id, className }, body, label) : createElement("label", { key: descriptor.id, className }, label, body);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Custom-styled, keyboard-navigable drop-down select. Replaces the native
|
|
88
|
+
* `<select>` so the control looks identical in light and dark themes and can
|
|
89
|
+
* be fully styled through CSS variables.
|
|
90
|
+
*/
|
|
91
|
+
function SelectControl({ descriptor }) {
|
|
92
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
93
|
+
const [focusedIndex, setFocusedIndex] = useState(null);
|
|
94
|
+
const [anchorRect, setAnchorRect] = useState(null);
|
|
95
|
+
const buttonRef = useRef(null);
|
|
96
|
+
const listboxRef = useRef(null);
|
|
97
|
+
const selectedIndex = useMemo(() => descriptor.options.findIndex((option) => option.value === descriptor.value), [descriptor.options, descriptor.value]);
|
|
98
|
+
const listboxId = `${descriptor.id}-listbox`;
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
if (!isOpen) {
|
|
101
|
+
setFocusedIndex(null);
|
|
102
|
+
setAnchorRect(null);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const rect = buttonRef.current ? buttonRef.current.getBoundingClientRect() : null;
|
|
106
|
+
if (rect) {
|
|
107
|
+
setAnchorRect({ x: rect.left, y: rect.bottom, width: rect.width });
|
|
108
|
+
}
|
|
109
|
+
setFocusedIndex(selectedIndex === -1 ? 0 : selectedIndex);
|
|
110
|
+
}, [isOpen, selectedIndex]);
|
|
111
|
+
const close = useCallback(() => {
|
|
112
|
+
setIsOpen(false);
|
|
113
|
+
setFocusedIndex(null);
|
|
114
|
+
setAnchorRect(null);
|
|
115
|
+
buttonRef.current?.focus();
|
|
116
|
+
}, []);
|
|
117
|
+
const selectOption = useCallback((index) => {
|
|
118
|
+
const option = descriptor.options[index];
|
|
119
|
+
if (!option || option.disabled)
|
|
120
|
+
return;
|
|
121
|
+
descriptor.onChange(option.value);
|
|
122
|
+
close();
|
|
123
|
+
}, [descriptor, close]);
|
|
124
|
+
const moveFocus = useCallback((delta) => {
|
|
125
|
+
if (focusedIndex === null) {
|
|
126
|
+
setFocusedIndex(0);
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
const length = descriptor.options.length;
|
|
130
|
+
let next = focusedIndex + delta;
|
|
131
|
+
while (next >= 0 && next < length && descriptor.options[next]?.disabled) {
|
|
132
|
+
next += delta;
|
|
133
|
+
}
|
|
134
|
+
if (next >= 0 && next < length)
|
|
135
|
+
setFocusedIndex(next);
|
|
136
|
+
}, [descriptor.options, focusedIndex]);
|
|
137
|
+
const handleButtonKeyDown = useCallback((event) => {
|
|
138
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp" || event.key === "Enter" || event.key === " ") {
|
|
139
|
+
event.preventDefault();
|
|
140
|
+
setIsOpen(true);
|
|
141
|
+
}
|
|
142
|
+
}, []);
|
|
143
|
+
const handleListboxKeyDown = useCallback((event) => {
|
|
144
|
+
switch (event.key) {
|
|
145
|
+
case "ArrowDown":
|
|
146
|
+
event.preventDefault();
|
|
147
|
+
moveFocus(1);
|
|
148
|
+
break;
|
|
149
|
+
case "ArrowUp":
|
|
150
|
+
event.preventDefault();
|
|
151
|
+
moveFocus(-1);
|
|
152
|
+
break;
|
|
153
|
+
case "Home":
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
setFocusedIndex(0);
|
|
156
|
+
break;
|
|
157
|
+
case "End":
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
setFocusedIndex(descriptor.options.length - 1);
|
|
160
|
+
break;
|
|
161
|
+
case "Enter":
|
|
162
|
+
event.preventDefault();
|
|
163
|
+
if (focusedIndex !== null)
|
|
164
|
+
selectOption(focusedIndex);
|
|
165
|
+
break;
|
|
166
|
+
case "Escape":
|
|
167
|
+
event.preventDefault();
|
|
168
|
+
close();
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
}, [descriptor.options.length, focusedIndex, moveFocus, selectOption, close]);
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (!isOpen)
|
|
174
|
+
return;
|
|
175
|
+
const handlePointerDown = (event) => {
|
|
176
|
+
const target = event.target;
|
|
177
|
+
if (buttonRef.current &&
|
|
178
|
+
!buttonRef.current.contains(target) &&
|
|
179
|
+
listboxRef.current &&
|
|
180
|
+
!listboxRef.current.contains(target)) {
|
|
181
|
+
close();
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
document.addEventListener("mousedown", handlePointerDown);
|
|
185
|
+
return () => {
|
|
186
|
+
document.removeEventListener("mousedown", handlePointerDown);
|
|
187
|
+
};
|
|
188
|
+
}, [isOpen, close]);
|
|
189
|
+
// Keep the portaled listbox anchored to the trigger while anything scrolls.
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
if (!isOpen || !anchorRect)
|
|
192
|
+
return;
|
|
193
|
+
const reposition = () => {
|
|
194
|
+
const rect = buttonRef.current ? buttonRef.current.getBoundingClientRect() : null;
|
|
195
|
+
if (rect)
|
|
196
|
+
setAnchorRect({ x: rect.left, y: rect.bottom, width: rect.width });
|
|
197
|
+
};
|
|
198
|
+
const targets = [window];
|
|
199
|
+
let node = buttonRef.current;
|
|
200
|
+
while (node && node !== document.body) {
|
|
201
|
+
const style = window.getComputedStyle(node);
|
|
202
|
+
if (style.overflowY === "auto" || style.overflowY === "scroll" || style.overflow === "auto" || style.overflow === "scroll") {
|
|
203
|
+
targets.push(node);
|
|
204
|
+
}
|
|
205
|
+
node = node.parentElement;
|
|
206
|
+
}
|
|
207
|
+
targets.forEach((target) => {
|
|
208
|
+
target.addEventListener("scroll", reposition, { passive: true });
|
|
209
|
+
});
|
|
210
|
+
window.addEventListener("resize", reposition);
|
|
211
|
+
return () => {
|
|
212
|
+
targets.forEach((target) => {
|
|
213
|
+
target.removeEventListener("scroll", reposition);
|
|
214
|
+
});
|
|
215
|
+
window.removeEventListener("resize", reposition);
|
|
216
|
+
};
|
|
217
|
+
}, [isOpen, anchorRect]);
|
|
218
|
+
const currentOption = descriptor.options[selectedIndex === -1 ? 0 : selectedIndex];
|
|
219
|
+
const label = currentOption ? currentOption.label : descriptor.value;
|
|
220
|
+
const listbox = (anchorRect &&
|
|
221
|
+
isOpen &&
|
|
222
|
+
createPortal(createElement("div", {
|
|
223
|
+
ref: listboxRef,
|
|
224
|
+
id: listboxId,
|
|
225
|
+
role: "listbox",
|
|
226
|
+
"aria-label": descriptor.ariaLabel ?? descriptor.label,
|
|
227
|
+
"data-omnigrid-filter-trigger": "",
|
|
228
|
+
className: "omnigrid-select-listbox",
|
|
229
|
+
onKeyDown: handleListboxKeyDown,
|
|
230
|
+
onClick: (event) => {
|
|
231
|
+
event.stopPropagation();
|
|
232
|
+
},
|
|
233
|
+
style: {
|
|
234
|
+
left: `${anchorRect.x}px`,
|
|
235
|
+
top: `${anchorRect.y}px`,
|
|
236
|
+
minWidth: `${anchorRect.width}px`,
|
|
237
|
+
},
|
|
238
|
+
}, descriptor.options.map((option, index) => {
|
|
239
|
+
const selected = option.value === descriptor.value;
|
|
240
|
+
const focused = focusedIndex === index;
|
|
241
|
+
return createElement("div", {
|
|
242
|
+
key: option.value,
|
|
243
|
+
role: "option",
|
|
244
|
+
"aria-selected": selected,
|
|
245
|
+
tabIndex: focused ? 0 : -1,
|
|
246
|
+
"aria-disabled": option.disabled || undefined,
|
|
247
|
+
className: [
|
|
248
|
+
"omnigrid-select-option",
|
|
249
|
+
focused ? "omnigrid-select-option-focused" : null,
|
|
250
|
+
selected ? "omnigrid-select-option-selected" : null,
|
|
251
|
+
option.disabled ? "omnigrid-select-option-disabled" : null,
|
|
252
|
+
]
|
|
253
|
+
.filter(Boolean)
|
|
254
|
+
.join(" "),
|
|
255
|
+
onClick: () => selectOption(index),
|
|
256
|
+
onKeyDown: (event) => handleListboxKeyDown(event),
|
|
257
|
+
}, option.label);
|
|
258
|
+
})), document.body));
|
|
259
|
+
return createElement("div", {
|
|
260
|
+
className: ["omnigrid-select-wrapper", descriptor.className].filter(Boolean).join(" "),
|
|
261
|
+
}, createElement("button", {
|
|
262
|
+
ref: buttonRef,
|
|
263
|
+
type: "button",
|
|
264
|
+
role: "button",
|
|
265
|
+
"aria-haspopup": "listbox",
|
|
266
|
+
"aria-expanded": isOpen,
|
|
267
|
+
"aria-controls": listboxId,
|
|
268
|
+
"aria-label": descriptor.ariaLabel ?? descriptor.label,
|
|
269
|
+
className: ["omnigrid-select-button", descriptor.disabled ? "omnigrid-select-button-disabled" : null]
|
|
270
|
+
.filter(Boolean)
|
|
271
|
+
.join(" "),
|
|
272
|
+
disabled: descriptor.disabled,
|
|
273
|
+
onClick: (event) => {
|
|
274
|
+
event.stopPropagation();
|
|
275
|
+
setIsOpen((previous) => !previous);
|
|
276
|
+
},
|
|
277
|
+
onKeyDown: handleButtonKeyDown,
|
|
278
|
+
}, createElement("span", { className: "omnigrid-select-value" }, label), createElement("span", { className: "omnigrid-select-arrow", "aria-hidden": "true" }, "▼")), listbox);
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Custom-styled, searchable multi-select listbox with checkboxes for set/category filtering.
|
|
282
|
+
*/
|
|
283
|
+
function MultiSelectControl({ descriptor }) {
|
|
284
|
+
const [searchTerm, setSearchTerm] = useState("");
|
|
285
|
+
const filteredOptions = useMemo(() => {
|
|
286
|
+
if (!searchTerm.trim())
|
|
287
|
+
return descriptor.options;
|
|
288
|
+
const term = searchTerm.toLowerCase();
|
|
289
|
+
return descriptor.options.filter((opt) => opt.label.toLowerCase().includes(term) || opt.value.toLowerCase().includes(term));
|
|
290
|
+
}, [descriptor.options, searchTerm]);
|
|
291
|
+
const allChecked = useMemo(() => descriptor.options.length > 0 && descriptor.options.every((opt) => opt.checked), [descriptor.options]);
|
|
292
|
+
const toggleAll = (checked) => {
|
|
293
|
+
if (checked) {
|
|
294
|
+
descriptor.onChange(descriptor.options.map((opt) => opt.value));
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
descriptor.onChange([]);
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const toggleOption = (val, checked) => {
|
|
301
|
+
const currentlyChecked = new Set(descriptor.options.filter((opt) => opt.checked).map((opt) => opt.value));
|
|
302
|
+
if (checked) {
|
|
303
|
+
currentlyChecked.add(val);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
currentlyChecked.delete(val);
|
|
307
|
+
}
|
|
308
|
+
descriptor.onChange(Array.from(currentlyChecked));
|
|
309
|
+
};
|
|
310
|
+
return createElement("div", { className: ["omnigrid-multi-select-container", descriptor.className].filter(Boolean).join(" ") }, createElement("div", { className: "omnigrid-control-input-wrapper" }, createElement("input", {
|
|
311
|
+
className: "omnigrid-control-input",
|
|
312
|
+
type: "text",
|
|
313
|
+
placeholder: descriptor.searchPlaceholder ?? "Search...",
|
|
314
|
+
value: searchTerm,
|
|
315
|
+
onChange: (e) => setSearchTerm(e.target.value),
|
|
316
|
+
onClick: (e) => e.stopPropagation(),
|
|
317
|
+
}), searchTerm.length > 0 &&
|
|
318
|
+
createElement("button", {
|
|
319
|
+
type: "button",
|
|
320
|
+
className: "omnigrid-control-clear",
|
|
321
|
+
"aria-label": "Clear search",
|
|
322
|
+
onClick: (e) => {
|
|
323
|
+
e.stopPropagation();
|
|
324
|
+
setSearchTerm("");
|
|
325
|
+
},
|
|
326
|
+
}, "×")), createElement("div", { className: "omnigrid-multi-select-actions" }, createElement("label", { className: "omnigrid-multi-select-item" }, createElement("input", {
|
|
327
|
+
type: "checkbox",
|
|
328
|
+
className: "omnigrid-checkbox",
|
|
329
|
+
checked: allChecked,
|
|
330
|
+
onChange: (e) => toggleAll(e.target.checked),
|
|
331
|
+
}), createElement("span", { className: "omnigrid-multi-select-label" }, "(Select all)"))), createElement("div", { className: "omnigrid-multi-select-list" }, filteredOptions.map((option) => createElement("label", { key: option.value, className: "omnigrid-multi-select-item" }, createElement("input", {
|
|
332
|
+
type: "checkbox",
|
|
333
|
+
className: "omnigrid-checkbox",
|
|
334
|
+
checked: option.checked,
|
|
335
|
+
onChange: (e) => toggleOption(option.value, e.target.checked),
|
|
336
|
+
}), createElement("span", { className: "omnigrid-multi-select-label" }, option.label)))));
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
* Renders one framework-agnostic control descriptor with native HTML elements.
|
|
340
|
+
* Descriptor `id`s become React keys, so re-describing a popup updates
|
|
341
|
+
* elements in place instead of remounting them.
|
|
342
|
+
* @param descriptor - Control descriptor to materialise.
|
|
343
|
+
* @param resolveIcon - Optional resolver mapping `descriptor.icon` names to nodes; backed by the grid icon registry.
|
|
344
|
+
*/
|
|
345
|
+
export function renderControl(descriptor, resolveIcon) {
|
|
346
|
+
switch (descriptor.type) {
|
|
347
|
+
case "text":
|
|
348
|
+
case "number":
|
|
349
|
+
case "date":
|
|
350
|
+
return withLabel(descriptor, createElement(DebouncedInput, { descriptor }), false, resolveIcon);
|
|
351
|
+
case "select":
|
|
352
|
+
return withLabel(descriptor, createElement(SelectControl, { descriptor }), false, resolveIcon);
|
|
353
|
+
case "multi-select":
|
|
354
|
+
return withLabel(descriptor, createElement(MultiSelectControl, { descriptor }), false, resolveIcon);
|
|
355
|
+
case "checkbox":
|
|
356
|
+
return withLabel(descriptor, createElement("input", {
|
|
357
|
+
type: "checkbox",
|
|
358
|
+
className: ["omnigrid-checkbox", descriptor.className].filter(Boolean).join(" "),
|
|
359
|
+
checked: descriptor.checked,
|
|
360
|
+
disabled: descriptor.disabled,
|
|
361
|
+
onChange: (event) => descriptor.onChange(event.target.checked),
|
|
362
|
+
}), true, resolveIcon);
|
|
363
|
+
case "button":
|
|
364
|
+
return createElement("button", {
|
|
365
|
+
key: descriptor.id,
|
|
366
|
+
type: "button",
|
|
367
|
+
className: ["omnigrid-control-button", descriptor.variant === "primary" ? "omnigrid-control-button-primary" : null, descriptor.className]
|
|
368
|
+
.filter(Boolean)
|
|
369
|
+
.join(" "),
|
|
370
|
+
disabled: descriptor.disabled,
|
|
371
|
+
onClick: () => descriptor.onClick(),
|
|
372
|
+
}, descriptor.text);
|
|
373
|
+
case "label":
|
|
374
|
+
return createElement("div", { key: descriptor.id, className: ["omnigrid-control-label", descriptor.className].filter(Boolean).join(" ") }, descriptor.text);
|
|
375
|
+
case "group":
|
|
376
|
+
return createElement("div", {
|
|
377
|
+
key: descriptor.id,
|
|
378
|
+
className: ["omnigrid-control", "omnigrid-control-group", descriptor.direction === "row" ? "omnigrid-control-group-row" : null, descriptor.className]
|
|
379
|
+
.filter(Boolean)
|
|
380
|
+
.join(" "),
|
|
381
|
+
}, descriptor.children.map((child) => renderControl(child, resolveIcon)));
|
|
382
|
+
default:
|
|
383
|
+
return null;
|
|
384
|
+
}
|
|
385
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,9 @@ export type { PooledCellRenderInfo, PooledColumn, PooledRowCallbacks, PooledRowM
|
|
|
6
6
|
export { OmniGrid } from "./OmniGrid";
|
|
7
7
|
export type { GridProps, OverlayComponentProps, SlotRendererRegistry } from "./OmniGrid";
|
|
8
8
|
export { useGrid } from "./useGrid";
|
|
9
|
+
export { DebouncedInput, isUIControlDescriptor, renderControl } from "./controls";
|
|
10
|
+
export type { DebouncedInputProps } from "./controls";
|
|
11
|
+
export { PopupHost } from "./popup";
|
|
12
|
+
export type { PopupHostProps } from "./popup";
|
|
9
13
|
export type { UseGridResult } from "./useGrid";
|
|
10
14
|
export { type ResolvedColumnPresentation, resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
package/dist/index.js
CHANGED
|
@@ -4,4 +4,6 @@ export * from "@omnigrid/core";
|
|
|
4
4
|
export { PooledRowPane } from "./pooledRow";
|
|
5
5
|
export { OmniGrid } from "./OmniGrid";
|
|
6
6
|
export { useGrid } from "./useGrid";
|
|
7
|
+
export { DebouncedInput, isUIControlDescriptor, renderControl } from "./controls";
|
|
8
|
+
export { PopupHost } from "./popup";
|
|
7
9
|
export { resolveCellClasses, resolveCellStyle, resolveColumnPresentation, resolveGroupHeaderClasses, resolveGroupHeaderStyle, resolveHeaderClasses, resolveHeaderStyle, } from "./styling";
|
package/dist/popup.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { GridApi } from "@omnigrid/core";
|
|
3
|
+
export interface PopupHostProps<T> {
|
|
4
|
+
grid: GridApi<T>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Renders the grid's active `UIPopupDescriptor`. Popup state lives here, so
|
|
8
|
+
* opening or updating a popup never re-renders the grid body. The popup is
|
|
9
|
+
* `position: fixed`, which keeps it out of the grid's layout and scroll flow.
|
|
10
|
+
*/
|
|
11
|
+
export declare function PopupHost<T>({ grid }: PopupHostProps<T>): ReactNode;
|
package/dist/popup.js
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createElement, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
import { contentToReactNode } from "./content";
|
|
3
|
+
const VIEWPORT_MARGIN = 8;
|
|
4
|
+
function anchorStyle(popup) {
|
|
5
|
+
const base = { position: "absolute", zIndex: 1000 };
|
|
6
|
+
const anchor = popup.anchor;
|
|
7
|
+
if (!anchor)
|
|
8
|
+
return { ...base, left: "50%", top: "50%", transform: "translate(-50%, -50%)" };
|
|
9
|
+
const top = anchor.y + (anchor.height ?? 0);
|
|
10
|
+
if (popup.placement === "bottom-end")
|
|
11
|
+
return { ...base, left: anchor.x + (anchor.width ?? 0), top, transform: "translateX(-100%)" };
|
|
12
|
+
return { ...base, left: anchor.x, top };
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Renders the grid's active `UIPopupDescriptor`. Popup state lives here, so
|
|
16
|
+
* opening or updating a popup never re-renders the grid body. The popup is
|
|
17
|
+
* `position: fixed`, which keeps it out of the grid's layout and scroll flow.
|
|
18
|
+
*/
|
|
19
|
+
export function PopupHost({ grid }) {
|
|
20
|
+
const [popup, setPopup] = useState(() => grid.getPopup());
|
|
21
|
+
const elementRef = useRef(null);
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
setPopup(grid.getPopup());
|
|
24
|
+
return grid.on("popupChange", setPopup);
|
|
25
|
+
}, [grid]);
|
|
26
|
+
const closeOnOutside = popup?.closeOnOutsideClick ?? true;
|
|
27
|
+
const closeOnEscape = popup?.closeOnEscape ?? true;
|
|
28
|
+
const isOpen = popup !== null;
|
|
29
|
+
useEffect(() => {
|
|
30
|
+
if (!isOpen)
|
|
31
|
+
return undefined;
|
|
32
|
+
const handlePointerDown = (event) => {
|
|
33
|
+
if (!closeOnOutside)
|
|
34
|
+
return;
|
|
35
|
+
if (event.target instanceof Element && event.target.closest("[data-omnigrid-filter-trigger]"))
|
|
36
|
+
return;
|
|
37
|
+
const element = elementRef.current;
|
|
38
|
+
if (element && event.target instanceof Node && !element.contains(event.target))
|
|
39
|
+
grid.closePopup();
|
|
40
|
+
};
|
|
41
|
+
const handleKeyDown = (event) => {
|
|
42
|
+
if (closeOnEscape && event.key === "Escape")
|
|
43
|
+
grid.closePopup();
|
|
44
|
+
};
|
|
45
|
+
document.addEventListener("pointerdown", handlePointerDown, true);
|
|
46
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
47
|
+
return () => {
|
|
48
|
+
document.removeEventListener("pointerdown", handlePointerDown, true);
|
|
49
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
50
|
+
};
|
|
51
|
+
}, [grid, isOpen, closeOnOutside, closeOnEscape]);
|
|
52
|
+
// Keep an anchored popup inside the window: a single measurement per popup change.
|
|
53
|
+
useLayoutEffect(() => {
|
|
54
|
+
const element = elementRef.current;
|
|
55
|
+
if (!element || !popup?.anchor)
|
|
56
|
+
return;
|
|
57
|
+
const rect = element.getBoundingClientRect();
|
|
58
|
+
const parent = element.parentElement;
|
|
59
|
+
const parentRect = parent ? parent.getBoundingClientRect() : { left: 0, top: 0 };
|
|
60
|
+
const maxLeft = Math.max(VIEWPORT_MARGIN, window.innerWidth - VIEWPORT_MARGIN - rect.width);
|
|
61
|
+
const left = Math.min(Math.max(rect.left, VIEWPORT_MARGIN), maxLeft);
|
|
62
|
+
if (left !== rect.left) {
|
|
63
|
+
element.style.transform = "none";
|
|
64
|
+
element.style.left = `${left - parentRect.left}px`;
|
|
65
|
+
}
|
|
66
|
+
}, [popup]);
|
|
67
|
+
if (!popup)
|
|
68
|
+
return null;
|
|
69
|
+
const bridge = {
|
|
70
|
+
registry: {},
|
|
71
|
+
context: () => ({ api: grid, state: grid.getState() }),
|
|
72
|
+
};
|
|
73
|
+
return createElement("div", {
|
|
74
|
+
key: popup.id,
|
|
75
|
+
ref: elementRef,
|
|
76
|
+
role: "dialog",
|
|
77
|
+
"aria-label": popup.title ?? popup.id,
|
|
78
|
+
className: ["omnigrid-popup", popup.className].filter(Boolean).join(" "),
|
|
79
|
+
style: anchorStyle(popup),
|
|
80
|
+
}, popup.title ? createElement("div", { className: "omnigrid-popup-title" }, popup.title) : null, popup.controls.map((control) => contentToReactNode(control, bridge)));
|
|
81
|
+
}
|
package/dist/useGrid.js
CHANGED
|
@@ -88,6 +88,19 @@ export function useGrid(options) {
|
|
|
88
88
|
grid.setColumns(options.columns);
|
|
89
89
|
}
|
|
90
90
|
}, [grid, options.columns]);
|
|
91
|
+
// Controlled filter model: applied when the host passes a new reference.
|
|
92
|
+
// Skipped on the first run — the Grid constructor already applied it.
|
|
93
|
+
const filterSyncedRef = useRef(false);
|
|
94
|
+
useEffect(() => {
|
|
95
|
+
if (grid.isDestroyed())
|
|
96
|
+
return;
|
|
97
|
+
if (!filterSyncedRef.current) {
|
|
98
|
+
filterSyncedRef.current = true;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (options.filterModel)
|
|
102
|
+
grid.setFilterModel(options.filterModel);
|
|
103
|
+
}, [grid, options.filterModel]);
|
|
91
104
|
// Sync loading state. An explicit boolean prop always wins and is applied
|
|
92
105
|
// on every change (including the first flush — the Grid constructor may
|
|
93
106
|
// have been created with a stale value). `undefined` means the host does
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omnigrid/react",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "React adapter and renderer for OmniGrid",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"omnigrid",
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"@omnigrid/default-theme": "^0.1.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
+
"@omnigrid/quick-filter-plugin": "*",
|
|
48
49
|
"@types/react": "^19.0.0",
|
|
49
50
|
"@types/react-dom": "^19.0.0"
|
|
50
51
|
},
|