@ox0/data-grid 0.1.22 → 0.3.0
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/components/DataCell.d.ts +3 -1
- package/dist/components/DataCell.d.ts.map +1 -1
- package/dist/components/DataGrid.cell-actions.test.d.ts +2 -0
- package/dist/components/DataGrid.cell-actions.test.d.ts.map +1 -0
- package/dist/components/DataGrid.d.ts.map +1 -1
- package/dist/components/VirtualScroller.d.ts +5 -2
- package/dist/components/VirtualScroller.d.ts.map +1 -1
- package/dist/components/auto-width.d.ts +2 -0
- package/dist/components/auto-width.d.ts.map +1 -1
- package/dist/components/cell-actions.d.ts +71 -0
- package/dist/components/cell-actions.d.ts.map +1 -0
- package/dist/components/column-layout.d.ts +22 -1
- package/dist/components/column-layout.d.ts.map +1 -1
- package/dist/hooks/midnight.d.ts.map +1 -1
- package/dist/index.js +725 -48
- package/dist/omnibar/highlight.d.ts.map +1 -1
- package/dist/types.d.ts +31 -2
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -5
package/dist/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useControllableState, useDebouncedValue, usePrefersReducedMotion } from "@ox0/hooks";
|
|
2
|
+
import { useControllableState, useDebouncedValue, useOS, usePrefersReducedMotion } from "@ox0/hooks";
|
|
3
|
+
import { editFieldValue } from "@ox0/query";
|
|
3
4
|
import { QueryBar } from "@ox0/query/react";
|
|
4
|
-
import { Button, Checkbox, Drawer, IconButton, MarkProvider, Markable, Menu, MenuItem, Popover, PopoverContent, PopoverTrigger, SearchField, Skeleton, Spinner, TextField, Tooltip, TooltipContent, useOptionalToast } from "@ox0/ui";
|
|
5
|
+
import { Button, Checkbox, Drawer, IconButton, MarkProvider, Markable, Menu, MenuItem, MenuSection, Popover, PopoverContent, PopoverTrigger, SearchField, Skeleton, Spinner, TextField, Tooltip, TooltipContent, useOptionalToast } from "@ox0/ui";
|
|
5
6
|
import { Fragment as external_react_Fragment, memo, startTransition as external_react_startTransition, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState, useTransition } from "react";
|
|
6
7
|
import { useStore } from "zustand";
|
|
7
8
|
import { createStore } from "zustand/vanilla";
|
|
8
9
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
10
|
+
import { flushSync } from "react-dom";
|
|
9
11
|
import { __webpack_require__ } from "./rslib-runtime.js";
|
|
10
12
|
import { scanFractionDigits, createMessageHandler } from "./774.js";
|
|
11
13
|
__webpack_require__.add({
|
|
@@ -550,6 +552,7 @@ __webpack_require__.add({
|
|
|
550
552
|
.cellText-Ge3QlA {
|
|
551
553
|
text-overflow: ellipsis;
|
|
552
554
|
white-space: nowrap;
|
|
555
|
+
flex: auto;
|
|
553
556
|
min-width: 0;
|
|
554
557
|
overflow: hidden;
|
|
555
558
|
}
|
|
@@ -562,6 +565,7 @@ __webpack_require__.add({
|
|
|
562
565
|
|
|
563
566
|
.cellWrap-lWoNaf {
|
|
564
567
|
overflow-wrap: anywhere;
|
|
568
|
+
flex: auto;
|
|
565
569
|
min-width: 0;
|
|
566
570
|
}
|
|
567
571
|
|
|
@@ -769,6 +773,49 @@ __webpack_require__.add({
|
|
|
769
773
|
position: absolute;
|
|
770
774
|
overflow: hidden;
|
|
771
775
|
}
|
|
776
|
+
|
|
777
|
+
.cellActions-xWCXK6 {
|
|
778
|
+
padding: 0 var(--ox0-space-2xs);
|
|
779
|
+
pointer-events: none;
|
|
780
|
+
z-index: 4;
|
|
781
|
+
align-items: center;
|
|
782
|
+
display: none;
|
|
783
|
+
position: absolute;
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
.cellActions-xWCXK6[data-shown] {
|
|
787
|
+
display: flex;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
.cellActions-xWCXK6[data-side="end"] {
|
|
791
|
+
justify-content: flex-end;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
.cellActions-xWCXK6 > * {
|
|
795
|
+
pointer-events: auto;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
.cell-q3dXM7[data-actions-hover] > * {
|
|
799
|
+
mask-image: linear-gradient(to left, #0000 0 24px, #000 40px);
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
.cell-q3dXM7[data-align="end"] > .cellText-Ge3QlA, .cell-q3dXM7[data-align="end"] > .cellWrap-lWoNaf {
|
|
803
|
+
text-align: end;
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
.cell-q3dXM7[data-align="end"][data-actions-hover] > * {
|
|
807
|
+
mask-image: linear-gradient(to right, #0000 0 24px, #000 40px);
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
.cell-q3dXM7[data-filter-pending="include"] {
|
|
811
|
+
background: var(--ox0-color-accent-subtle);
|
|
812
|
+
box-shadow: inset 0 0 0 1px var(--ox0-color-accent);
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
.cell-q3dXM7[data-filter-pending="exclude"] {
|
|
816
|
+
color: var(--ox0-color-text-secondary);
|
|
817
|
+
text-decoration: line-through;
|
|
818
|
+
}
|
|
772
819
|
`,
|
|
773
820
|
""
|
|
774
821
|
]);
|
|
@@ -829,7 +876,8 @@ __webpack_require__.add({
|
|
|
829
876
|
count: "count-FBgM_P",
|
|
830
877
|
loadStatus: "loadStatus-e4Tv3g",
|
|
831
878
|
statusEnd: "statusEnd-U9ISsx",
|
|
832
|
-
visuallyHidden: "visuallyHidden-whkcjO"
|
|
879
|
+
visuallyHidden: "visuallyHidden-whkcjO",
|
|
880
|
+
cellActions: "cellActions-xWCXK6"
|
|
833
881
|
};
|
|
834
882
|
const __rspack_default_export = ___CSS_LOADER_EXPORT___;
|
|
835
883
|
__webpack_require__.d(__webpack_exports__, {}, {
|
|
@@ -2415,7 +2463,7 @@ function createEngine(kind) {
|
|
|
2415
2463
|
}
|
|
2416
2464
|
const DAY_MS = 86400000;
|
|
2417
2465
|
function dependsOnToday(tokens) {
|
|
2418
|
-
return tokens.some((token)=>"field" === token.type && "date" === token.dataType && ("within-last" === token.operator || "within-next" === token.operator || "between" === token.operator && true === token.openEnd));
|
|
2466
|
+
return tokens.some((token)=>"field" === token.type && "date" === token.dataType && ("within-last" === token.operator || "within-next" === token.operator || "between" === token.operator && true === token.openEnd || ("in" === token.operator || "not-in" === token.operator) && token.ranges.some((range)=>true === range.openEnd)));
|
|
2419
2467
|
}
|
|
2420
2468
|
const wallFormatters = new Map();
|
|
2421
2469
|
function wallFormatter(timeZone) {
|
|
@@ -3237,6 +3285,10 @@ function highlightTerms(tokens) {
|
|
|
3237
3285
|
token.value
|
|
3238
3286
|
], isCaseSensitive);
|
|
3239
3287
|
if ("matches" === token.operator) add(token.field, token.pattern, isCaseSensitive);
|
|
3288
|
+
if ("in" === token.operator) add(token.field, [
|
|
3289
|
+
...token.values,
|
|
3290
|
+
...(token.patterns ?? []).flat()
|
|
3291
|
+
], isCaseSensitive);
|
|
3240
3292
|
} else if ("field" === token.type && "enum" === token.dataType && "in" === token.operator) add(token.field, [
|
|
3241
3293
|
...token.values,
|
|
3242
3294
|
...(token.patterns ?? []).flat()
|
|
@@ -3292,12 +3344,323 @@ function measureAutoWidths(input) {
|
|
|
3292
3344
|
const widths = new Map();
|
|
3293
3345
|
for (const column of input.columns){
|
|
3294
3346
|
if (column.cell) continue;
|
|
3295
|
-
let widest =
|
|
3347
|
+
let widest = headerWidth(column, input);
|
|
3296
3348
|
for (const text of input.sampleText(column))if ("" !== text) widest = Math.max(widest, input.measure(text, input.cellFont) + input.cellPadding);
|
|
3297
3349
|
widths.set(column.id, Math.ceil(widest));
|
|
3298
3350
|
}
|
|
3299
3351
|
return widths;
|
|
3300
3352
|
}
|
|
3353
|
+
function measureHeaderWidths(input) {
|
|
3354
|
+
return new Map(input.columns.map((column)=>[
|
|
3355
|
+
column.id,
|
|
3356
|
+
Math.ceil(headerWidth(column, input))
|
|
3357
|
+
]));
|
|
3358
|
+
}
|
|
3359
|
+
function headerWidth(column, input) {
|
|
3360
|
+
return input.measure(column.header, input.headerFont) + input.headerPadding + (column.sortable ? SORT_INDICATOR_ALLOWANCE : 0);
|
|
3361
|
+
}
|
|
3362
|
+
const injectStylesIntoStyleTag = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/injectStylesIntoStyleTag.js");
|
|
3363
|
+
var injectStylesIntoStyleTag_default = /*#__PURE__*/ __webpack_require__.n(injectStylesIntoStyleTag);
|
|
3364
|
+
const styleDomAPI = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/styleDomAPI.js");
|
|
3365
|
+
var styleDomAPI_default = /*#__PURE__*/ __webpack_require__.n(styleDomAPI);
|
|
3366
|
+
const insertBySelector = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/insertBySelector.js");
|
|
3367
|
+
var insertBySelector_default = /*#__PURE__*/ __webpack_require__.n(insertBySelector);
|
|
3368
|
+
const setAttributesWithoutAttributes = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/setAttributesWithoutAttributes.js");
|
|
3369
|
+
var setAttributesWithoutAttributes_default = /*#__PURE__*/ __webpack_require__.n(setAttributesWithoutAttributes);
|
|
3370
|
+
const insertStyleElement = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/insertStyleElement.js");
|
|
3371
|
+
var insertStyleElement_default = /*#__PURE__*/ __webpack_require__.n(insertStyleElement);
|
|
3372
|
+
const styleTagTransform = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/styleTagTransform.js");
|
|
3373
|
+
var styleTagTransform_default = /*#__PURE__*/ __webpack_require__.n(styleTagTransform);
|
|
3374
|
+
const data_grid_module_0 = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/css-loader/index.js??ruleSet[1].rules[1].oneOf[4].use[1]!builtin:lightningcss-loader??ruleSet[1].rules[1].oneOf[4].use[2]!./src/components/data-grid.module.css");
|
|
3375
|
+
var data_grid_module_options = {};
|
|
3376
|
+
data_grid_module_options.styleTagTransform = styleTagTransform_default();
|
|
3377
|
+
data_grid_module_options.setAttributes = setAttributesWithoutAttributes_default();
|
|
3378
|
+
data_grid_module_options.insert = insertBySelector_default().bind(null, "head");
|
|
3379
|
+
data_grid_module_options.domAPI = styleDomAPI_default();
|
|
3380
|
+
data_grid_module_options.insertStyleElement = insertStyleElement_default();
|
|
3381
|
+
injectStylesIntoStyleTag_default()(data_grid_module_0.A, data_grid_module_options);
|
|
3382
|
+
const data_grid_module = data_grid_module_0.A && data_grid_module_0.A.locals ? data_grid_module_0.A.locals : void 0;
|
|
3383
|
+
const HOVER_ATTRIBUTE = "data-actions-hover";
|
|
3384
|
+
function placeAnchor(anchor, cellRef, cell) {
|
|
3385
|
+
const previous = cellRef.current;
|
|
3386
|
+
if (previous && previous !== cell) previous.removeAttribute(HOVER_ATTRIBUTE);
|
|
3387
|
+
cellRef.current = cell;
|
|
3388
|
+
if (!anchor) return;
|
|
3389
|
+
const frame = anchor.parentElement;
|
|
3390
|
+
if (!cell || !(frame instanceof HTMLElement)) return void delete anchor.dataset.shown;
|
|
3391
|
+
cell.setAttribute(HOVER_ATTRIBUTE, "");
|
|
3392
|
+
const box = cell.getBoundingClientRect();
|
|
3393
|
+
const frameBox = frame.getBoundingClientRect();
|
|
3394
|
+
anchor.dataset.shown = "";
|
|
3395
|
+
anchor.style.top = `${box.top - frameBox.top}px`;
|
|
3396
|
+
anchor.style.left = `${box.left - frameBox.left}px`;
|
|
3397
|
+
anchor.style.width = `${box.width}px`;
|
|
3398
|
+
anchor.style.height = `${box.height}px`;
|
|
3399
|
+
anchor.dataset.side = "end" === cell.dataset.align ? "start" : "end";
|
|
3400
|
+
}
|
|
3401
|
+
function CellActions({ apiRef, sectionsFor, onAction, labelFor }) {
|
|
3402
|
+
const anchorRef = useRef(null);
|
|
3403
|
+
const cellRef = useRef(null);
|
|
3404
|
+
const rowRef = useRef(null);
|
|
3405
|
+
const isOpenRef = useRef(false);
|
|
3406
|
+
const shiftRef = useRef(false);
|
|
3407
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
3408
|
+
const [label, setLabel] = useState("");
|
|
3409
|
+
const [sections, setSections] = useState([]);
|
|
3410
|
+
const latest = useRef({
|
|
3411
|
+
sectionsFor,
|
|
3412
|
+
labelFor
|
|
3413
|
+
});
|
|
3414
|
+
useEffect(()=>{
|
|
3415
|
+
latest.current = {
|
|
3416
|
+
sectionsFor,
|
|
3417
|
+
labelFor
|
|
3418
|
+
};
|
|
3419
|
+
});
|
|
3420
|
+
const place = (cell)=>placeAnchor(anchorRef.current, cellRef, cell);
|
|
3421
|
+
useEffect(()=>{
|
|
3422
|
+
const api = {
|
|
3423
|
+
hover: (cell)=>{
|
|
3424
|
+
if (isOpenRef.current || cell === cellRef.current) return;
|
|
3425
|
+
placeAnchor(anchorRef.current, cellRef, cell);
|
|
3426
|
+
if (cell) setLabel(latest.current.labelFor(cell));
|
|
3427
|
+
},
|
|
3428
|
+
open: (cell, options = {})=>{
|
|
3429
|
+
placeAnchor(anchorRef.current, cellRef, cell);
|
|
3430
|
+
setLabel(latest.current.labelFor(cell));
|
|
3431
|
+
rowRef.current = options.row ?? null;
|
|
3432
|
+
const next = latest.current.sectionsFor(cell, options.row);
|
|
3433
|
+
if (0 === next.length) return;
|
|
3434
|
+
setSections(next);
|
|
3435
|
+
isOpenRef.current = true;
|
|
3436
|
+
setIsOpen(true);
|
|
3437
|
+
}
|
|
3438
|
+
};
|
|
3439
|
+
apiRef.current = api;
|
|
3440
|
+
return ()=>{
|
|
3441
|
+
apiRef.current = null;
|
|
3442
|
+
};
|
|
3443
|
+
}, [
|
|
3444
|
+
apiRef
|
|
3445
|
+
]);
|
|
3446
|
+
useEffect(()=>{
|
|
3447
|
+
if (!isOpen) return;
|
|
3448
|
+
const track = (event)=>{
|
|
3449
|
+
shiftRef.current = event.shiftKey;
|
|
3450
|
+
};
|
|
3451
|
+
window.addEventListener("keydown", track, true);
|
|
3452
|
+
window.addEventListener("pointerdown", track, true);
|
|
3453
|
+
return ()=>{
|
|
3454
|
+
window.removeEventListener("keydown", track, true);
|
|
3455
|
+
window.removeEventListener("pointerdown", track, true);
|
|
3456
|
+
};
|
|
3457
|
+
}, [
|
|
3458
|
+
isOpen
|
|
3459
|
+
]);
|
|
3460
|
+
function handleOpenChange(next) {
|
|
3461
|
+
if (next) {
|
|
3462
|
+
const cell = cellRef.current;
|
|
3463
|
+
const opened = cell ? latest.current.sectionsFor(cell, void 0) : [];
|
|
3464
|
+
if (0 === opened.length) return;
|
|
3465
|
+
rowRef.current = null;
|
|
3466
|
+
setSections(opened);
|
|
3467
|
+
}
|
|
3468
|
+
isOpenRef.current = next;
|
|
3469
|
+
setIsOpen(next);
|
|
3470
|
+
if (!next) {
|
|
3471
|
+
rowRef.current?.focus();
|
|
3472
|
+
rowRef.current = null;
|
|
3473
|
+
place(null);
|
|
3474
|
+
}
|
|
3475
|
+
}
|
|
3476
|
+
return /*#__PURE__*/ jsx("div", {
|
|
3477
|
+
className: data_grid_module.cellActions,
|
|
3478
|
+
"data-cell-actions": "",
|
|
3479
|
+
ref: anchorRef,
|
|
3480
|
+
children: /*#__PURE__*/ jsx(Menu, {
|
|
3481
|
+
"aria-label": "Filter options",
|
|
3482
|
+
isOpen: isOpen,
|
|
3483
|
+
onOpenChange: handleOpenChange,
|
|
3484
|
+
trigger: /*#__PURE__*/ jsx(IconButton, {
|
|
3485
|
+
icon: MoreHorizontalIcon,
|
|
3486
|
+
label: label,
|
|
3487
|
+
size: "xs",
|
|
3488
|
+
tabIndex: -1,
|
|
3489
|
+
tooltipPlacement: "bottom",
|
|
3490
|
+
variant: "ghost"
|
|
3491
|
+
}),
|
|
3492
|
+
children: sections.map((section)=>/*#__PURE__*/ jsx(MenuSection, {
|
|
3493
|
+
label: section.label,
|
|
3494
|
+
children: section.actions.map((action)=>/*#__PURE__*/ jsx(MenuItem, {
|
|
3495
|
+
hint: action.hint,
|
|
3496
|
+
id: `${section.key}:${action.id}`,
|
|
3497
|
+
onSelect: ()=>onAction(section, action, shiftRef.current),
|
|
3498
|
+
children: action.label
|
|
3499
|
+
}, action.id))
|
|
3500
|
+
}, section.key))
|
|
3501
|
+
})
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
function MoreHorizontalIcon({ size = 12 }) {
|
|
3505
|
+
return /*#__PURE__*/ jsxs("svg", {
|
|
3506
|
+
"aria-hidden": "true",
|
|
3507
|
+
fill: "currentColor",
|
|
3508
|
+
height: size,
|
|
3509
|
+
viewBox: "0 0 16 16",
|
|
3510
|
+
width: size,
|
|
3511
|
+
children: [
|
|
3512
|
+
/*#__PURE__*/ jsx("circle", {
|
|
3513
|
+
cx: "3",
|
|
3514
|
+
cy: "8",
|
|
3515
|
+
r: "1.5"
|
|
3516
|
+
}),
|
|
3517
|
+
/*#__PURE__*/ jsx("circle", {
|
|
3518
|
+
cx: "8",
|
|
3519
|
+
cy: "8",
|
|
3520
|
+
r: "1.5"
|
|
3521
|
+
}),
|
|
3522
|
+
/*#__PURE__*/ jsx("circle", {
|
|
3523
|
+
cx: "13",
|
|
3524
|
+
cy: "8",
|
|
3525
|
+
r: "1.5"
|
|
3526
|
+
})
|
|
3527
|
+
]
|
|
3528
|
+
});
|
|
3529
|
+
}
|
|
3530
|
+
const dayFormatters = new Map();
|
|
3531
|
+
function isoDay(date, timeZone) {
|
|
3532
|
+
const key = timeZone ?? "";
|
|
3533
|
+
let formatter = dayFormatters.get(key);
|
|
3534
|
+
if (!formatter) {
|
|
3535
|
+
formatter = new Intl.DateTimeFormat("en-US", {
|
|
3536
|
+
day: "2-digit",
|
|
3537
|
+
month: "2-digit",
|
|
3538
|
+
timeZone,
|
|
3539
|
+
year: "numeric"
|
|
3540
|
+
});
|
|
3541
|
+
dayFormatters.set(key, formatter);
|
|
3542
|
+
}
|
|
3543
|
+
const parts = formatter.formatToParts(date);
|
|
3544
|
+
const part = (type)=>parts.find((p)=>p.type === type)?.value ?? "";
|
|
3545
|
+
return `${part("year")}-${part("month")}-${part("day")}`;
|
|
3546
|
+
}
|
|
3547
|
+
function filterValue(raw, type, timeZone) {
|
|
3548
|
+
if (null == raw || "" === raw) return null;
|
|
3549
|
+
switch(type){
|
|
3550
|
+
case "numeric":
|
|
3551
|
+
{
|
|
3552
|
+
const n = "number" == typeof raw ? raw : Number(raw);
|
|
3553
|
+
return Number.isFinite(n) ? n : null;
|
|
3554
|
+
}
|
|
3555
|
+
case "date":
|
|
3556
|
+
{
|
|
3557
|
+
if ("string" == typeof raw && /^\d{4}-\d{2}-\d{2}$/.test(raw)) return raw;
|
|
3558
|
+
const date = raw instanceof Date ? raw : "string" == typeof raw || "number" == typeof raw ? new Date(raw) : null;
|
|
3559
|
+
return date && !Number.isNaN(date.getTime()) ? isoDay(date, timeZone) : null;
|
|
3560
|
+
}
|
|
3561
|
+
case "text":
|
|
3562
|
+
case "enum":
|
|
3563
|
+
return "string" == typeof raw || "number" == typeof raw || "boolean" == typeof raw ? String(raw) : null;
|
|
3564
|
+
}
|
|
3565
|
+
}
|
|
3566
|
+
function cellFilterValues(raw, type, timeZone) {
|
|
3567
|
+
if (Array.isArray(raw)) {
|
|
3568
|
+
const values = raw.map((item)=>filterValue(item, type, timeZone)).filter((value)=>null !== value);
|
|
3569
|
+
return values.length > 0 ? values : [
|
|
3570
|
+
null
|
|
3571
|
+
];
|
|
3572
|
+
}
|
|
3573
|
+
return [
|
|
3574
|
+
filterValue(raw, type, timeZone)
|
|
3575
|
+
];
|
|
3576
|
+
}
|
|
3577
|
+
function valueKey(value) {
|
|
3578
|
+
return "string" == typeof value ? value.toLowerCase() : String(value);
|
|
3579
|
+
}
|
|
3580
|
+
function pendingMarks(tokens) {
|
|
3581
|
+
const marks = new Map();
|
|
3582
|
+
if (!tokens) return marks;
|
|
3583
|
+
const add = (field, isNegative, keys)=>{
|
|
3584
|
+
const entry = marks.get(field) ?? {
|
|
3585
|
+
include: new Set(),
|
|
3586
|
+
exclude: new Set()
|
|
3587
|
+
};
|
|
3588
|
+
for (const key of keys)(isNegative ? entry.exclude : entry.include).add(key);
|
|
3589
|
+
marks.set(field, entry);
|
|
3590
|
+
};
|
|
3591
|
+
for (const token of tokens)if ("field" === token.type) switch(token.operator){
|
|
3592
|
+
case "equals":
|
|
3593
|
+
case "not-equals":
|
|
3594
|
+
add(token.field, "not-equals" === token.operator, [
|
|
3595
|
+
token.value.toLowerCase()
|
|
3596
|
+
]);
|
|
3597
|
+
break;
|
|
3598
|
+
case "eq":
|
|
3599
|
+
case "on":
|
|
3600
|
+
if (void 0 !== token.value) add(token.field, false, [
|
|
3601
|
+
valueKey(token.value)
|
|
3602
|
+
]);
|
|
3603
|
+
break;
|
|
3604
|
+
case "in":
|
|
3605
|
+
case "not-in":
|
|
3606
|
+
{
|
|
3607
|
+
const isNegative = "not-in" === token.operator;
|
|
3608
|
+
if ("values" in token) add(token.field, isNegative, token.values.map(valueKey));
|
|
3609
|
+
else {
|
|
3610
|
+
const singles = token.ranges.filter((range)=>void 0 !== range.value && range.value === range.valueTo).map((range)=>valueKey(range.value ?? null));
|
|
3611
|
+
add(token.field, isNegative, singles);
|
|
3612
|
+
}
|
|
3613
|
+
break;
|
|
3614
|
+
}
|
|
3615
|
+
default:
|
|
3616
|
+
break;
|
|
3617
|
+
}
|
|
3618
|
+
return marks;
|
|
3619
|
+
}
|
|
3620
|
+
function actionsFor(type, state, options) {
|
|
3621
|
+
const include = options.isMac ? "⌘-click" : "Ctrl-click";
|
|
3622
|
+
const exclude = options.isMac ? "⌥-click" : "Alt-click";
|
|
3623
|
+
const actions = [
|
|
3624
|
+
state.isIncluded ? {
|
|
3625
|
+
id: "include",
|
|
3626
|
+
label: "Remove from filter",
|
|
3627
|
+
hint: include
|
|
3628
|
+
} : {
|
|
3629
|
+
id: "include",
|
|
3630
|
+
label: "Filter to this",
|
|
3631
|
+
hint: include
|
|
3632
|
+
}
|
|
3633
|
+
];
|
|
3634
|
+
if (state.hasOthers) actions.push({
|
|
3635
|
+
id: "only",
|
|
3636
|
+
label: "Filter to only this"
|
|
3637
|
+
});
|
|
3638
|
+
actions.push(state.isExcluded ? {
|
|
3639
|
+
id: "exclude",
|
|
3640
|
+
label: "Stop excluding",
|
|
3641
|
+
hint: exclude
|
|
3642
|
+
} : {
|
|
3643
|
+
id: "exclude",
|
|
3644
|
+
label: "Exclude this",
|
|
3645
|
+
hint: exclude
|
|
3646
|
+
});
|
|
3647
|
+
if ("numeric" === type || "date" === type) actions.push({
|
|
3648
|
+
id: "at-least",
|
|
3649
|
+
label: "At least this"
|
|
3650
|
+
}, {
|
|
3651
|
+
id: "at-most",
|
|
3652
|
+
label: "At most this"
|
|
3653
|
+
});
|
|
3654
|
+
if (options.hasColumnFilter) actions.push({
|
|
3655
|
+
id: "clear",
|
|
3656
|
+
label: "Clear column filter"
|
|
3657
|
+
});
|
|
3658
|
+
if (options.canCopy) actions.push({
|
|
3659
|
+
id: "copy",
|
|
3660
|
+
label: "Copy value"
|
|
3661
|
+
});
|
|
3662
|
+
return actions;
|
|
3663
|
+
}
|
|
3301
3664
|
const DEFAULT_AUTO_WIDTH = 150;
|
|
3302
3665
|
const DEFAULT_MIN_WIDTH = 40;
|
|
3303
3666
|
function resolveWidth(def, width, autoWidths) {
|
|
@@ -3305,7 +3668,7 @@ function resolveWidth(def, width, autoWidths) {
|
|
|
3305
3668
|
const measured = autoWidths.get(def.id) ?? DEFAULT_AUTO_WIDTH;
|
|
3306
3669
|
return Math.min(Math.max(measured, def.minWidth ?? DEFAULT_MIN_WIDTH), def.maxWidth ?? 1 / 0);
|
|
3307
3670
|
}
|
|
3308
|
-
function layoutColumns(columnDefs, columnStates, autoWidths = new Map()) {
|
|
3671
|
+
function layoutColumns(columnDefs, columnStates, autoWidths = new Map(), fit) {
|
|
3309
3672
|
const defsById = new Map(columnDefs.map((def)=>[
|
|
3310
3673
|
def.id,
|
|
3311
3674
|
def
|
|
@@ -3313,13 +3676,37 @@ function layoutColumns(columnDefs, columnStates, autoWidths = new Map()) {
|
|
|
3313
3676
|
const pinnedLeft = [];
|
|
3314
3677
|
const center = [];
|
|
3315
3678
|
const pinnedRightRaw = [];
|
|
3316
|
-
|
|
3317
|
-
let centerWidth = 0;
|
|
3679
|
+
const visible = [];
|
|
3318
3680
|
for (const state of columnStates){
|
|
3319
3681
|
if (!state.visible) continue;
|
|
3320
3682
|
const def = defsById.get(state.id);
|
|
3321
|
-
if (
|
|
3322
|
-
|
|
3683
|
+
if (def) visible.push({
|
|
3684
|
+
def,
|
|
3685
|
+
state
|
|
3686
|
+
});
|
|
3687
|
+
}
|
|
3688
|
+
const resolved = visible.map(({ def, state })=>resolveWidth(def, state.width, autoWidths));
|
|
3689
|
+
const widths = fit ? fitWidths(visible.map(({ def, state }, i)=>{
|
|
3690
|
+
const basis = resolved[i];
|
|
3691
|
+
if ("number" == typeof state.width) return {
|
|
3692
|
+
basis,
|
|
3693
|
+
min: basis,
|
|
3694
|
+
max: basis,
|
|
3695
|
+
isFlexible: false
|
|
3696
|
+
};
|
|
3697
|
+
const header = fit.headerWidths.get(def.id) ?? basis;
|
|
3698
|
+
const min = def.minWidth ?? Math.max(DEFAULT_MIN_WIDTH, Math.min(basis, header));
|
|
3699
|
+
return {
|
|
3700
|
+
basis,
|
|
3701
|
+
min,
|
|
3702
|
+
max: def.maxWidth ?? 1 / 0,
|
|
3703
|
+
isFlexible: true
|
|
3704
|
+
};
|
|
3705
|
+
}), fit.available) : resolved;
|
|
3706
|
+
let leftOffset = 0;
|
|
3707
|
+
let centerWidth = 0;
|
|
3708
|
+
for (const [i, { def, state }] of visible.entries()){
|
|
3709
|
+
const width = widths[i];
|
|
3323
3710
|
if ("left" === state.pinned) {
|
|
3324
3711
|
pinnedLeft.push({
|
|
3325
3712
|
def,
|
|
@@ -3359,6 +3746,42 @@ function layoutColumns(columnDefs, columnStates, autoWidths = new Map()) {
|
|
|
3359
3746
|
totalWidth
|
|
3360
3747
|
};
|
|
3361
3748
|
}
|
|
3749
|
+
function fitWidths(columns, available) {
|
|
3750
|
+
const widths = columns.map((column)=>column.basis);
|
|
3751
|
+
const total = widths.reduce((sum, width)=>sum + width, 0);
|
|
3752
|
+
if (available <= 0 || 0 === columns.length) return widths;
|
|
3753
|
+
if (total < available) {
|
|
3754
|
+
let remaining = available - total;
|
|
3755
|
+
for(let pass = 0; pass < columns.length && remaining > 0.5; pass++){
|
|
3756
|
+
const growing = columns.flatMap((column, i)=>column.isFlexible && widths[i] < column.max ? [
|
|
3757
|
+
i
|
|
3758
|
+
] : []);
|
|
3759
|
+
const weight = growing.reduce((sum, i)=>sum + columns[i].basis, 0);
|
|
3760
|
+
if (0 === growing.length || weight <= 0) break;
|
|
3761
|
+
let given = 0;
|
|
3762
|
+
for (const i of growing){
|
|
3763
|
+
const next = Math.min(columns[i].max, widths[i] + remaining * columns[i].basis / weight);
|
|
3764
|
+
given += next - widths[i];
|
|
3765
|
+
widths[i] = next;
|
|
3766
|
+
}
|
|
3767
|
+
remaining -= given;
|
|
3768
|
+
}
|
|
3769
|
+
} else if (total > available) {
|
|
3770
|
+
const over = total - available;
|
|
3771
|
+
const slack = columns.map((column, i)=>column.isFlexible ? Math.max(0, widths[i] - column.min) : 0);
|
|
3772
|
+
const totalSlack = slack.reduce((sum, value)=>sum + value, 0);
|
|
3773
|
+
const share = Math.min(1, over / totalSlack);
|
|
3774
|
+
if (totalSlack > 0) for (const [i, value] of slack.entries())widths[i] -= value * share;
|
|
3775
|
+
}
|
|
3776
|
+
let previous = 0;
|
|
3777
|
+
let running = 0;
|
|
3778
|
+
return widths.map((width)=>{
|
|
3779
|
+
running += width;
|
|
3780
|
+
const rounded = Math.round(running) - previous;
|
|
3781
|
+
previous += rounded;
|
|
3782
|
+
return rounded;
|
|
3783
|
+
});
|
|
3784
|
+
}
|
|
3362
3785
|
function flattenLayout(layout) {
|
|
3363
3786
|
return [
|
|
3364
3787
|
...layout.pinnedLeft.map((c)=>({
|
|
@@ -3462,18 +3885,6 @@ function groupHeaderSegments(layout) {
|
|
|
3462
3885
|
}
|
|
3463
3886
|
return segments;
|
|
3464
3887
|
}
|
|
3465
|
-
const injectStylesIntoStyleTag = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/injectStylesIntoStyleTag.js");
|
|
3466
|
-
var injectStylesIntoStyleTag_default = /*#__PURE__*/ __webpack_require__.n(injectStylesIntoStyleTag);
|
|
3467
|
-
const styleDomAPI = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/styleDomAPI.js");
|
|
3468
|
-
var styleDomAPI_default = /*#__PURE__*/ __webpack_require__.n(styleDomAPI);
|
|
3469
|
-
const insertBySelector = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/insertBySelector.js");
|
|
3470
|
-
var insertBySelector_default = /*#__PURE__*/ __webpack_require__.n(insertBySelector);
|
|
3471
|
-
const setAttributesWithoutAttributes = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/setAttributesWithoutAttributes.js");
|
|
3472
|
-
var setAttributesWithoutAttributes_default = /*#__PURE__*/ __webpack_require__.n(setAttributesWithoutAttributes);
|
|
3473
|
-
const insertStyleElement = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/insertStyleElement.js");
|
|
3474
|
-
var insertStyleElement_default = /*#__PURE__*/ __webpack_require__.n(insertStyleElement);
|
|
3475
|
-
const styleTagTransform = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/style-loader/runtime/styleTagTransform.js");
|
|
3476
|
-
var styleTagTransform_default = /*#__PURE__*/ __webpack_require__.n(styleTagTransform);
|
|
3477
3888
|
const column_chooser_module_0 = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/css-loader/index.js??ruleSet[1].rules[1].oneOf[4].use[1]!builtin:lightningcss-loader??ruleSet[1].rules[1].oneOf[4].use[2]!./src/components/column-chooser.module.css");
|
|
3478
3889
|
var column_chooser_module_options = {};
|
|
3479
3890
|
column_chooser_module_options.styleTagTransform = styleTagTransform_default();
|
|
@@ -3787,15 +4198,6 @@ function GripIcon() {
|
|
|
3787
4198
|
]
|
|
3788
4199
|
});
|
|
3789
4200
|
}
|
|
3790
|
-
const data_grid_module_0 = __webpack_require__("../../node_modules/.pnpm/@rsbuild+core@2.1.13_core-js@3.47.0/node_modules/@rsbuild/core/compiled/css-loader/index.js??ruleSet[1].rules[1].oneOf[4].use[1]!builtin:lightningcss-loader??ruleSet[1].rules[1].oneOf[4].use[2]!./src/components/data-grid.module.css");
|
|
3791
|
-
var data_grid_module_options = {};
|
|
3792
|
-
data_grid_module_options.styleTagTransform = styleTagTransform_default();
|
|
3793
|
-
data_grid_module_options.setAttributes = setAttributesWithoutAttributes_default();
|
|
3794
|
-
data_grid_module_options.insert = insertBySelector_default().bind(null, "head");
|
|
3795
|
-
data_grid_module_options.domAPI = styleDomAPI_default();
|
|
3796
|
-
data_grid_module_options.insertStyleElement = insertStyleElement_default();
|
|
3797
|
-
injectStylesIntoStyleTag_default()(data_grid_module_0.A, data_grid_module_options);
|
|
3798
|
-
const data_grid_module = data_grid_module_0.A && data_grid_module_0.A.locals ? data_grid_module_0.A.locals : void 0;
|
|
3799
4201
|
const KEYBOARD_STEP = 10;
|
|
3800
4202
|
function ColumnResizeHandle({ header, width, minWidth, maxWidth, edge, viewportRef, guideRef, onResize, onAutoFit }) {
|
|
3801
4203
|
const dragRef = useRef(null);
|
|
@@ -3926,7 +4328,7 @@ function renderCell(column, row, meta, marked, fractionDigits) {
|
|
|
3926
4328
|
}
|
|
3927
4329
|
return column.cell(void 0, row, meta);
|
|
3928
4330
|
}
|
|
3929
|
-
function DataCellImpl({ column, row, rowIndex, colIndex, isSelected, isDetailOpen, pinned, offset, width, align, fractionDigits, highlight }) {
|
|
4331
|
+
function DataCellImpl({ column, row, rowIndex, colIndex, isSelected, isDetailOpen, pinned, offset, width, align, fractionDigits, highlight, hasActions = false, pending }) {
|
|
3930
4332
|
const meta = {
|
|
3931
4333
|
columnId: column.id,
|
|
3932
4334
|
rowId: row.__rowId,
|
|
@@ -3945,6 +4347,8 @@ function DataCellImpl({ column, row, rowIndex, colIndex, isSelected, isDetailOpe
|
|
|
3945
4347
|
"aria-colindex": colIndex,
|
|
3946
4348
|
className: data_grid_module.cell,
|
|
3947
4349
|
"data-align": "end" === align ? "end" : void 0,
|
|
4350
|
+
"data-filter-column": hasActions ? column.id : void 0,
|
|
4351
|
+
"data-filter-pending": pending,
|
|
3948
4352
|
"data-wrap": "wrap" === column.overflow || void 0,
|
|
3949
4353
|
role: "gridcell",
|
|
3950
4354
|
style: pinnedCellStyle(pinned, offset, width),
|
|
@@ -4448,7 +4852,7 @@ function TrashIcon({ size = 12 }) {
|
|
|
4448
4852
|
});
|
|
4449
4853
|
}
|
|
4450
4854
|
const NO_COLUMNS = [];
|
|
4451
|
-
function VirtualScroller({ height, rowHeight, rowCount, heightMode, renderRow, className, apiRef, rowWidth, onScroll, onRangeChange, variableHeight = false, rowKey, centerColumns, onColumnRangeChange }) {
|
|
4855
|
+
function VirtualScroller({ height, maxHeight, rowHeight, rowCount, heightMode, renderRow, className, apiRef, rowWidth, onScroll, onRangeChange, variableHeight = false, rowKey, centerColumns, onColumnRangeChange, onViewportWidthChange, overflowX = "auto" }) {
|
|
4452
4856
|
const scrollRef = useRef(null);
|
|
4453
4857
|
const [fillHeightIsZero, setFillHeightIsZero] = useState(false);
|
|
4454
4858
|
const virtualizer = useVirtualizer({
|
|
@@ -4461,7 +4865,7 @@ function VirtualScroller({ height, rowHeight, rowCount, heightMode, renderRow, c
|
|
|
4461
4865
|
overscan: 8,
|
|
4462
4866
|
initialRect: {
|
|
4463
4867
|
width: 0,
|
|
4464
|
-
height: "number" == typeof height ? height : 480
|
|
4868
|
+
height: "number" == typeof height ? height : maxHeight ?? 480
|
|
4465
4869
|
}
|
|
4466
4870
|
});
|
|
4467
4871
|
useEffect(()=>{
|
|
@@ -4517,6 +4921,22 @@ function VirtualScroller({ height, rowHeight, rowCount, heightMode, renderRow, c
|
|
|
4517
4921
|
rangeEnd,
|
|
4518
4922
|
onRangeChange
|
|
4519
4923
|
]);
|
|
4924
|
+
const onViewportWidthChangeRef = useRef(onViewportWidthChange);
|
|
4925
|
+
useEffect(()=>{
|
|
4926
|
+
onViewportWidthChangeRef.current = onViewportWidthChange;
|
|
4927
|
+
});
|
|
4928
|
+
useEffect(()=>{
|
|
4929
|
+
const el = scrollRef.current;
|
|
4930
|
+
if (!el || "u" < typeof ResizeObserver) return;
|
|
4931
|
+
const width = ()=>Math.floor(el.getBoundingClientRect().width - (el.offsetWidth - el.clientWidth));
|
|
4932
|
+
const observer = new ResizeObserver(()=>{
|
|
4933
|
+
const next = width();
|
|
4934
|
+
flushSync(()=>onViewportWidthChangeRef.current?.(next));
|
|
4935
|
+
});
|
|
4936
|
+
observer.observe(el);
|
|
4937
|
+
onViewportWidthChangeRef.current?.(width());
|
|
4938
|
+
return ()=>observer.disconnect();
|
|
4939
|
+
}, []);
|
|
4520
4940
|
useEffect(()=>{
|
|
4521
4941
|
if ("fill" !== height) return;
|
|
4522
4942
|
const el = scrollRef.current;
|
|
@@ -4543,8 +4963,13 @@ function VirtualScroller({ height, rowHeight, rowCount, heightMode, renderRow, c
|
|
|
4543
4963
|
ref: scrollRef,
|
|
4544
4964
|
onScroll: onScroll ? (e)=>onScroll(e.currentTarget) : void 0,
|
|
4545
4965
|
style: {
|
|
4546
|
-
|
|
4547
|
-
|
|
4966
|
+
..."auto" === height ? {
|
|
4967
|
+
flex: "1 1 auto"
|
|
4968
|
+
} : {
|
|
4969
|
+
height: "number" == typeof height ? height : "100%"
|
|
4970
|
+
},
|
|
4971
|
+
overflowX,
|
|
4972
|
+
overflowY: "auto"
|
|
4548
4973
|
},
|
|
4549
4974
|
children: /*#__PURE__*/ jsx("div", {
|
|
4550
4975
|
style: {
|
|
@@ -4637,7 +5062,7 @@ function callerRow(row) {
|
|
|
4637
5062
|
for (const [key, value] of Object.entries(row))if ("__rowId" !== key && !key.startsWith("__derived_")) plain[key] = value;
|
|
4638
5063
|
return plain;
|
|
4639
5064
|
}
|
|
4640
|
-
function
|
|
5065
|
+
function DataGrid_rowRef(...refs) {
|
|
4641
5066
|
const present = refs.filter((ref)=>void 0 !== ref);
|
|
4642
5067
|
if (0 === present.length) return;
|
|
4643
5068
|
return (element)=>{
|
|
@@ -4735,6 +5160,13 @@ function CloseIcon() {
|
|
|
4735
5160
|
})
|
|
4736
5161
|
});
|
|
4737
5162
|
}
|
|
5163
|
+
function rawCellValue(column, row) {
|
|
5164
|
+
if (isKeyColumnDef(column)) return Reflect.get(row, column.accessorKey);
|
|
5165
|
+
if (DataCell_isDerivedColumnDef(column)) return Reflect.get(row, `__derived_${column.id}`);
|
|
5166
|
+
}
|
|
5167
|
+
function valueLabel(value) {
|
|
5168
|
+
return null === value ? "empty" : String(value);
|
|
5169
|
+
}
|
|
4738
5170
|
const INTERACTIVE = 'button, a, input, select, textarea, label, [role="checkbox"], [data-row-control]';
|
|
4739
5171
|
function MoreIcon() {
|
|
4740
5172
|
return /*#__PURE__*/ jsxs("svg", {
|
|
@@ -4903,7 +5335,13 @@ function DataGrid(props) {
|
|
|
4903
5335
|
return columnDigits.get(columnId) ?? 0;
|
|
4904
5336
|
}
|
|
4905
5337
|
const [autoWidths, setAutoWidths] = useState(()=>new Map());
|
|
4906
|
-
const
|
|
5338
|
+
const [viewportWidth, setViewportWidth] = useState(0);
|
|
5339
|
+
const [headerWidths, setHeaderWidths] = useState(()=>new Map());
|
|
5340
|
+
const isFitting = (props.columnSizing ?? "fit") === "fit" && viewportWidth > 0;
|
|
5341
|
+
const columnLayout = layoutColumns(columnDefs, columnStates, autoWidths, isFitting ? {
|
|
5342
|
+
available: viewportWidth - injectedWidth,
|
|
5343
|
+
headerWidths
|
|
5344
|
+
} : void 0);
|
|
4907
5345
|
const orderedColumns = flattenLayout(columnLayout);
|
|
4908
5346
|
const [centerRange, setCenterRange] = useState({
|
|
4909
5347
|
start: 0,
|
|
@@ -4988,14 +5426,28 @@ function DataGrid(props) {
|
|
|
4988
5426
|
headerPadding: paddingOf(headerStyle)
|
|
4989
5427
|
});
|
|
4990
5428
|
}
|
|
5429
|
+
function measureHeaders(columns) {
|
|
5430
|
+
const headerCell = gridRef.current?.querySelector('[role="columnheader"][data-column-id]');
|
|
5431
|
+
const measure = createCanvasMeasurer();
|
|
5432
|
+
if (!headerCell || !measure) return null;
|
|
5433
|
+
const headerStyle = getComputedStyle(headerCell);
|
|
5434
|
+
return measureHeaderWidths({
|
|
5435
|
+
columns,
|
|
5436
|
+
measure,
|
|
5437
|
+
headerFont: fontOf(headerStyle),
|
|
5438
|
+
headerPadding: paddingOf(headerStyle)
|
|
5439
|
+
});
|
|
5440
|
+
}
|
|
4991
5441
|
useEffect(()=>{
|
|
4992
5442
|
const key = `${autoColumnIds}|${columnDefs.map((column)=>column.id).join(",")}`;
|
|
4993
5443
|
if (!hasLoadedRows || "" === autoColumnIds || measuredKeyRef.current === key) return;
|
|
4994
5444
|
const autoIds = new Set(autoColumnIds.split(","));
|
|
4995
|
-
const
|
|
5445
|
+
const autoColumns = columnDefs.filter((column)=>autoIds.has(column.id));
|
|
5446
|
+
const measured = measureColumns(autoColumns);
|
|
4996
5447
|
if (!measured) return;
|
|
4997
5448
|
measuredKeyRef.current = key;
|
|
4998
5449
|
setAutoWidths(measured);
|
|
5450
|
+
setHeaderWidths(measureHeaders(autoColumns) ?? new Map());
|
|
4999
5451
|
}, [
|
|
5000
5452
|
hasLoadedRows,
|
|
5001
5453
|
autoColumnIds,
|
|
@@ -5565,6 +6017,22 @@ function DataGrid(props) {
|
|
|
5565
6017
|
}), [
|
|
5566
6018
|
querySchemaKey
|
|
5567
6019
|
]);
|
|
6020
|
+
const cellActionsOn = void 0 !== structuredFilter && false !== structuredFilter.cellActions;
|
|
6021
|
+
const actionTypes = useMemo(()=>new Map(cellActionsOn ? querySchema.fields.map((field)=>[
|
|
6022
|
+
field.id,
|
|
6023
|
+
field.type
|
|
6024
|
+
]) : []), [
|
|
6025
|
+
querySchema,
|
|
6026
|
+
cellActionsOn
|
|
6027
|
+
]);
|
|
6028
|
+
const queryBarApiRef = useRef(null);
|
|
6029
|
+
const cellActionsRef = useRef(null);
|
|
6030
|
+
const [pendingTokens, setPendingTokens] = useState(null);
|
|
6031
|
+
const marks = useMemo(()=>pendingMarks(pendingTokens), [
|
|
6032
|
+
pendingTokens
|
|
6033
|
+
]);
|
|
6034
|
+
const [filterAnnouncement, setFilterAnnouncement] = useState("");
|
|
6035
|
+
const isMac = "mac" === useOS();
|
|
5568
6036
|
const [committedQuery, setCommittedQuery] = useControllableState({
|
|
5569
6037
|
defaultValue: simpleFilter?.initialQuery ?? "",
|
|
5570
6038
|
value: simpleFilter?.query,
|
|
@@ -5641,10 +6109,170 @@ function DataGrid(props) {
|
|
|
5641
6109
|
const scrollerApiRef = useRef(null);
|
|
5642
6110
|
const overflowTooltipRef = useRef(null);
|
|
5643
6111
|
function handleCellPointerOver(event) {
|
|
5644
|
-
if ("touch" === event.pointerType) return;
|
|
5645
6112
|
const target = event.target instanceof Element ? event.target : null;
|
|
6113
|
+
if (cellActionsOn && target?.closest('[role="row"]')) cellActionsRef.current?.hover(target.closest("[data-filter-column]"));
|
|
6114
|
+
if ("touch" === event.pointerType) return;
|
|
5646
6115
|
overflowTooltipRef.current?.show(target?.closest("[data-truncatable]") ?? null);
|
|
5647
6116
|
}
|
|
6117
|
+
function cellTarget(cell) {
|
|
6118
|
+
if (!(cell instanceof HTMLElement)) return null;
|
|
6119
|
+
const columnId = cell.dataset.filterColumn;
|
|
6120
|
+
const type = void 0 === columnId ? void 0 : actionTypes.get(columnId);
|
|
6121
|
+
const column = void 0 === columnId ? void 0 : defsById.get(columnId);
|
|
6122
|
+
const rowElement = cell.closest('[role="row"][data-row-index]');
|
|
6123
|
+
const entry = rowElement ? grid.getEntry(Number(rowElement.dataset.rowIndex)) : void 0;
|
|
6124
|
+
if (!type || !column || entry?.kind !== "row") return null;
|
|
6125
|
+
const raw = rawCellValue(column, entry.data);
|
|
6126
|
+
return {
|
|
6127
|
+
column,
|
|
6128
|
+
type,
|
|
6129
|
+
isList: Array.isArray(raw),
|
|
6130
|
+
values: cellFilterValues(raw, type, timeZone),
|
|
6131
|
+
text: (cell.textContent ?? "").trim()
|
|
6132
|
+
};
|
|
6133
|
+
}
|
|
6134
|
+
function runFilterAction(column, value, action, apply) {
|
|
6135
|
+
const api = queryBarApiRef.current;
|
|
6136
|
+
if (!api) return;
|
|
6137
|
+
const before = pendingMarks(api.pending()).get(column.id);
|
|
6138
|
+
const key = valueKey(value);
|
|
6139
|
+
api.edit((pending)=>editFieldValue(pending, querySchema, {
|
|
6140
|
+
field: column.id,
|
|
6141
|
+
value,
|
|
6142
|
+
action
|
|
6143
|
+
}), {
|
|
6144
|
+
apply
|
|
6145
|
+
});
|
|
6146
|
+
const what = `${column.header} ${valueLabel(value)}`;
|
|
6147
|
+
const done = "include" === action ? before?.include.has(key) ? "removed from the filter" : "added to the filter" : "exclude" === action ? before?.exclude.has(key) ? "no longer excluded" : "excluded" : "clear" === action ? "filter cleared" : "set as the filter";
|
|
6148
|
+
const shortcut = isMac ? "⌘↵" : "Ctrl+Enter";
|
|
6149
|
+
setFilterAnnouncement(`${"clear" === action ? column.header : what} ${done}.${apply ? "" : ` ${shortcut} to apply.`}`);
|
|
6150
|
+
}
|
|
6151
|
+
function cellActionSections(cell, row) {
|
|
6152
|
+
const cells = row ? [
|
|
6153
|
+
...row.querySelectorAll("[data-filter-column]")
|
|
6154
|
+
] : [
|
|
6155
|
+
cell
|
|
6156
|
+
];
|
|
6157
|
+
const current = queryBarApiRef.current?.pending() ?? structuredTokens;
|
|
6158
|
+
const currentMarks = pendingMarks(current);
|
|
6159
|
+
const sections = [];
|
|
6160
|
+
for (const element of cells){
|
|
6161
|
+
const target = cellTarget(element);
|
|
6162
|
+
if (!target) continue;
|
|
6163
|
+
const columnMarks = currentMarks.get(target.column.id);
|
|
6164
|
+
const hasColumnFilter = current.some((token)=>"field" === token.type && token.field === target.column.id);
|
|
6165
|
+
for (const value of target.values){
|
|
6166
|
+
const key = valueKey(value);
|
|
6167
|
+
const text = null === value ? "" : target.isList ? String(value) : target.text;
|
|
6168
|
+
const actions = null === value ? [
|
|
6169
|
+
{
|
|
6170
|
+
id: "include",
|
|
6171
|
+
label: "Filter to empty"
|
|
6172
|
+
},
|
|
6173
|
+
{
|
|
6174
|
+
id: "exclude",
|
|
6175
|
+
label: "Exclude empty"
|
|
6176
|
+
},
|
|
6177
|
+
...hasColumnFilter ? [
|
|
6178
|
+
{
|
|
6179
|
+
id: "clear",
|
|
6180
|
+
label: "Clear column filter"
|
|
6181
|
+
}
|
|
6182
|
+
] : []
|
|
6183
|
+
] : actionsFor(target.type, {
|
|
6184
|
+
isIncluded: columnMarks?.include.has(key) ?? false,
|
|
6185
|
+
isExcluded: columnMarks?.exclude.has(key) ?? false,
|
|
6186
|
+
hasOthers: [
|
|
6187
|
+
...columnMarks?.include ?? []
|
|
6188
|
+
].some((other)=>other !== key)
|
|
6189
|
+
}, {
|
|
6190
|
+
isMac,
|
|
6191
|
+
hasColumnFilter,
|
|
6192
|
+
canCopy: "" !== text
|
|
6193
|
+
});
|
|
6194
|
+
sections.push({
|
|
6195
|
+
key: `${target.column.id}:${key}`,
|
|
6196
|
+
label: `${target.column.header}: ${null === value ? "(empty)" : text || String(value)}`,
|
|
6197
|
+
columnId: target.column.id,
|
|
6198
|
+
value,
|
|
6199
|
+
text,
|
|
6200
|
+
actions
|
|
6201
|
+
});
|
|
6202
|
+
}
|
|
6203
|
+
}
|
|
6204
|
+
return sections;
|
|
6205
|
+
}
|
|
6206
|
+
function handleCellAction(section, action, apply) {
|
|
6207
|
+
if ("copy" === action.id) return void navigator.clipboard?.writeText(section.text);
|
|
6208
|
+
const column = defsById.get(section.columnId);
|
|
6209
|
+
if (column) runFilterAction(column, section.value, action.id, apply);
|
|
6210
|
+
}
|
|
6211
|
+
function cellActionsLabel(cell) {
|
|
6212
|
+
const target = cellTarget(cell);
|
|
6213
|
+
if (!target) return "Filter options";
|
|
6214
|
+
const [only] = target.values;
|
|
6215
|
+
const value = 1 === target.values.length && void 0 !== only ? valueLabel(only) : target.text;
|
|
6216
|
+
return `Filter options for ${target.column.header}: ${value}`;
|
|
6217
|
+
}
|
|
6218
|
+
function modifiedCellClick(event) {
|
|
6219
|
+
if (!cellActionsOn) return null;
|
|
6220
|
+
const isInclude = isMac ? event.metaKey : event.ctrlKey;
|
|
6221
|
+
if (!isInclude && !event.altKey) return null;
|
|
6222
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
6223
|
+
if (!target || target.closest(INTERACTIVE) || target.closest("[data-cell-actions]")) return null;
|
|
6224
|
+
const cell = target.closest("[data-filter-column]");
|
|
6225
|
+
const hit = cell ? cellTarget(cell) : null;
|
|
6226
|
+
if (!hit || hit.isList) return null;
|
|
6227
|
+
return {
|
|
6228
|
+
hit,
|
|
6229
|
+
action: event.altKey ? "exclude" : "include"
|
|
6230
|
+
};
|
|
6231
|
+
}
|
|
6232
|
+
function handleCellClickCapture(event) {
|
|
6233
|
+
const click = modifiedCellClick(event);
|
|
6234
|
+
if (!click) return;
|
|
6235
|
+
event.preventDefault();
|
|
6236
|
+
event.stopPropagation();
|
|
6237
|
+
const [value = null] = click.hit.values;
|
|
6238
|
+
runFilterAction(click.hit.column, value, click.action, event.shiftKey);
|
|
6239
|
+
}
|
|
6240
|
+
function handleCellMouseDownCapture(event) {
|
|
6241
|
+
if (modifiedCellClick(event)) event.preventDefault();
|
|
6242
|
+
}
|
|
6243
|
+
function handleCellContextMenu(event) {
|
|
6244
|
+
if (!cellActionsOn || event.shiftKey) return;
|
|
6245
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
6246
|
+
if (!target || target.closest(INTERACTIVE)) return;
|
|
6247
|
+
const cell = target.closest("[data-filter-column]");
|
|
6248
|
+
if (cell && cellTarget(cell)) {
|
|
6249
|
+
event.preventDefault();
|
|
6250
|
+
cellActionsRef.current?.open(cell);
|
|
6251
|
+
return;
|
|
6252
|
+
}
|
|
6253
|
+
if (target instanceof HTMLElement && target.matches('[role="row"][data-row-index]')) {
|
|
6254
|
+
if (openRowMenu(target)) event.preventDefault();
|
|
6255
|
+
}
|
|
6256
|
+
}
|
|
6257
|
+
function openRowMenu(row) {
|
|
6258
|
+
const first = row.querySelector("[data-filter-column]");
|
|
6259
|
+
if (!first) return false;
|
|
6260
|
+
cellActionsRef.current?.open(first, {
|
|
6261
|
+
row
|
|
6262
|
+
});
|
|
6263
|
+
return true;
|
|
6264
|
+
}
|
|
6265
|
+
function pendingFor(column, row) {
|
|
6266
|
+
const columnMarks = marks.get(column.id);
|
|
6267
|
+
const type = actionTypes.get(column.id);
|
|
6268
|
+
if (!columnMarks || !type) return;
|
|
6269
|
+
const raw = rawCellValue(column, row);
|
|
6270
|
+
if (Array.isArray(raw)) return;
|
|
6271
|
+
const [value = null] = cellFilterValues(raw, type, timeZone);
|
|
6272
|
+
if (null === value) return;
|
|
6273
|
+
const key = valueKey(value);
|
|
6274
|
+
return columnMarks.exclude.has(key) ? "exclude" : columnMarks.include.has(key) ? "include" : void 0;
|
|
6275
|
+
}
|
|
5648
6276
|
function registerRowRef(rowId) {
|
|
5649
6277
|
return (el)=>{
|
|
5650
6278
|
if (el) {
|
|
@@ -5674,6 +6302,7 @@ function DataGrid(props) {
|
|
|
5674
6302
|
else pendingSelectIndexRef.current = clamped;
|
|
5675
6303
|
}
|
|
5676
6304
|
const [multiFocusIndex, setMultiFocusIndex] = useState(0);
|
|
6305
|
+
const isFocusOnly = !singleSelect && !multiSelect && cellActionsOn;
|
|
5677
6306
|
function focusRowOnly(index) {
|
|
5678
6307
|
if (0 === totalCount) return;
|
|
5679
6308
|
const clamped = Math.max(0, Math.min(index, totalCount - 1));
|
|
@@ -5755,6 +6384,13 @@ function DataGrid(props) {
|
|
|
5755
6384
|
}
|
|
5756
6385
|
function handleGridKeyDown(event) {
|
|
5757
6386
|
const isModified = event.ctrlKey || event.metaKey;
|
|
6387
|
+
if (cellActionsOn && "F10" === event.key && event.shiftKey) {
|
|
6388
|
+
const target = event.target;
|
|
6389
|
+
if (target instanceof HTMLElement && target.matches('[role="row"][data-row-index]')) {
|
|
6390
|
+
if (openRowMenu(target)) event.preventDefault();
|
|
6391
|
+
return;
|
|
6392
|
+
}
|
|
6393
|
+
}
|
|
5758
6394
|
if ("Escape" === event.key && rowDetail && null !== openRowId) {
|
|
5759
6395
|
event.preventDefault();
|
|
5760
6396
|
setOpenRowId(null);
|
|
@@ -5799,6 +6435,19 @@ function DataGrid(props) {
|
|
|
5799
6435
|
}
|
|
5800
6436
|
return;
|
|
5801
6437
|
}
|
|
6438
|
+
if (isFocusOnly && totalCount > 0) {
|
|
6439
|
+
const target = event.target instanceof Element ? event.target : null;
|
|
6440
|
+
const rowElement = target?.closest('[role="row"][data-row-index]');
|
|
6441
|
+
const index = rowElement ? Number(rowElement.dataset.rowIndex) : multiFocusIndex;
|
|
6442
|
+
const focused = rowElement && target === rowElement ? grid.getEntry(index) : void 0;
|
|
6443
|
+
if (focused?.kind === "group-header" && handleGroupKey(event, focused)) return;
|
|
6444
|
+
const to = navigationTarget(event, index);
|
|
6445
|
+
if (null !== to) {
|
|
6446
|
+
event.preventDefault();
|
|
6447
|
+
focusRowOnly(to);
|
|
6448
|
+
}
|
|
6449
|
+
return;
|
|
6450
|
+
}
|
|
5802
6451
|
if (!singleSelect || 0 === totalCount) return;
|
|
5803
6452
|
if ("Enter" === event.key && rowDetail && null !== selectedRowId) {
|
|
5804
6453
|
event.preventDefault();
|
|
@@ -5914,7 +6563,7 @@ function DataGrid(props) {
|
|
|
5914
6563
|
"data-detail-open": multiSelect && rowDetail && rowId === openRowId || void 0,
|
|
5915
6564
|
"data-index": index,
|
|
5916
6565
|
"data-row-index": index,
|
|
5917
|
-
ref:
|
|
6566
|
+
ref: DataGrid_rowRef(isSelectable || isFocusOnly ? registerRowRef(rowId) : void 0, measure),
|
|
5918
6567
|
role: "row",
|
|
5919
6568
|
style: {
|
|
5920
6569
|
...style,
|
|
@@ -5925,8 +6574,8 @@ function DataGrid(props) {
|
|
|
5925
6574
|
height: rowHeight
|
|
5926
6575
|
}
|
|
5927
6576
|
},
|
|
5928
|
-
tabIndex: singleSelect ? isSelected || null === selectedRowId && 0 === index ? 0 : -1 : multiSelect ? index === multiFocusIndex ? 0 : -1 : void 0,
|
|
5929
|
-
onClick: singleSelect ? ()=>selectRow(rowId, index) : multiSelect && rowDetail ? (event)=>openDetailFromClick(event, rowId, index) : void 0,
|
|
6577
|
+
tabIndex: singleSelect ? isSelected || null === selectedRowId && 0 === index ? 0 : -1 : multiSelect || isFocusOnly ? index === multiFocusIndex ? 0 : -1 : void 0,
|
|
6578
|
+
onClick: singleSelect ? ()=>selectRow(rowId, index) : multiSelect && rowDetail ? (event)=>openDetailFromClick(event, rowId, index) : isFocusOnly ? ()=>setMultiFocusIndex(index) : void 0,
|
|
5930
6579
|
children: renderPlannedColumns((col, colIndex)=>/*#__PURE__*/ jsx(DataCell, {
|
|
5931
6580
|
colIndex: colIndex + 1,
|
|
5932
6581
|
column: col.def,
|
|
@@ -5939,7 +6588,9 @@ function DataGrid(props) {
|
|
|
5939
6588
|
fractionDigits: digitsFor(col.def.id),
|
|
5940
6589
|
row: row,
|
|
5941
6590
|
rowIndex: index,
|
|
5942
|
-
width: col.width
|
|
6591
|
+
width: col.width,
|
|
6592
|
+
hasActions: actionTypes.has(col.def.id),
|
|
6593
|
+
pending: marks.size > 0 ? pendingFor(col.def, row) : void 0
|
|
5943
6594
|
}, col.def.id), (kind, cellStyle, colIndex)=>"grab" === kind ? renderGrabCell(rowId, index, row, cellStyle, colIndex) : renderSelectCell(rowId, index, row, cellStyle, colIndex))
|
|
5944
6595
|
}, rowId);
|
|
5945
6596
|
}
|
|
@@ -5950,7 +6601,7 @@ function DataGrid(props) {
|
|
|
5950
6601
|
const column = void 0 === columnId ? void 0 : defsById.get(columnId);
|
|
5951
6602
|
const value = void 0 === columnId ? null : header.groupValues[columnId];
|
|
5952
6603
|
const label = `${column?.header ?? columnId}: ${groupValueLabel(value)}`;
|
|
5953
|
-
const isFocusable = void 0 !== multiSelect;
|
|
6604
|
+
const isFocusable = void 0 !== multiSelect || isFocusOnly;
|
|
5954
6605
|
return /*#__PURE__*/ jsx("div", {
|
|
5955
6606
|
"aria-expanded": header.isExpanded,
|
|
5956
6607
|
"aria-level": header.level,
|
|
@@ -5958,7 +6609,7 @@ function DataGrid(props) {
|
|
|
5958
6609
|
className: data_grid_module.groupRow,
|
|
5959
6610
|
"data-index": index,
|
|
5960
6611
|
"data-row-index": index,
|
|
5961
|
-
ref:
|
|
6612
|
+
ref: DataGrid_rowRef(isFocusable ? registerRowRef(key) : void 0, measure),
|
|
5962
6613
|
role: "row",
|
|
5963
6614
|
style: {
|
|
5964
6615
|
...style,
|
|
@@ -6147,6 +6798,8 @@ function DataGrid(props) {
|
|
|
6147
6798
|
ref: toolbarRef,
|
|
6148
6799
|
children: [
|
|
6149
6800
|
structuredFilter && /*#__PURE__*/ jsx(QueryBar, {
|
|
6801
|
+
apiRef: queryBarApiRef,
|
|
6802
|
+
onPendingChange: cellActionsOn ? setPendingTokens : void 0,
|
|
6150
6803
|
flex: 1,
|
|
6151
6804
|
minWidth: 200,
|
|
6152
6805
|
label: "Filter",
|
|
@@ -6297,10 +6950,18 @@ function DataGrid(props) {
|
|
|
6297
6950
|
className: data_grid_module.visuallyHidden,
|
|
6298
6951
|
children: announced
|
|
6299
6952
|
}),
|
|
6953
|
+
cellActionsOn && /*#__PURE__*/ jsx("div", {
|
|
6954
|
+
"aria-live": "polite",
|
|
6955
|
+
className: data_grid_module.visuallyHidden,
|
|
6956
|
+
children: filterAnnouncement
|
|
6957
|
+
}),
|
|
6300
6958
|
/*#__PURE__*/ jsxs("div", {
|
|
6301
6959
|
className: data_grid_module.layout,
|
|
6302
6960
|
style: "number" == typeof height ? {
|
|
6303
6961
|
height
|
|
6962
|
+
} : "auto" === height ? {
|
|
6963
|
+
height: "auto",
|
|
6964
|
+
maxHeight: props.maxHeight
|
|
6304
6965
|
} : void 0,
|
|
6305
6966
|
children: [
|
|
6306
6967
|
/*#__PURE__*/ jsxs("div", {
|
|
@@ -6311,7 +6972,13 @@ function DataGrid(props) {
|
|
|
6311
6972
|
className: data_grid_module.viewport,
|
|
6312
6973
|
"data-pending": isPending || grid.isPending || void 0,
|
|
6313
6974
|
onKeyDown: handleGridKeyDown,
|
|
6314
|
-
|
|
6975
|
+
onClickCapture: cellActionsOn ? handleCellClickCapture : void 0,
|
|
6976
|
+
onContextMenu: cellActionsOn ? handleCellContextMenu : void 0,
|
|
6977
|
+
onMouseDownCapture: cellActionsOn ? handleCellMouseDownCapture : void 0,
|
|
6978
|
+
onPointerLeave: ()=>{
|
|
6979
|
+
overflowTooltipRef.current?.show(null);
|
|
6980
|
+
cellActionsRef.current?.hover(null);
|
|
6981
|
+
},
|
|
6315
6982
|
onPointerOver: handleCellPointerOver,
|
|
6316
6983
|
ref: gridRef,
|
|
6317
6984
|
role: isGrouped ? "treegrid" : "grid",
|
|
@@ -6320,6 +6987,12 @@ function DataGrid(props) {
|
|
|
6320
6987
|
/*#__PURE__*/ jsx(OverflowTooltip, {
|
|
6321
6988
|
apiRef: overflowTooltipRef
|
|
6322
6989
|
}),
|
|
6990
|
+
cellActionsOn && /*#__PURE__*/ jsx(CellActions, {
|
|
6991
|
+
apiRef: cellActionsRef,
|
|
6992
|
+
labelFor: cellActionsLabel,
|
|
6993
|
+
onAction: handleCellAction,
|
|
6994
|
+
sectionsFor: cellActionSections
|
|
6995
|
+
}),
|
|
6323
6996
|
/*#__PURE__*/ jsx("div", {
|
|
6324
6997
|
"aria-hidden": true,
|
|
6325
6998
|
className: data_grid_module.resizeGuide,
|
|
@@ -6450,9 +7123,11 @@ function DataGrid(props) {
|
|
|
6450
7123
|
apiRef: scrollerApiRef,
|
|
6451
7124
|
className: data_grid_module.scroller,
|
|
6452
7125
|
height: height,
|
|
7126
|
+
maxHeight: props.maxHeight,
|
|
6453
7127
|
heightMode: "total",
|
|
6454
7128
|
onRangeChange: grid.requestRange,
|
|
6455
7129
|
onScroll: (scroller)=>{
|
|
7130
|
+
cellActionsRef.current?.hover(null);
|
|
6456
7131
|
for (const follower of scrollFollowersRef.current)follower.scrollLeft = scroller.scrollLeft;
|
|
6457
7132
|
markScrollEdges(scroller);
|
|
6458
7133
|
},
|
|
@@ -6463,7 +7138,9 @@ function DataGrid(props) {
|
|
|
6463
7138
|
rowKey: rowKey,
|
|
6464
7139
|
rowWidth: totalWidth,
|
|
6465
7140
|
centerColumns: centerColumns,
|
|
6466
|
-
onColumnRangeChange: handleColumnRangeChange
|
|
7141
|
+
onColumnRangeChange: handleColumnRangeChange,
|
|
7142
|
+
onViewportWidthChange: setViewportWidth,
|
|
7143
|
+
overflowX: isFitting && totalWidth <= viewportWidth ? "hidden" : "auto"
|
|
6467
7144
|
}),
|
|
6468
7145
|
isAppending && totalCount > 0 && (props.renderLoadingState ? props.renderLoadingState({
|
|
6469
7146
|
phase: "append"
|