@kumix/ui 0.3.10 → 0.3.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -14
- package/dist/components/motion/adaptive-stepper.d.ts +32 -0
- package/dist/components/motion/adaptive-stepper.d.ts.map +1 -0
- package/dist/components/motion/adaptive-stepper.js +302 -0
- package/dist/components/motion/adaptive-stepper.js.map +1 -0
- package/dist/components/motion/combobox/content.js +1 -1
- package/dist/components/motion/combobox/context.js +216 -1
- package/dist/components/motion/combobox/context.js.map +1 -0
- package/dist/components/motion/combobox/list.js +1 -1
- package/dist/components/motion/combobox/trigger.js +1 -1
- package/dist/components/motion/combobox.js +1 -1
- package/dist/components/motion/input.d.ts +2 -0
- package/dist/components/motion/input.d.ts.map +1 -1
- package/dist/components/motion/input.js +28 -25
- package/dist/components/motion/input.js.map +1 -1
- package/dist/components/motion/liquid.d.ts +30 -0
- package/dist/components/motion/liquid.d.ts.map +1 -0
- package/dist/components/motion/liquid.js +248 -0
- package/dist/components/motion/liquid.js.map +1 -0
- package/dist/components/motion/multi-select/content.d.ts +16 -0
- package/dist/components/motion/multi-select/content.d.ts.map +1 -0
- package/dist/components/motion/multi-select/content.js +91 -0
- package/dist/components/motion/multi-select/content.js.map +1 -0
- package/dist/components/motion/multi-select/context.d.ts +64 -0
- package/dist/components/motion/multi-select/context.d.ts.map +1 -0
- package/dist/{context-BizvUNZv.js → components/motion/multi-select/context.js} +44 -114
- package/dist/components/motion/multi-select/context.js.map +1 -0
- package/dist/components/motion/multi-select/index.d.ts +5 -0
- package/dist/components/motion/multi-select/index.js +6 -0
- package/dist/components/motion/multi-select/list.d.ts +40 -0
- package/dist/components/motion/multi-select/list.d.ts.map +1 -0
- package/dist/components/motion/multi-select/list.js +144 -0
- package/dist/components/motion/multi-select/list.js.map +1 -0
- package/dist/components/motion/multi-select/trigger.d.ts +22 -0
- package/dist/components/motion/multi-select/trigger.d.ts.map +1 -0
- package/dist/components/motion/multi-select/trigger.js +185 -0
- package/dist/components/motion/multi-select/trigger.js.map +1 -0
- package/dist/components/motion/signup-form.js +6 -2
- package/dist/components/motion/signup-form.js.map +1 -1
- package/dist/components/motion/table/index.js.map +1 -1
- package/dist/components/reui/alert.d.ts +1 -1
- package/dist/components/reui/badge.d.ts +1 -1
- package/dist/components/reui/cascader/cascader-async.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-async.js.map +1 -1
- package/dist/components/reui/cascader/cascader-virtual.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader-virtual.js.map +1 -1
- package/dist/components/reui/cascader/cascader.d.ts.map +1 -1
- package/dist/components/reui/cascader/cascader.js.map +1 -1
- package/dist/components/reui/code-block/code-block.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts +117 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.d.ts.map +1 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.js +1554 -0
- package/dist/components/reui/data-grid/data-grid-cell-selection.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-column-filter.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-filter.js +6 -4
- package/dist/components/reui/data-grid/data-grid-column-filter.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-header.js +10 -7
- package/dist/components/reui/data-grid/data-grid-column-header.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-column-visibility.js +3 -2
- package/dist/components/reui/data-grid/data-grid-column-visibility.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-i18n.d.ts +2 -0
- package/dist/components/reui/data-grid/data-grid-i18n.js +53 -0
- package/dist/components/reui/data-grid/data-grid-i18n.js.map +1 -0
- package/dist/components/reui/data-grid/data-grid-pagination.js +14 -8
- package/dist/components/reui/data-grid/data-grid-pagination.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-scroll-area.js +3 -3
- package/dist/components/reui/data-grid/data-grid-scroll-area.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js +6 -4
- package/dist/components/reui/data-grid/data-grid-table-dnd-rows.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-dnd.js +2 -2
- package/dist/components/reui/data-grid/data-grid-table-dnd.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts +17 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table-virtual.js +146 -50
- package/dist/components/reui/data-grid/data-grid-table-virtual.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.d.ts +23 -4
- package/dist/components/reui/data-grid/data-grid-table.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid-table.js +215 -68
- package/dist/components/reui/data-grid/data-grid-table.js.map +1 -1
- package/dist/components/reui/data-grid/data-grid.d.ts +276 -6
- package/dist/components/reui/data-grid/data-grid.d.ts.map +1 -1
- package/dist/components/reui/data-grid/data-grid.js +150 -15
- package/dist/components/reui/data-grid/data-grid.js.map +1 -1
- package/dist/components/reui/filters/filters-advanced.js.map +1 -1
- package/dist/components/reui/filters/filters-chip.js.map +1 -1
- package/dist/components/reui/filters/filters.d.ts.map +1 -1
- package/dist/components/reui/filters/filters.js.map +1 -1
- package/dist/components/reui/icon-tile.d.ts +1 -1
- package/dist/components/ui/badge.d.ts +1 -1
- package/dist/components/ui/bubble.d.ts +1 -1
- package/dist/components/ui/button.d.ts +1 -1
- package/dist/components/ui/item.d.ts +1 -1
- package/dist/components/ui/marker.d.ts +1 -1
- package/dist/components/ui/message-scroller.js +1 -1
- package/dist/components/ui/message-scroller.js.map +1 -1
- package/dist/components/ui/tabs.d.ts +1 -1
- package/dist/data-grid-i18n-52UUYPbr.d.ts +66 -0
- package/dist/data-grid-i18n-52UUYPbr.d.ts.map +1 -0
- package/dist/use-active-option-CmX6Z-4S.js +86 -0
- package/dist/use-active-option-CmX6Z-4S.js.map +1 -0
- package/package.json +5 -5
- package/dist/context-BizvUNZv.js.map +0 -1
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { Button } from "../../ui/button.js";
|
|
2
3
|
import { Spinner } from "../../ui/spinner.js";
|
|
3
4
|
import { Checkbox } from "../../ui/checkbox.js";
|
|
4
|
-
import { useDataGrid } from "./data-grid.js";
|
|
5
|
+
import { dataGridCellSelectionCellClasses, getDataGridCellSelectionCellAttrs, toDataGridDomId, useDataGrid } from "./data-grid.js";
|
|
5
6
|
import { Fragment, memo, useCallback, useEffect, useLayoutEffect, useMemo, useRef } from "react";
|
|
6
7
|
import { cn } from "@kumix/utils";
|
|
7
8
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { PlusIcon } from "lucide-react";
|
|
8
10
|
import { Subscribe, flexRender } from "@tanstack/react-table";
|
|
9
11
|
//#region src/components/reui/data-grid/data-grid-table.tsx
|
|
10
12
|
const headerCellSpacingVariants = ({ size }) => size === "dense" ? "px-2 h-8" : "px-3";
|
|
11
13
|
const bodyCellSpacingVariants = ({ size }) => size === "dense" ? "px-2 py-1.5" : "px-3 py-2";
|
|
14
|
+
const bodyCellTruncateWrapVariants = ({ size }) => size === "dense" ? "-mx-2 -my-1.5 truncate px-2 py-1.5" : "-mx-3 -my-2 truncate px-3 py-2";
|
|
12
15
|
const footerCellSpacingVariants = ({ size }) => size === "dense" ? "px-2 py-1.5" : "px-3 py-2";
|
|
13
16
|
function getPinningStyles(column) {
|
|
14
17
|
const isPinned = column.getIsPinned();
|
|
@@ -62,7 +65,7 @@ function getDataGridResizeEventClientX(event, touchIdentifier) {
|
|
|
62
65
|
}
|
|
63
66
|
return event.clientX;
|
|
64
67
|
}
|
|
65
|
-
function startDataGridColumnResizeOnEnd(event, header, table) {
|
|
68
|
+
function startDataGridColumnResizeOnEnd(event, header, table, live = false) {
|
|
66
69
|
const column = table.getColumn(header.column.id);
|
|
67
70
|
if (!column?.getCanResize()) return;
|
|
68
71
|
const isTouchSession = isDataGridTouchEvent(event);
|
|
@@ -75,13 +78,16 @@ function startDataGridColumnResizeOnEnd(event, header, table) {
|
|
|
75
78
|
const startSize = header.getSize();
|
|
76
79
|
const touchIdentifier = isTouchSession ? event.touches[0]?.identifier : void 0;
|
|
77
80
|
const dragStartClientX = getDataGridResizeEventClientX(event, touchIdentifier);
|
|
78
|
-
const
|
|
79
|
-
const
|
|
81
|
+
const headerCell = event.currentTarget.closest("th");
|
|
82
|
+
const headerRect = headerCell?.getBoundingClientRect();
|
|
83
|
+
const liveTableElement = live ? headerCell?.closest("table") : null;
|
|
84
|
+
const resizeRtl = table.options.columnResizeDirection === "rtl" !== (column.getIsPinned() === "end");
|
|
85
|
+
const startOffset = headerRect && Number.isFinite(resizeRtl ? headerRect.left : headerRect.right) ? resizeRtl ? headerRect.left : headerRect.right : dragStartClientX;
|
|
80
86
|
if (typeof dragStartClientX !== "number" || typeof startOffset !== "number") return;
|
|
81
87
|
ownerDocument.body.style.cursor = "col-resize";
|
|
82
88
|
ownerDocument.documentElement.style.cursor = "col-resize";
|
|
83
89
|
const columnSizingStart = header.getLeafHeaders().map((leafHeader) => [leafHeader.column.id, leafHeader.column.getSize()]);
|
|
84
|
-
const directionMultiplier =
|
|
90
|
+
const directionMultiplier = resizeRtl ? -1 : 1;
|
|
85
91
|
let minDeltaPercentage = -.999999;
|
|
86
92
|
let maxDeltaPercentage = Number.POSITIVE_INFINITY;
|
|
87
93
|
columnSizingStart.forEach(([columnId, headerSize]) => {
|
|
@@ -104,7 +110,13 @@ function startDataGridColumnResizeOnEnd(event, header, table) {
|
|
|
104
110
|
columnSizingStart.forEach(([columnId, headerSize]) => {
|
|
105
111
|
nextColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
|
|
106
112
|
});
|
|
107
|
-
|
|
113
|
+
if (liveTableElement) columnSizingStart.forEach(([columnId]) => {
|
|
114
|
+
const nextSize = nextColumnSizing[columnId];
|
|
115
|
+
if (typeof nextSize !== "number") return;
|
|
116
|
+
liveTableElement.style.setProperty(`--col-${columnId}-size`, String(nextSize));
|
|
117
|
+
liveTableElement.style.setProperty(`--header-${columnId}-size`, String(nextSize));
|
|
118
|
+
});
|
|
119
|
+
else table.setColumnResizing((old) => ({
|
|
108
120
|
...old,
|
|
109
121
|
startOffset,
|
|
110
122
|
startSize,
|
|
@@ -268,45 +280,83 @@ function getDataGridTableMergedHeaderGroups(table) {
|
|
|
268
280
|
function hasDataGridTableRightPinnedColumns(table) {
|
|
269
281
|
return (table.state.columnPinning.end?.length ?? 0) > 0;
|
|
270
282
|
}
|
|
283
|
+
function hasDataGridFillColumn(table) {
|
|
284
|
+
return table.getVisibleLeafColumns().some((column) => column.columnDef.meta?.fillWidth);
|
|
285
|
+
}
|
|
271
286
|
function DataGridTableFillCol() {
|
|
272
|
-
const { props } = useDataGrid();
|
|
287
|
+
const { props, table } = useDataGrid();
|
|
273
288
|
if (!props.tableLayout?.columnsResizable) return null;
|
|
274
289
|
return /* @__PURE__ */ jsx("col", {
|
|
275
290
|
"data-slot": "data-grid-table-fill-col",
|
|
276
|
-
style: { width: "var(--data-grid-fill-size, 0px)" }
|
|
291
|
+
style: { width: hasDataGridFillColumn(table) ? 0 : "var(--data-grid-fill-size, 0px)" }
|
|
277
292
|
});
|
|
278
293
|
}
|
|
279
294
|
function DataGridTableFillHeadCell() {
|
|
280
|
-
const { props } = useDataGrid();
|
|
295
|
+
const { props, table } = useDataGrid();
|
|
281
296
|
if (!props.tableLayout?.columnsResizable) return null;
|
|
282
297
|
return /* @__PURE__ */ jsx("th", {
|
|
283
298
|
"data-slot": "data-grid-table-fill-head-cell",
|
|
284
|
-
style: { width: "var(--data-grid-fill-size, 0px)" },
|
|
299
|
+
style: { width: hasDataGridFillColumn(table) ? 0 : "var(--data-grid-fill-size, 0px)" },
|
|
285
300
|
className: cn("p-0", props.tableLayout?.headerBackground && "bg-muted")
|
|
286
301
|
});
|
|
287
302
|
}
|
|
288
303
|
function DataGridTableFillBodyCell() {
|
|
289
|
-
const { props } = useDataGrid();
|
|
304
|
+
const { props, table } = useDataGrid();
|
|
290
305
|
if (!props.tableLayout?.columnsResizable) return null;
|
|
291
306
|
return /* @__PURE__ */ jsx("td", {
|
|
292
307
|
"aria-hidden": "true",
|
|
293
308
|
"data-slot": "data-grid-table-fill-body-cell",
|
|
294
|
-
style: { width: "var(--data-grid-fill-size, 0px)" },
|
|
309
|
+
style: { width: hasDataGridFillColumn(table) ? 0 : "var(--data-grid-fill-size, 0px)" },
|
|
295
310
|
className: "p-0"
|
|
296
311
|
});
|
|
297
312
|
}
|
|
298
313
|
function DataGridTableFillFootCell() {
|
|
299
|
-
const { props } = useDataGrid();
|
|
314
|
+
const { props, table } = useDataGrid();
|
|
300
315
|
if (!props.tableLayout?.columnsResizable) return null;
|
|
301
316
|
return /* @__PURE__ */ jsx("td", {
|
|
302
317
|
"aria-hidden": "true",
|
|
303
318
|
"data-slot": "data-grid-table-fill-foot-cell",
|
|
304
|
-
style: { width: "var(--data-grid-fill-size, 0px)" },
|
|
319
|
+
style: { width: hasDataGridFillColumn(table) ? 0 : "var(--data-grid-fill-size, 0px)" },
|
|
305
320
|
className: "p-0"
|
|
306
321
|
});
|
|
307
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* The quick-create affordance, rendered as the body's last row when
|
|
325
|
+
* `onRowCreate` is set: one full-width ghost button, the Notion/Airtable
|
|
326
|
+
* "+ New" idiom. What the click creates stays consumer-owned.
|
|
327
|
+
*/
|
|
328
|
+
function DataGridTableAddRow() {
|
|
329
|
+
const { i18n, props, table } = useDataGrid();
|
|
330
|
+
if (!props.onRowCreate) return null;
|
|
331
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
332
|
+
"data-slot": "data-grid-table-add-row",
|
|
333
|
+
className: cn("hover:bg-muted/40 [thead+tbody_&:first-child]:border-t", props.tableClassNames?.rowCreate),
|
|
334
|
+
children: /* @__PURE__ */ jsx("td", {
|
|
335
|
+
colSpan: table.getVisibleLeafColumns().length + (props.tableLayout?.columnsResizable ? 1 : 0),
|
|
336
|
+
className: "p-0",
|
|
337
|
+
children: /* @__PURE__ */ jsxs(Button, {
|
|
338
|
+
type: "button",
|
|
339
|
+
variant: "ghost",
|
|
340
|
+
size: "sm",
|
|
341
|
+
className: cn("flex w-full items-center justify-start rounded-none px-3 text-muted-foreground", props.tableLayout?.dense ? "h-8 px-2" : "h-9"),
|
|
342
|
+
onClick: (event) => {
|
|
343
|
+
const button = event.currentTarget;
|
|
344
|
+
const grid = button.closest("table");
|
|
345
|
+
props.onRowCreate?.();
|
|
346
|
+
setTimeout(() => {
|
|
347
|
+
if (!button.isConnected && grid?.isConnected && grid.tabIndex >= 0 && (document.activeElement === document.body || !document.activeElement)) grid.focus();
|
|
348
|
+
}, 0);
|
|
349
|
+
},
|
|
350
|
+
children: [/* @__PURE__ */ jsx(PlusIcon, {
|
|
351
|
+
className: "size-4",
|
|
352
|
+
"aria-hidden": "true"
|
|
353
|
+
}), props.rowCreateLabel ?? i18n.labels.rowCreate]
|
|
354
|
+
})
|
|
355
|
+
})
|
|
356
|
+
});
|
|
357
|
+
}
|
|
308
358
|
function DataGridTableBase({ children }) {
|
|
309
|
-
const { props, table } = useDataGrid();
|
|
359
|
+
const { props, table, recordCount } = useDataGrid();
|
|
310
360
|
const leftVisibleColumns = table.getStartVisibleLeafColumns();
|
|
311
361
|
const centerVisibleColumns = table.getCenterVisibleLeafColumns();
|
|
312
362
|
const rightVisibleColumns = table.getEndVisibleLeafColumns();
|
|
@@ -320,16 +370,25 @@ function DataGridTableBase({ children }) {
|
|
|
320
370
|
const columnSizeVars = useMemo(() => {
|
|
321
371
|
if (!props.tableLayout?.columnsResizable) return void 0;
|
|
322
372
|
const headers = table.getFlatHeaders();
|
|
373
|
+
const fillColumnId = table.getVisibleLeafColumns().find((column) => column.columnDef.meta?.fillWidth)?.id;
|
|
323
374
|
const colSizes = {};
|
|
324
375
|
for (let i = 0; i < headers.length; i++) {
|
|
325
376
|
const header = headers[i];
|
|
326
377
|
colSizes[`--header-${header.id}-size`] = header.getSize();
|
|
327
|
-
colSizes[`--col-${header.column.id}-size`] = header.column.getSize();
|
|
378
|
+
colSizes[`--col-${header.column.id}-size`] = header.column.id === fillColumnId ? `calc(${header.column.getSize()} + var(--data-grid-fill, 0))` : header.column.getSize();
|
|
328
379
|
}
|
|
329
380
|
return colSizes;
|
|
330
|
-
}, [
|
|
381
|
+
}, [
|
|
382
|
+
props.tableLayout?.columnsResizable,
|
|
383
|
+
table.getFlatHeaders,
|
|
384
|
+
table.getVisibleLeafColumns
|
|
385
|
+
]);
|
|
386
|
+
const cellSelectionOn = !!props.tableLayout?.cellSelection && table.atoms.cellSelection != null;
|
|
331
387
|
return /* @__PURE__ */ jsxs("table", {
|
|
332
388
|
"data-slot": "data-grid-table",
|
|
389
|
+
role: cellSelectionOn ? "grid" : void 0,
|
|
390
|
+
"aria-multiselectable": cellSelectionOn && props.tableLayout?.cellSelectionMode !== "single" ? true : void 0,
|
|
391
|
+
"aria-rowcount": cellSelectionOn ? Math.max(recordCount, table.getRowsInDisplayOrder().length) + 1 : void 0,
|
|
333
392
|
className: cn("caption-bottom text-left align-middle font-normal text-foreground text-sm rtl:text-right", props.tableLayout?.columnsResizable ? "min-w-0" : "w-full min-w-full", props.tableLayout?.width === "auto" ? "table-auto" : "table-fixed", !props.tableLayout?.columnsResizable && "", !props.tableLayout?.columnsDraggable && "border-separate border-spacing-0", props.tableClassNames?.base),
|
|
334
393
|
style: props.tableLayout?.columnsResizable ? {
|
|
335
394
|
...columnSizeVars,
|
|
@@ -355,12 +414,14 @@ function DataGridTableViewport({ children, className, viewportRef, style }) {
|
|
|
355
414
|
const syncFillWidth = useCallback(() => {
|
|
356
415
|
const node = viewportNodeRef.current;
|
|
357
416
|
if (!node) return;
|
|
358
|
-
const
|
|
417
|
+
const freeSpace = fillStateRef.current.containerWidth - table.getTotalSize();
|
|
418
|
+
const fillWidth = Math.max(0, freeSpace);
|
|
359
419
|
if (fillStateRef.current.appliedFill !== fillWidth) {
|
|
360
420
|
fillStateRef.current.appliedFill = fillWidth;
|
|
361
421
|
node.style.setProperty("--data-grid-fill-size", `${fillWidth}px`);
|
|
422
|
+
node.style.setProperty("--data-grid-fill", String(fillWidth));
|
|
362
423
|
}
|
|
363
|
-
autoSize?.apply(
|
|
424
|
+
autoSize?.apply(freeSpace);
|
|
364
425
|
}, [autoSize, table]);
|
|
365
426
|
const handleViewportRef = useCallback((node) => {
|
|
366
427
|
stopContainerObserverRef.current?.();
|
|
@@ -371,6 +432,7 @@ function DataGridTableViewport({ children, className, viewportRef, style }) {
|
|
|
371
432
|
if (!isColumnsResizable) {
|
|
372
433
|
fillStateRef.current.appliedFill = -1;
|
|
373
434
|
node.style.removeProperty("--data-grid-fill-size");
|
|
435
|
+
node.style.removeProperty("--data-grid-fill");
|
|
374
436
|
return;
|
|
375
437
|
}
|
|
376
438
|
const measurementTarget = getDataGridScrollAreaViewport(node) ?? node.parentElement ?? node;
|
|
@@ -414,12 +476,13 @@ function DataGridTableHead({ children }) {
|
|
|
414
476
|
function DataGridTableHeadRow({ children }) {
|
|
415
477
|
const { props } = useDataGrid();
|
|
416
478
|
return /* @__PURE__ */ jsx("tr", {
|
|
479
|
+
"aria-rowindex": props.tableLayout?.cellSelection ? 1 : void 0,
|
|
417
480
|
className: cn(props.tableLayout?.headerBorder && "[&>th]:border-b", props.tableLayout?.cellBorder && "*:last:border-e-0", props.tableLayout?.stripped && "bg-transparent", props.tableLayout?.headerBackground === false && "bg-transparent", props.tableClassNames?.headerRow),
|
|
418
481
|
children
|
|
419
482
|
});
|
|
420
483
|
}
|
|
421
484
|
function DataGridTableHeadRowCell({ children, header, dndRef, dndStyle }) {
|
|
422
|
-
const { props } = useDataGrid();
|
|
485
|
+
const { props, table } = useDataGrid();
|
|
423
486
|
const { column } = header;
|
|
424
487
|
const isPinned = column.getIsPinned();
|
|
425
488
|
const isFirstStartPinned = isPinned === "start" && column.getIsFirstColumn("start");
|
|
@@ -433,17 +496,20 @@ function DataGridTableHeadRowCell({ children, header, dndRef, dndStyle }) {
|
|
|
433
496
|
ref: dndRef,
|
|
434
497
|
scope: "col",
|
|
435
498
|
colSpan: header.colSpan > 1 ? header.colSpan : void 0,
|
|
436
|
-
"aria-sort": sortDirection === "asc" ? "ascending" : sortDirection === "desc" ? "descending" : void 0,
|
|
499
|
+
"aria-sort": sortDirection === "asc" ? "ascending" : sortDirection === "desc" ? "descending" : column.getCanSort() ? "none" : void 0,
|
|
500
|
+
"aria-colindex": props.tableLayout?.cellSelection ? column.getIndex() + 1 : void 0,
|
|
501
|
+
"data-col-id": column.id,
|
|
437
502
|
style: {
|
|
438
503
|
...props.tableLayout?.width === "fixed" && !props.tableLayout?.columnsResizable && { width: header.getSize() },
|
|
439
504
|
...props.tableLayout?.columnsPinnable && column.getCanPin() && getPinningStyles(column),
|
|
505
|
+
...props.tableLayout?.headerSticky && isPinned && { top: 0 },
|
|
440
506
|
...props.tableLayout?.columnsResizable && { width: `calc(var(--header-${header.id}-size) * 1px)` },
|
|
441
507
|
...dndStyle ? dndStyle : null
|
|
442
508
|
},
|
|
443
509
|
"data-pinned": isPinned || void 0,
|
|
444
510
|
"data-outer-pinned-col": isFirstStartPinned ? "start" : isLastEndPinned ? "end" : void 0,
|
|
445
511
|
"data-last-col": isLastStartPinned ? "start" : isFirstEndPinned ? "end" : void 0,
|
|
446
|
-
className: cn("relative h-10 text-left align-middle font-medium text-foreground rtl:text-right [&:has([role=checkbox])]:pe-0", headerCellSpacing, props.tableLayout?.headerBackground && "bg-muted", props.tableLayout?.cellBorder && "border-e", props.tableLayout?.columnsResizable && column.getCanResize() && (isPinned ? "overflow-hidden" : "overflow-visible"), props.tableLayout?.columnsResizable && column.getCanResize() && isLastVisibleColumn && "pe-8", props.tableLayout?.columnsPinnable && column.getCanPin() && cn("data-pinned:isolate data-pinned:bg-muted data-outer-pinned-col:bg-clip-padding", "[&[data-pinned=end]:last-child_div.cursor-col-resize:last-child]:opacity-0 [&[data-pinned=end][data-last-col=end]]:shadow-[inset_1px_0_0_0_var(--border)] [&[data-pinned=start][data-last-col=start]]:shadow-[inset_-1px_0_0_0_var(--border)]", "[&:not([data-pinned]):has(+[data-pinned])_div.cursor-col-resize:last-child]:opacity-0 [&[data-last-col=start]_div.cursor-col-resize:last-child]:opacity-0"), header.column.columnDef.meta?.headerClassName, column.getIndex() === 0 || isLastVisibleColumn ? props.tableClassNames?.edgeCell : ""),
|
|
512
|
+
className: cn("relative h-10 text-left align-middle font-medium text-foreground rtl:text-right [&:has([role=checkbox])]:pe-0", headerCellSpacing, props.tableLayout?.headerBackground && "bg-muted", props.tableLayout?.cellBorder && "border-e", props.tableLayout?.cellBorder && props.tableLayout?.columnsResizable && (props.tableLayout?.columnsPinnable || !hasDataGridTableRightPinnedColumns(table)) && !isPinned && column.getIsLastColumn("center") && "border-e-0", props.tableLayout?.columnsResizable && column.getCanResize() && (isPinned ? "overflow-hidden" : "overflow-visible"), props.tableLayout?.columnsResizable && column.getCanResize() && isLastVisibleColumn && "pe-8", props.tableLayout?.columnsPinnable && column.getCanPin() && cn("data-pinned:isolate data-pinned:bg-muted data-outer-pinned-col:bg-clip-padding", "[&[data-pinned=end]:last-child_div.cursor-col-resize:last-child]:opacity-0 [&[data-pinned=end][data-last-col=end]]:shadow-[inset_1px_0_0_0_var(--border)] [&[data-pinned=start][data-last-col=start]]:shadow-[inset_-1px_0_0_0_var(--border)]", "[&:not([data-pinned]):has(+[data-pinned])_div.cursor-col-resize:last-child]:opacity-0 [&[data-last-col=start]_div.cursor-col-resize:last-child]:opacity-0"), header.column.columnDef.meta?.headerClassName, column.getIndex() === 0 || isLastVisibleColumn ? props.tableClassNames?.edgeCell : ""),
|
|
447
513
|
children
|
|
448
514
|
});
|
|
449
515
|
}
|
|
@@ -479,28 +545,21 @@ function DataGridTableHeadRowCellResize({ header }) {
|
|
|
479
545
|
if (event.button !== 0) return;
|
|
480
546
|
event.preventDefault();
|
|
481
547
|
event.stopPropagation();
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
stopResizeSessionRef.current = startDataGridColumnResizeOnEnd(event, header, table);
|
|
485
|
-
return;
|
|
486
|
-
}
|
|
487
|
-
header.getResizeHandler()(event);
|
|
548
|
+
stopResizeSessionRef.current?.();
|
|
549
|
+
stopResizeSessionRef.current = startDataGridColumnResizeOnEnd(event, header, table, !isResizeModeOnEnd);
|
|
488
550
|
};
|
|
489
551
|
const handleTouchStart = (event) => {
|
|
490
552
|
event.preventDefault();
|
|
491
553
|
event.stopPropagation();
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
stopResizeSessionRef.current = startDataGridColumnResizeOnEnd(event, header, table);
|
|
495
|
-
return;
|
|
496
|
-
}
|
|
497
|
-
header.getResizeHandler()(event);
|
|
554
|
+
stopResizeSessionRef.current?.();
|
|
555
|
+
stopResizeSessionRef.current = startDataGridColumnResizeOnEnd(event, header, table, !isResizeModeOnEnd);
|
|
498
556
|
};
|
|
499
|
-
return /* @__PURE__ */ jsx("
|
|
557
|
+
return /* @__PURE__ */ jsx("span", {
|
|
558
|
+
"data-slot": "data-grid-table-resize-handle",
|
|
500
559
|
onDoubleClick: () => column.resetSize(),
|
|
501
560
|
onMouseDown: handleMouseDown,
|
|
502
561
|
onTouchStart: handleTouchStart,
|
|
503
|
-
className: cn("user-select-none absolute top-0 z-10 flex h-full cursor-col-resize touch-none", isLastVisibleColumn ? "end-0 w-5 justify-end before:hidden" : isPinned ? cn("end-0 w-5 justify-end", props.tableLayout?.columnsPinnable ? "before:hidden" : "before:absolute before:inset-y-0 before:end-0 before:w-px before:bg-border") : "-end-2 w-5 justify-center before:absolute before:inset-y-0 before:w-px before:-translate-x-px before:bg-border", column.getIsResizing() && (isResizeModeOnEnd ? "opacity-100" : isLastVisibleColumn ? "opacity-100 before:absolute before:inset-y-0 before:end-0 before:block before:w-0.5 before:bg-primary" : "opacity-100 before:block before:w-0.5 before:bg-primary"))
|
|
562
|
+
className: cn("user-select-none absolute top-0 z-10 flex h-full cursor-col-resize touch-none", isPinned === "end" ? cn("start-0 w-5 justify-start", props.tableLayout?.columnsPinnable ? "before:hidden" : "before:absolute before:inset-y-0 before:start-0 before:w-px before:bg-border") : isLastVisibleColumn ? "end-0 w-5 justify-end before:hidden" : isPinned ? cn("end-0 w-5 justify-end", props.tableLayout?.columnsPinnable ? "before:hidden" : "before:absolute before:inset-y-0 before:end-0 before:w-px before:bg-border") : cn("-end-2 w-5 justify-center", props.tableLayout?.cellBorder ? "before:hidden" : "before:absolute before:inset-y-0 before:w-px before:-translate-x-px before:bg-border"), column.getIsResizing() && (isResizeModeOnEnd ? "opacity-100" : isLastVisibleColumn ? "opacity-100 before:absolute before:inset-y-0 before:end-0 before:block before:w-0.5 before:bg-primary" : "opacity-100 before:block before:w-0.5 before:bg-primary"))
|
|
504
563
|
});
|
|
505
564
|
}
|
|
506
565
|
function DataGridTableResizeIndicator({ viewportNodeRef }) {
|
|
@@ -522,14 +581,21 @@ function DataGridTableResizeIndicator({ viewportNodeRef }) {
|
|
|
522
581
|
if (!isActive || !indicator || !indicatorHead || !resizingColumnId) return;
|
|
523
582
|
const resizingHeader = table.getFlatHeaders().find((header) => header.column.id === resizingColumnId || header.id === resizingColumnId);
|
|
524
583
|
if (!resizingHeader) return;
|
|
525
|
-
const directionMultiplier = table.options.columnResizeDirection === "rtl" ? -1 : 1;
|
|
584
|
+
const directionMultiplier = table.options.columnResizeDirection === "rtl" !== (resizingHeader.column.getIsPinned() === "end") ? -1 : 1;
|
|
526
585
|
const deltaOffset = (columnResizing.deltaOffset ?? 0) * directionMultiplier;
|
|
527
586
|
if (headerHeightCacheRef.current.key !== resizingColumnId) headerHeightCacheRef.current = {
|
|
528
587
|
key: resizingColumnId,
|
|
529
588
|
value: viewportElement?.querySelector("[data-slot=\"data-grid-table\"] thead")?.getBoundingClientRect().height ?? 0
|
|
530
589
|
};
|
|
531
590
|
const headerHeight = headerHeightCacheRef.current.value;
|
|
532
|
-
const
|
|
591
|
+
const viewportRoot = viewportElement ?? indicator.closest("[data-slot=\"data-grid-table-viewport\"]");
|
|
592
|
+
const headerCellElement = viewportRoot?.querySelector(`thead th[data-col-id="${CSS.escape(resizingHeader.column.id)}"]`);
|
|
593
|
+
let indicatorLeft;
|
|
594
|
+
if (headerCellElement && viewportRoot) {
|
|
595
|
+
const anchorRect = headerCellElement.getBoundingClientRect();
|
|
596
|
+
indicatorLeft = (table.options.columnResizeDirection === "rtl" !== (resizingHeader.column.getIsPinned() === "end") ? anchorRect.left : anchorRect.right) - viewportRoot.getBoundingClientRect().left;
|
|
597
|
+
} else if (typeof columnResizing.startOffset === "number" && viewportElement) indicatorLeft = columnResizing.startOffset - viewportElement.getBoundingClientRect().left;
|
|
598
|
+
else indicatorLeft = resizingHeader.getStart() + resizingHeader.getSize();
|
|
533
599
|
indicator.style.left = `${indicatorLeft}px`;
|
|
534
600
|
indicator.style.transform = `translateX(${deltaOffset}px)`;
|
|
535
601
|
indicatorHead.style.height = `${Math.max(headerHeight, 6)}px`;
|
|
@@ -571,10 +637,10 @@ function DataGridTableFoot({ children }) {
|
|
|
571
637
|
});
|
|
572
638
|
}
|
|
573
639
|
function DataGridTableFootRow({ children }) {
|
|
574
|
-
const { props } = useDataGrid();
|
|
640
|
+
const { props, table } = useDataGrid();
|
|
575
641
|
return /* @__PURE__ */ jsxs("tr", {
|
|
576
642
|
"data-slot": "data-grid-table-foot-row",
|
|
577
|
-
className: cn(props.tableLayout?.footerBackground && "bg-muted/40 dark:bg-background", props.tableLayout?.rowBorder && "[&:not(:last-child)>td]:border-b", props.tableLayout?.cellBorder && "*:last:border-e-0"),
|
|
643
|
+
className: cn(props.tableLayout?.footerBackground && "bg-muted/40 dark:bg-background", props.tableLayout?.rowBorder && "[&:not(:last-child)>td]:border-b", props.tableLayout?.cellBorder && "*:last:border-e-0", props.tableLayout?.cellBorder && props.tableLayout?.columnsResizable && (props.tableLayout?.columnsPinnable || !hasDataGridTableRightPinnedColumns(table)) && "[&>td:has(+td[data-slot=data-grid-table-fill-foot-cell])]:border-e-0"),
|
|
578
644
|
children: [children, /* @__PURE__ */ jsx(DataGridTableFillFootCell, {})]
|
|
579
645
|
});
|
|
580
646
|
}
|
|
@@ -588,9 +654,9 @@ function DataGridTableFootRowCell({ children, colSpan, className }) {
|
|
|
588
654
|
});
|
|
589
655
|
}
|
|
590
656
|
function DataGridTableBodyRowSkeleton({ children }) {
|
|
591
|
-
const {
|
|
657
|
+
const { props } = useDataGrid();
|
|
592
658
|
return /* @__PURE__ */ jsx("tr", {
|
|
593
|
-
className: cn("hover:bg-muted/40 data-[state=selected]:bg-muted/50", props.onRowClick && "cursor-pointer", !props.tableLayout?.stripped && props.tableLayout?.rowBorder && "border-border border-b [&:not(:last-child)>td]:border-b", props.tableLayout?.cellBorder && "*:last:border-e-0", props.tableLayout?.stripped && "odd:bg-muted/90 hover:bg-transparent odd:hover:bg-muted",
|
|
659
|
+
className: cn("hover:bg-muted/40 data-[state=selected]:bg-muted/50", props.onRowClick && "cursor-pointer", !props.tableLayout?.stripped && props.tableLayout?.rowBorder && "border-border border-b [&:not(:last-child)>td]:border-b", props.tableLayout?.cellBorder && "*:last:border-e-0", props.tableLayout?.stripped && "odd:bg-muted/90 hover:bg-transparent odd:hover:bg-muted", props.tableClassNames?.bodyRow),
|
|
594
660
|
children
|
|
595
661
|
});
|
|
596
662
|
}
|
|
@@ -599,13 +665,14 @@ function DataGridTableBodyRowSkeletonCell({ children, column }) {
|
|
|
599
665
|
const bodyCellSpacing = bodyCellSpacingVariants({ size: props.tableLayout?.dense ? "dense" : "default" });
|
|
600
666
|
return /* @__PURE__ */ jsx("td", {
|
|
601
667
|
style: props.tableLayout?.columnsResizable ? { width: `calc(var(--col-${column.id}-size) * 1px)` } : void 0,
|
|
602
|
-
className: cn("align-middle", bodyCellSpacing, props.tableLayout?.cellBorder && "border-e", props.tableLayout?.columnsResizable && column.getCanResize() && "truncate", column.columnDef.meta?.cellClassName, props.tableLayout?.columnsPinnable && column.getCanPin() && "data-pinned:isolate data-pinned:bg-background [&[data-pinned=end][data-last-col=end]]:shadow-[inset_1px_0_0_0_var(--border)] [&[data-pinned=start][data-last-col=start]]:shadow-[inset_-1px_0_0_0_var(--border)]", column.getIndex() === 0 || column.getIndex() === table.getVisibleLeafColumns().length - 1 ? props.tableClassNames?.edgeCell : ""),
|
|
668
|
+
className: cn("align-middle", bodyCellSpacing, props.tableLayout?.cellBorder && "border-e", props.tableLayout?.cellBorder && props.tableLayout?.columnsResizable && (props.tableLayout?.columnsPinnable || !hasDataGridTableRightPinnedColumns(table)) && !column.getIsPinned() && column.getIsLastColumn("center") && "border-e-0", props.tableLayout?.columnsResizable && column.getCanResize() && "truncate", column.columnDef.meta?.cellClassName, props.tableLayout?.columnsPinnable && column.getCanPin() && "data-pinned:isolate data-pinned:bg-background [&[data-pinned=end][data-last-col=end]]:shadow-[inset_1px_0_0_0_var(--border)] [&[data-pinned=start][data-last-col=start]]:shadow-[inset_-1px_0_0_0_var(--border)]", column.getIndex() === 0 || column.getIndex() === table.getVisibleLeafColumns().length - 1 ? props.tableClassNames?.edgeCell : ""),
|
|
603
669
|
children
|
|
604
670
|
});
|
|
605
671
|
}
|
|
606
672
|
function DataGridTableBodyRow({ children, row, pinnedBoundary, rowRef, dndRef, dndStyle, dataIndex }) {
|
|
607
673
|
const { props, table } = useDataGrid();
|
|
608
674
|
const isRowPinned = row.getIsPinned();
|
|
675
|
+
const rowStatus = props.getRowStatus?.(row.original);
|
|
609
676
|
const bodyRowBottomBorderClasses = "[&:not(:last-child)>td]:border-b [tbody:has(+tfoot)_&:last-child>td]:border-b [*:has(>[data-slot=data-grid]+[data-slot=data-grid-pagination])_[data-slot=data-grid]_&:last-child>td]:border-b";
|
|
610
677
|
return /* @__PURE__ */ jsx("tr", {
|
|
611
678
|
ref: (node) => {
|
|
@@ -619,8 +686,10 @@ function DataGridTableBodyRow({ children, row, pinnedBoundary, rowRef, dndRef, d
|
|
|
619
686
|
"data-depth": row.depth || void 0,
|
|
620
687
|
"data-row-pinned": isRowPinned || void 0,
|
|
621
688
|
"data-row-pinned-boundary": pinnedBoundary,
|
|
689
|
+
"data-row-status": rowStatus,
|
|
690
|
+
"aria-rowindex": props.tableLayout?.cellSelection ? row.index + 2 : void 0,
|
|
622
691
|
onClick: () => props.onRowClick?.(row.original),
|
|
623
|
-
className: cn("hover:bg-muted/40 data-[state=selected]:bg-muted/50", props.onRowClick && "cursor-pointer", !props.tableLayout?.stripped && props.tableLayout?.rowBorder && bodyRowBottomBorderClasses, props.tableLayout?.cellBorder && `*:last:border-e-0 ${bodyRowBottomBorderClasses}`, props.tableLayout?.stripped && (typeof dataIndex === "number" ? cn("hover:bg-transparent", dataIndex % 2 === 0 && "bg-muted/90 hover:bg-muted") : "odd:bg-muted/90 hover:bg-transparent odd:hover:bg-muted"),
|
|
692
|
+
className: cn("hover:bg-muted/40 data-[state=selected]:bg-muted/50", "hover:[&>td[data-pinned]]:bg-[color-mix(in_oklab,var(--muted)_40%,var(--background))]", "data-[state=selected]:[&>td[data-pinned]]:bg-[color-mix(in_oklab,var(--muted)_50%,var(--background))]", props.onRowClick && "cursor-pointer", props.getRowStatus && "data-[row-status=deleted]:bg-destructive/5 data-[row-status=dirty]:bg-amber-500/5 data-[row-status=new]:bg-green-500/5 data-[row-status=deleted]:opacity-60 data-[row-status=deleted]:[&_td]:line-through", props.getRowStatus && "data-[row-status=deleted]:[&>td[data-pinned]]:bg-[color-mix(in_oklab,var(--destructive)_5%,var(--background))] data-[row-status=dirty]:[&>td[data-pinned]]:bg-[color-mix(in_oklab,var(--color-amber-500)_5%,var(--background))] data-[row-status=new]:[&>td[data-pinned]]:bg-[color-mix(in_oklab,var(--color-green-500)_5%,var(--background))]", rowStatus === "new" && props.tableClassNames?.rowNew, rowStatus === "dirty" && props.tableClassNames?.rowDirty, rowStatus === "deleted" && props.tableClassNames?.rowDeleted, !props.tableLayout?.stripped && props.tableLayout?.rowBorder && bodyRowBottomBorderClasses, props.tableLayout?.cellBorder && `*:last:border-e-0 ${bodyRowBottomBorderClasses}`, props.tableLayout?.stripped && (typeof dataIndex === "number" ? cn("hover:bg-transparent", dataIndex % 2 === 0 && "bg-muted/90 hover:bg-muted") : "odd:bg-muted/90 hover:bg-transparent odd:hover:bg-muted"), props.tableLayout?.rowsPinnable && isRowPinned && "bg-muted/30 hover:bg-muted/50", pinnedBoundary === "top" && "[&>td]:shadow-[0_2px_0_rgba(0,0,0,0.03)] dark:[&>td]:shadow-[0_2px_0_rgba(255,255,255,0.06)]", pinnedBoundary === "bottom" && "[&>td]:shadow-[0_-2px_0_rgba(0,0,0,0.03)] dark:[&>td]:shadow-[0_-2px_0_rgba(255,255,255,0.06)]", props.tableLayout?.rowsPinnable && isRowPinned && props.tableClassNames?.rowPinned, props.tableClassNames?.bodyRow),
|
|
624
693
|
children
|
|
625
694
|
});
|
|
626
695
|
}
|
|
@@ -636,42 +705,111 @@ function DataGridTableBodyRowExpandded({ row }) {
|
|
|
636
705
|
})
|
|
637
706
|
});
|
|
638
707
|
}
|
|
639
|
-
|
|
640
|
-
|
|
708
|
+
/**
|
|
709
|
+
* Interactive descendants keep their own mousedown semantics: a click on a
|
|
710
|
+
* button, link, editor or checkbox inside a cell must never start or replace
|
|
711
|
+
* a range. One selector also covers the row-dnd grip (a button), the expand
|
|
712
|
+
* toggle, and `data-cell-interactive` - the documented opt-out for custom
|
|
713
|
+
* widgets built from elements the tag list cannot know about.
|
|
714
|
+
*/
|
|
715
|
+
function isDataGridCellInteractiveTarget(target) {
|
|
716
|
+
return target instanceof Element && target.closest("button, a, input, select, textarea, [contenteditable], [role=\"checkbox\"], [data-cell-interactive], [data-slot=\"data-grid-table-row-expand\"], [data-slot=\"data-grid-cell-fill-handle\"]") != null;
|
|
717
|
+
}
|
|
718
|
+
function DataGridTableBodyRowCell({ children, cell, dndRef, dndStyle, columnIndex }) {
|
|
719
|
+
const { props, table, gridId } = useDataGrid();
|
|
641
720
|
const { column, row } = cell;
|
|
642
721
|
const isPinned = column.getIsPinned();
|
|
643
722
|
const isLastStartPinned = isPinned === "start" && column.getIsLastColumn("start");
|
|
644
723
|
const isFirstEndPinned = isPinned === "end" && column.getIsFirstColumn("end");
|
|
645
724
|
const bodyCellSpacing = bodyCellSpacingVariants({ size: props.tableLayout?.dense ? "dense" : "default" });
|
|
646
|
-
|
|
725
|
+
const cellSelectionOn = !!props.tableLayout?.cellSelection && table.atoms.cellSelection != null;
|
|
726
|
+
const rangeSelectionOn = cellSelectionOn && props.tableLayout?.cellSelectionMode !== "single";
|
|
727
|
+
const renderTd = (selection) => /* @__PURE__ */ jsxs("td", {
|
|
647
728
|
ref: dndRef,
|
|
729
|
+
id: cellSelectionOn ? `${gridId}c-${toDataGridDomId(row.id)}-${toDataGridDomId(column.id)}` : void 0,
|
|
730
|
+
"aria-colindex": cellSelectionOn ? column.getIndex() + 1 : void 0,
|
|
648
731
|
style: {
|
|
649
732
|
...props.tableLayout?.columnsPinnable && column.getCanPin() && getPinningStyles(column),
|
|
733
|
+
...cellSelectionOn ? { contain: void 0 } : null,
|
|
650
734
|
...props.tableLayout?.columnsResizable && { width: `calc(var(--col-${column.id}-size) * 1px)` },
|
|
651
735
|
...dndStyle ? dndStyle : null
|
|
652
736
|
},
|
|
653
737
|
"data-pinned": isPinned || void 0,
|
|
654
738
|
"data-last-col": isLastStartPinned ? "start" : isFirstEndPinned ? "end" : void 0,
|
|
655
|
-
|
|
656
|
-
|
|
739
|
+
"data-cell-status": props.getCellStatus?.(row.original, column.id),
|
|
740
|
+
"data-column-index": columnIndex,
|
|
741
|
+
...selection ? selection : null,
|
|
742
|
+
onMouseDown: selection ? (event) => {
|
|
743
|
+
if (event.button !== 0) return;
|
|
744
|
+
if (isDataGridCellInteractiveTarget(event.target)) {
|
|
745
|
+
if (rangeSelectionOn && (event.shiftKey || event.metaKey || event.ctrlKey) && cell.getCanSelect()) {
|
|
746
|
+
event.preventDefault();
|
|
747
|
+
cell.getSelectionStartHandler()(event);
|
|
748
|
+
return;
|
|
749
|
+
}
|
|
750
|
+
if (cell.getCanSelect()) {
|
|
751
|
+
if (rangeSelectionOn) cell.getSelectionStartHandler()(event);
|
|
752
|
+
else table.setFocusedCell(row.id, column.id);
|
|
753
|
+
}
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
if (!rangeSelectionOn) {
|
|
757
|
+
if (cell.getCanSelect()) table.setFocusedCell(row.id, column.id);
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
cell.getSelectionStartHandler()(event);
|
|
761
|
+
} : void 0,
|
|
762
|
+
onMouseEnter: rangeSelectionOn ? (event) => cell.getSelectionExtendHandler()(event) : void 0,
|
|
763
|
+
className: cn("align-middle", bodyCellSpacing, props.getCellStatus && "data-cell-status:relative data-cell-status:after:absolute data-cell-status:after:end-0 data-cell-status:after:top-0 data-cell-status:after:size-0 data-cell-status:after:border-s-[5px] data-cell-status:after:border-s-transparent data-[cell-status=dirty]:after:border-t-amber-500 data-[cell-status=invalid]:after:border-t-destructive data-cell-status:after:border-t-[5px] data-cell-status:after:content-['']", props.tableLayout?.cellBorder && "border-e", props.tableLayout?.cellBorder && props.tableLayout?.columnsResizable && (props.tableLayout?.columnsPinnable || !hasDataGridTableRightPinnedColumns(table)) && !isPinned && column.getIsLastColumn("center") && "border-e-0", props.tableLayout?.columnsResizable && column.getCanResize() && !cellSelectionOn && "truncate", cell.column.columnDef.meta?.cellClassName, props.tableLayout?.columnsPinnable && column.getCanPin() && cn("data-pinned:isolate data-pinned:bg-background", "[&[data-pinned=start][data-last-col=start]]:shadow-[inset_-1px_0_0_0_var(--border)]", "[&[data-pinned=end][data-last-col=end]]:shadow-[inset_1px_0_0_0_var(--border)]"), column.getIndex() === 0 || column.getIndex() === row.getVisibleCells().length - 1 ? props.tableClassNames?.edgeCell : "", selection && dataGridCellSelectionCellClasses),
|
|
764
|
+
children: [cellSelectionOn && props.tableLayout?.columnsResizable && column.getCanResize() ? /* @__PURE__ */ jsx("div", {
|
|
765
|
+
className: bodyCellTruncateWrapVariants({ size: props.tableLayout?.dense ? "dense" : "default" }),
|
|
766
|
+
children
|
|
767
|
+
}) : children, props.tableLayout?.cellFillHandle && selection?.["data-cell-edge-bottom"] && selection["data-cell-edge-right"] && /* @__PURE__ */ jsx("span", {
|
|
768
|
+
"data-slot": "data-grid-cell-fill-handle",
|
|
769
|
+
className: cn("absolute z-10 in-data-cell-editing:hidden in-data-cell-selecting:hidden cursor-crosshair", props.tableLayout?.cellFillHandleVariant === "ring" ? "-end-[5px] in-[td:has(+[data-slot=data-grid-table-fill-body-cell]+td[data-pinned])]:end-0 in-[td:has(+[data-slot=data-grid-table-fill-body-cell]:last-child)]:end-0 in-[td:has(+td[data-pinned])]:end-0 in-[td:last-child]:end-0 -bottom-[5px] in-[tr:last-child]:bottom-0 size-[11px] rounded-full border-2 border-primary bg-background" : props.tableLayout?.cellFillHandleVariant === "square" ? "end-0 bottom-0 size-[5px] bg-primary" : "end-0 bottom-0 size-[9px] rounded-full border border-background bg-primary", props.tableClassNames?.cellFillHandle)
|
|
770
|
+
})]
|
|
771
|
+
});
|
|
772
|
+
if (!cellSelectionOn) return renderTd(null);
|
|
773
|
+
return /* @__PURE__ */ jsx(Subscribe, {
|
|
774
|
+
source: table.atoms.cellSelection,
|
|
775
|
+
selector: () => getDataGridCellSelectionCellAttrs(cell),
|
|
776
|
+
children: (selection) => renderTd(selection)
|
|
657
777
|
});
|
|
658
778
|
}
|
|
659
|
-
function DataGridTableRenderedRow({ row, pinnedBoundary, rowRef, rowIndex }) {
|
|
779
|
+
function DataGridTableRenderedRow({ row, pinnedBoundary, rowRef, rowIndex, centerWindow }) {
|
|
660
780
|
const { props, table } = useDataGrid();
|
|
661
781
|
const startVisibleCells = row.getStartVisibleCells();
|
|
662
782
|
const centerVisibleCells = row.getCenterVisibleCells();
|
|
663
783
|
const endVisibleCells = row.getEndVisibleCells();
|
|
664
784
|
const hasRightPinnedColumns = hasDataGridTableRightPinnedColumns(table);
|
|
785
|
+
const windowedCenterCells = centerWindow ? centerVisibleCells.slice(centerWindow.start, centerWindow.end + 1) : centerVisibleCells;
|
|
786
|
+
const leadingSpacerSpan = centerWindow ? centerWindow.start : 0;
|
|
787
|
+
const trailingSpacerSpan = centerWindow ? Math.max(0, centerVisibleCells.length - 1 - centerWindow.end) : 0;
|
|
665
788
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(DataGridTableBodyRow, {
|
|
666
789
|
row,
|
|
667
790
|
pinnedBoundary,
|
|
668
791
|
rowRef,
|
|
669
792
|
dataIndex: rowIndex,
|
|
670
793
|
children: [
|
|
671
|
-
|
|
794
|
+
startVisibleCells.map((cell) => /* @__PURE__ */ jsx(DataGridTableBodyRowCell, {
|
|
672
795
|
cell,
|
|
673
796
|
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
674
797
|
}, cell.id)),
|
|
798
|
+
leadingSpacerSpan > 0 && /* @__PURE__ */ jsx("td", {
|
|
799
|
+
"aria-hidden": "true",
|
|
800
|
+
"data-slot": "data-grid-table-virtual-col-spacer",
|
|
801
|
+
colSpan: leadingSpacerSpan
|
|
802
|
+
}),
|
|
803
|
+
windowedCenterCells.map((cell, cellIndex) => /* @__PURE__ */ jsx(DataGridTableBodyRowCell, {
|
|
804
|
+
cell,
|
|
805
|
+
columnIndex: centerWindow ? centerWindow.start + cellIndex : void 0,
|
|
806
|
+
children: flexRender(cell.column.columnDef.cell, cell.getContext())
|
|
807
|
+
}, cell.id)),
|
|
808
|
+
trailingSpacerSpan > 0 && /* @__PURE__ */ jsx("td", {
|
|
809
|
+
"aria-hidden": "true",
|
|
810
|
+
"data-slot": "data-grid-table-virtual-col-spacer",
|
|
811
|
+
colSpan: trailingSpacerSpan
|
|
812
|
+
}),
|
|
675
813
|
props.tableLayout?.columnsResizable && hasRightPinnedColumns ? /* @__PURE__ */ jsx(DataGridTableFillBodyCell, {}) : null,
|
|
676
814
|
endVisibleCells.map((cell) => /* @__PURE__ */ jsx(DataGridTableBodyRowCell, {
|
|
677
815
|
cell,
|
|
@@ -682,29 +820,30 @@ function DataGridTableRenderedRow({ row, pinnedBoundary, rowRef, rowIndex }) {
|
|
|
682
820
|
}), row.getIsExpanded() && /* @__PURE__ */ jsx(DataGridTableBodyRowExpandded, { row })] });
|
|
683
821
|
}
|
|
684
822
|
function DataGridTableEmpty() {
|
|
685
|
-
const { table, props } = useDataGrid();
|
|
823
|
+
const { i18n, table, props } = useDataGrid();
|
|
686
824
|
const visibleColumnCount = getDataGridTableOrderedVisibleColumns(table).length + (props.tableLayout?.columnsResizable ? 1 : 0);
|
|
687
825
|
return /* @__PURE__ */ jsx("tr", { children: /* @__PURE__ */ jsx("td", {
|
|
688
826
|
colSpan: Math.max(visibleColumnCount, 1),
|
|
689
827
|
className: "py-6 text-center text-muted-foreground text-sm",
|
|
690
|
-
children: props.emptyMessage ||
|
|
828
|
+
children: props.emptyMessage || i18n.labels.empty
|
|
691
829
|
}) });
|
|
692
830
|
}
|
|
693
831
|
function DataGridTableLoader() {
|
|
694
|
-
const { props } = useDataGrid();
|
|
832
|
+
const { i18n, props } = useDataGrid();
|
|
695
833
|
return /* @__PURE__ */ jsx("div", {
|
|
696
834
|
className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2",
|
|
697
835
|
children: /* @__PURE__ */ jsxs("div", {
|
|
698
836
|
className: "flex items-center gap-2 rounded-lg border bg-card px-4 py-2 font-medium text-muted-foreground text-sm leading-none",
|
|
699
|
-
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-5 opacity-60" }), props.loadingMessage ||
|
|
837
|
+
children: [/* @__PURE__ */ jsx(Spinner, { className: "size-5 opacity-60" }), props.loadingMessage || i18n.labels.loading]
|
|
700
838
|
})
|
|
701
839
|
});
|
|
702
840
|
}
|
|
703
841
|
function DataGridTableRowPin({ row }) {
|
|
842
|
+
const { i18n } = useDataGrid();
|
|
704
843
|
const isPinned = row.getIsPinned();
|
|
705
844
|
return /* @__PURE__ */ jsx("button", {
|
|
706
845
|
type: "button",
|
|
707
|
-
"aria-label": isPinned ?
|
|
846
|
+
"aria-label": isPinned ? i18n.labels.unpinRow : i18n.labels.pinRow,
|
|
708
847
|
onClick: (event) => {
|
|
709
848
|
event.stopPropagation();
|
|
710
849
|
if (isPinned) row.pin(false);
|
|
@@ -756,22 +895,23 @@ function DataGridTableRowPin({ row }) {
|
|
|
756
895
|
* has no `Subscribe` attached.
|
|
757
896
|
*/
|
|
758
897
|
function DataGridTableRowSelect({ row }) {
|
|
898
|
+
const { i18n } = useDataGrid();
|
|
759
899
|
return /* @__PURE__ */ jsx(Subscribe, {
|
|
760
900
|
source: row.table.atoms.rowSelection,
|
|
761
|
-
children: () => /* @__PURE__ */
|
|
901
|
+
children: () => /* @__PURE__ */ jsx(Fragment$1, { children: /* @__PURE__ */ jsx(Checkbox, {
|
|
762
902
|
checked: row.getIsSelected(),
|
|
763
903
|
indeterminate: row.getIsSomeSelected() && !row.getIsSelected(),
|
|
764
904
|
onCheckedChange: (value) => row.toggleSelected(!!value),
|
|
765
905
|
onClick: (event) => {
|
|
766
906
|
event.stopPropagation();
|
|
767
907
|
},
|
|
768
|
-
"aria-label":
|
|
908
|
+
"aria-label": i18n.labels.selectRow,
|
|
769
909
|
className: "align-[inherit]"
|
|
770
|
-
})
|
|
910
|
+
}) })
|
|
771
911
|
});
|
|
772
912
|
}
|
|
773
913
|
function DataGridTableRowSelectAll() {
|
|
774
|
-
const { table, recordCount, isLoading } = useDataGrid();
|
|
914
|
+
const { i18n, table, recordCount, isLoading } = useDataGrid();
|
|
775
915
|
return /* @__PURE__ */ jsx(Subscribe, {
|
|
776
916
|
source: table.atoms.rowSelection,
|
|
777
917
|
children: () => {
|
|
@@ -782,14 +922,14 @@ function DataGridTableRowSelectAll() {
|
|
|
782
922
|
indeterminate: isSomeSelected && !isAllSelected,
|
|
783
923
|
disabled: isLoading || recordCount === 0,
|
|
784
924
|
onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
|
|
785
|
-
"aria-label":
|
|
925
|
+
"aria-label": i18n.labels.selectAll,
|
|
786
926
|
className: "align-[inherit]"
|
|
787
927
|
});
|
|
788
928
|
}
|
|
789
929
|
});
|
|
790
930
|
}
|
|
791
931
|
function DataGridTableRowExpand({ row, indent = 20, className, children }) {
|
|
792
|
-
const { props } = useDataGrid();
|
|
932
|
+
const { i18n, props } = useDataGrid();
|
|
793
933
|
const isExpanded = row.getIsExpanded();
|
|
794
934
|
const controlSize = props.tableLayout?.dense ? "size-6" : "size-7";
|
|
795
935
|
return /* @__PURE__ */ jsx("span", {
|
|
@@ -799,7 +939,7 @@ function DataGridTableRowExpand({ row, indent = 20, className, children }) {
|
|
|
799
939
|
children: row.getCanExpand() ? /* @__PURE__ */ jsx("button", {
|
|
800
940
|
type: "button",
|
|
801
941
|
"aria-expanded": isExpanded,
|
|
802
|
-
"aria-label": isExpanded ?
|
|
942
|
+
"aria-label": isExpanded ? i18n.labels.collapseRow : i18n.labels.expandRow,
|
|
803
943
|
onClick: (event) => {
|
|
804
944
|
event.stopPropagation();
|
|
805
945
|
row.toggleExpanded();
|
|
@@ -826,7 +966,7 @@ function DataGridTableRowExpand({ row, indent = 20, className, children }) {
|
|
|
826
966
|
});
|
|
827
967
|
}
|
|
828
968
|
function DataGridTableBodyRows({ table }) {
|
|
829
|
-
const { isLoading, props } = useDataGrid();
|
|
969
|
+
const { i18n, isLoading, props } = useDataGrid();
|
|
830
970
|
const pagination = table.state.pagination;
|
|
831
971
|
if (isLoading && props.loadingMode === "skeleton" && pagination?.pageSize) {
|
|
832
972
|
const leftVisibleColumns = table.getStartVisibleLeafColumns();
|
|
@@ -868,7 +1008,7 @@ function DataGridTableBodyRows({ table }) {
|
|
|
868
1008
|
fill: "currentColor",
|
|
869
1009
|
d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
|
|
870
1010
|
})]
|
|
871
|
-
}), props.loadingMessage ||
|
|
1011
|
+
}), props.loadingMessage || i18n.labels.loading]
|
|
872
1012
|
})
|
|
873
1013
|
}) });
|
|
874
1014
|
const resolvedRows = getDataGridTableResolvedRows(table, props.tableLayout?.rowsPinnable);
|
|
@@ -882,8 +1022,11 @@ function DataGridTableBodyRows({ table }) {
|
|
|
882
1022
|
* Memoized body rows: skip re-renders during active column resize.
|
|
883
1023
|
* Column widths update via CSS variables on the <table> element,
|
|
884
1024
|
* so the browser handles width changes without React re-renders.
|
|
1025
|
+
* A cell-selection drag gets the same treatment: the root re-renders once per
|
|
1026
|
+
* cell crossed, but painting goes through each cell's own Subscribe, so row
|
|
1027
|
+
* reconciliation during the drag is pure waste.
|
|
885
1028
|
*/
|
|
886
|
-
const MemoizedDataGridTableBodyRows = memo(DataGridTableBodyRows, (_prev, next) => !!next.table.state.columnResizing.isResizingColumn);
|
|
1029
|
+
const MemoizedDataGridTableBodyRows = memo(DataGridTableBodyRows, (_prev, next) => !!next.table.state.columnResizing.isResizingColumn || next.table._isSelectingCells === true);
|
|
887
1030
|
function DataGridTableHeader() {
|
|
888
1031
|
const { table, props } = useDataGrid();
|
|
889
1032
|
const mergedHeaderGroups = getDataGridTableMergedHeaderGroups(table);
|
|
@@ -941,11 +1084,15 @@ function DataGridTable({ footerContent, renderHeader = true }) {
|
|
|
941
1084
|
}, headerGroup.id);
|
|
942
1085
|
}) }),
|
|
943
1086
|
renderHeader && (props.tableLayout?.stripped || !props.tableLayout?.rowBorder) && /* @__PURE__ */ jsx(DataGridTableRowSpacer, {}),
|
|
944
|
-
/* @__PURE__ */
|
|
1087
|
+
/* @__PURE__ */ jsxs(DataGridTableBody, { children: [
|
|
1088
|
+
/* @__PURE__ */ jsx(MemoizedDataGridTableBodyRows, { table }),
|
|
1089
|
+
props.appendRow,
|
|
1090
|
+
/* @__PURE__ */ jsx(DataGridTableAddRow, {})
|
|
1091
|
+
] }),
|
|
945
1092
|
footerContent && /* @__PURE__ */ jsx(DataGridTableFoot, { children: footerContent })
|
|
946
1093
|
] }) });
|
|
947
1094
|
}
|
|
948
1095
|
//#endregion
|
|
949
|
-
export { DataGridTable, DataGridTableBase, DataGridTableBody, DataGridTableBodyRow, DataGridTableBodyRowCell, DataGridTableBodyRowExpandded, DataGridTableBodyRowSkeleton, DataGridTableBodyRowSkeletonCell, DataGridTableEmpty, DataGridTableFillBodyCell, DataGridTableFillHeadCell, DataGridTableFoot, DataGridTableFootRow, DataGridTableFootRowCell, DataGridTableHead, DataGridTableHeadRow, DataGridTableHeadRowCell, DataGridTableHeadRowCellResize, DataGridTableHeader, DataGridTableLoader, DataGridTableRenderedRow, DataGridTableRowExpand, DataGridTableRowPin, DataGridTableRowSelect, DataGridTableRowSelectAll, DataGridTableRowSpacer, DataGridTableViewport, getDataGridScrollAreaViewport, getDataGridTableMergedHeaderGroups, getDataGridTableResolvedRows, getDataGridTableRowSections, getDataGridTreeIndentStyle, getPinningStyles, hasDataGridTableRightPinnedColumns };
|
|
1096
|
+
export { DataGridTable, DataGridTableAddRow, DataGridTableBase, DataGridTableBody, DataGridTableBodyRow, DataGridTableBodyRowCell, DataGridTableBodyRowExpandded, DataGridTableBodyRowSkeleton, DataGridTableBodyRowSkeletonCell, DataGridTableEmpty, DataGridTableFillBodyCell, DataGridTableFillHeadCell, DataGridTableFoot, DataGridTableFootRow, DataGridTableFootRowCell, DataGridTableHead, DataGridTableHeadRow, DataGridTableHeadRowCell, DataGridTableHeadRowCellResize, DataGridTableHeader, DataGridTableLoader, DataGridTableRenderedRow, DataGridTableRowExpand, DataGridTableRowPin, DataGridTableRowSelect, DataGridTableRowSelectAll, DataGridTableRowSpacer, DataGridTableViewport, getDataGridScrollAreaViewport, getDataGridTableMergedHeaderGroups, getDataGridTableResolvedRows, getDataGridTableRowSections, getDataGridTreeIndentStyle, getPinningStyles, hasDataGridTableRightPinnedColumns };
|
|
950
1097
|
|
|
951
1098
|
//# sourceMappingURL=data-grid-table.js.map
|