m9-react-data-grid 7.0.0-beta.7.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/lib/bundle.js ADDED
@@ -0,0 +1,2624 @@
1
+ import { useEffect, useLayoutEffect as useLayoutEffect$1, useRef, useContext, createContext, useMemo, useCallback, useState, memo, forwardRef, useImperativeHandle } from 'react';
2
+ import clsx from 'clsx';
3
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
4
+
5
+ function styleInject(css, ref) {
6
+ if ( ref === void 0 ) ref = {};
7
+ var insertAt = ref.insertAt;
8
+
9
+ if (!css || typeof document === 'undefined') { return; }
10
+
11
+ var head = document.head || document.getElementsByTagName('head')[0];
12
+ var style = document.createElement('style');
13
+ style.type = 'text/css';
14
+
15
+ if (insertAt === 'top') {
16
+ if (head.firstChild) {
17
+ head.insertBefore(style, head.firstChild);
18
+ } else {
19
+ head.appendChild(style);
20
+ }
21
+ } else {
22
+ head.appendChild(style);
23
+ }
24
+
25
+ if (style.styleSheet) {
26
+ style.styleSheet.cssText = css;
27
+ } else {
28
+ style.appendChild(document.createTextNode(css));
29
+ }
30
+ }
31
+
32
+ var css_248z$e = ".cj343x0700-beta711{background-color:inherit;border-bottom:1px solid var(--border-color);border-right:1px solid var(--border-color);contain:strict;contain:size layout style paint;outline:none;overflow:hidden;overflow:clip;padding:0 8px;text-overflow:ellipsis;white-space:nowrap}.cj343x0700-beta711[aria-selected=true]{box-shadow:inset 0 0 0 2px var(--selection-color)}.csofj7r700-beta711{position:sticky;z-index:1}.ch2wcw8700-beta711{box-shadow:2px 0 5px -2px hsla(0,0%,53%,.3)}";
33
+ styleInject(css_248z$e,{"insertAt":"top"});
34
+
35
+ const cell = "cj343x0700-beta711";
36
+ const cellClassname = `rdg-cell ${cell}`;
37
+ const cellFrozen = "csofj7r700-beta711";
38
+ const cellFrozenClassname = `rdg-cell-frozen ${cellFrozen}`;
39
+ const cellFrozenLast = "ch2wcw8700-beta711";
40
+ const cellFrozenLastClassname = `rdg-cell-frozen-last ${cellFrozenLast}`;
41
+
42
+ var css_248z$d = ".rnvodz5700-beta711{--color:#000;--border-color:#ddd;--summary-border-color:#aaa;--background-color:#fff;--header-background-color:#f9f9f9;--row-hover-background-color:#f5f5f5;--row-selected-background-color:#dbecfa;--row-selected-hover-background-color:#c9e3f8;--checkbox-color:#005194;--checkbox-focus-color:#61b8ff;--checkbox-disabled-border-color:#ccc;--checkbox-disabled-background-color:#ddd;--selection-color:#66afe9;--font-size:14px;background-color:var(--background-color);border:1px solid var(--border-color);box-sizing:border-box;color:var(--color);color-scheme:var(--color-scheme,light dark);contain:strict;contain:size layout style paint;content-visibility:auto;direction:ltr;font-size:var(--font-size);height:350px;overflow:auto;user-select:none}@supports not (contain:strict){.rnvodz5700-beta711{position:relative;z-index:0}}.rnvodz5700-beta711 *,.rnvodz5700-beta711 :after,.rnvodz5700-beta711 :before{box-sizing:inherit}.rnvodz5700-beta711.rdg-dark{--color-scheme:dark;--color:#ddd;--border-color:#444;--summary-border-color:#555;--background-color:#212121;--header-background-color:#1b1b1b;--row-hover-background-color:#171717;--row-selected-background-color:#1a73bc;--row-selected-hover-background-color:#1768ab;--checkbox-color:#94cfff;--checkbox-focus-color:#c7e6ff;--checkbox-disabled-border-color:#000;--checkbox-disabled-background-color:#333}.rnvodz5700-beta711.rdg-light{--color-scheme:light}@media (prefers-color-scheme:dark){.rnvodz5700-beta711:not(.rdg-light){--color:#ddd;--border-color:#444;--summary-border-color:#555;--background-color:#212121;--header-background-color:#1b1b1b;--row-hover-background-color:#171717;--row-selected-background-color:#1a73bc;--row-selected-hover-background-color:#1768ab;--checkbox-color:#94cfff;--checkbox-focus-color:#c7e6ff;--checkbox-disabled-border-color:#000;--checkbox-disabled-background-color:#333}}.vlqv91k700-beta711.r1upfr80700-beta711{cursor:move}";
43
+ styleInject(css_248z$d,{"insertAt":"top"});
44
+
45
+ const root = "rnvodz5700-beta711";
46
+ const rootClassname = `rdg ${root}`;
47
+ const viewportDragging = "vlqv91k700-beta711";
48
+ const viewportDraggingClassname = `rdg-viewport-dragging ${viewportDragging}`;
49
+
50
+ var css_248z$c = ".r1upfr80700-beta711{background-color:var(--background-color);contain:strict;contain:size layout style paint;display:grid;grid-template-columns:var(--template-columns);grid-template-rows:var(--row-height);height:var(--row-height);left:0;line-height:var(--row-height);position:absolute;width:var(--row-width)}.r1upfr80700-beta711:hover{background-color:var(--row-hover-background-color)}.r1upfr80700-beta711[aria-selected=true]{background-color:var(--row-selected-background-color)}.r1upfr80700-beta711[aria-selected=true]:hover{background-color:var(--row-selected-hover-background-color)}";
51
+ styleInject(css_248z$c,{"insertAt":"top"});
52
+
53
+ const row = "r1upfr80700-beta711";
54
+ const rowClassname = `rdg-row ${row}`;
55
+
56
+ const useLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect$1;
57
+
58
+ function useFocusRef(isSelected) {
59
+ const ref = useRef(null);
60
+ useLayoutEffect(() => {
61
+ if (!isSelected) return;
62
+ ref.current?.focus({
63
+ preventScroll: true
64
+ });
65
+ }, [isSelected]);
66
+ return {
67
+ ref,
68
+ tabIndex: isSelected ? 0 : -1
69
+ };
70
+ }
71
+
72
+ var css_248z$b = ".c4l3n6v700-beta711{align-items:center;cursor:pointer;display:flex;inset:0;justify-content:center;margin-right:1px;position:absolute}.c1bikpmb700-beta711{all:unset;margin:0;width:0}.c1eyot7g700-beta711{background-color:var(--background-color);border:2px solid var(--border-color);content:\"\";height:20px;width:20px}.c1bikpmb700-beta711:checked+.c1eyot7g700-beta711{background-color:var(--checkbox-color);box-shadow:inset 0 0 0 4px var(--background-color)}.c1bikpmb700-beta711:focus+.c1eyot7g700-beta711{border-color:var(--checkbox-focus-color)}.c1jlcvp4700-beta711{cursor:default}.c1jlcvp4700-beta711 .c1eyot7g700-beta711{background-color:var(--checkbox-disabled-background-color);border-color:var(--checkbox-disabled-border-color)}";
73
+ styleInject(css_248z$b,{"insertAt":"top"});
74
+
75
+ const checkboxLabel = "c4l3n6v700-beta711";
76
+ const checkboxLabelClassname = `rdg-checkbox-label ${checkboxLabel}`;
77
+ const checkboxInput = "c1bikpmb700-beta711";
78
+ const checkboxInputClassname = `rdg-checkbox-input ${checkboxInput}`;
79
+ const checkbox = "c1eyot7g700-beta711";
80
+ const checkboxClassname = `rdg-checkbox ${checkbox}`;
81
+ const checkboxLabelDisabled = "c1jlcvp4700-beta711";
82
+ const checkboxLabelDisabledClassname = `rdg-checkbox-label-disabled ${checkboxLabelDisabled}`;
83
+ function SelectCellFormatter({
84
+ value,
85
+ isCellSelected,
86
+ disabled,
87
+ onClick,
88
+ onChange,
89
+ 'aria-label': ariaLabel,
90
+ 'aria-labelledby': ariaLabelledBy
91
+ }) {
92
+ const {
93
+ ref,
94
+ tabIndex
95
+ } = useFocusRef(isCellSelected);
96
+ function handleChange(e) {
97
+ onChange(e.target.checked, e.nativeEvent.shiftKey);
98
+ }
99
+ return /*#__PURE__*/jsxs("label", {
100
+ className: clsx(checkboxLabelClassname, disabled && checkboxLabelDisabledClassname),
101
+ children: [/*#__PURE__*/jsx("input", {
102
+ "aria-label": ariaLabel,
103
+ "aria-labelledby": ariaLabelledBy,
104
+ ref: ref,
105
+ type: "checkbox",
106
+ tabIndex: tabIndex,
107
+ className: checkboxInputClassname,
108
+ disabled: disabled,
109
+ checked: value,
110
+ onChange: handleChange,
111
+ onClick: onClick
112
+ }), /*#__PURE__*/jsx("div", {
113
+ className: checkboxClassname
114
+ })]
115
+ });
116
+ }
117
+
118
+ function ValueFormatter(props) {
119
+ try {
120
+ return /*#__PURE__*/jsx(Fragment, {
121
+ children: props.row[props.column.key]
122
+ });
123
+ } catch {
124
+ return null;
125
+ }
126
+ }
127
+
128
+ var css_248z$a = ".g1vzro7t700-beta711{outline:none}.c1fsqdic700-beta711{stroke:currentColor;stroke-width:1.5px;fill:transparent;margin-left:4px;vertical-align:middle}.c1fsqdic700-beta711>path{transition:d .1s}";
129
+ styleInject(css_248z$a,{"insertAt":"top"});
130
+
131
+ const groupCellContent = "g1vzro7t700-beta711";
132
+ const groupCellContentClassname = `rdg-group-cell-content ${groupCellContent}`;
133
+ const caret = "c1fsqdic700-beta711";
134
+ const caretClassname = `rdg-caret ${caret}`;
135
+ function ToggleGroupFormatter({
136
+ groupKey,
137
+ isExpanded,
138
+ isCellSelected,
139
+ toggleGroup
140
+ }) {
141
+ const {
142
+ ref,
143
+ tabIndex
144
+ } = useFocusRef(isCellSelected);
145
+ function handleKeyDown({
146
+ key
147
+ }) {
148
+ if (key === 'Enter') {
149
+ toggleGroup();
150
+ }
151
+ }
152
+ const d = isExpanded ? 'M1 1 L 7 7 L 13 1' : 'M1 7 L 7 1 L 13 7';
153
+ return /*#__PURE__*/jsxs("span", {
154
+ ref: ref,
155
+ className: groupCellContentClassname,
156
+ tabIndex: tabIndex,
157
+ onKeyDown: handleKeyDown,
158
+ children: [groupKey, /*#__PURE__*/jsx("svg", {
159
+ viewBox: "0 0 14 8",
160
+ width: "14",
161
+ height: "8",
162
+ className: caretClassname,
163
+ "aria-hidden": true,
164
+ children: /*#__PURE__*/jsx("path", {
165
+ d: d
166
+ })
167
+ })]
168
+ });
169
+ }
170
+
171
+ const RowSelectionContext = /*#__PURE__*/createContext(undefined);
172
+ const RowSelectionProvider = RowSelectionContext.Provider;
173
+ const RowSelectionChangeContext = /*#__PURE__*/createContext(undefined);
174
+ const RowSelectionChangeProvider = RowSelectionChangeContext.Provider;
175
+ function useRowSelection() {
176
+ const rowSelectionContext = useContext(RowSelectionContext);
177
+ const rowSelectionChangeContext = useContext(RowSelectionChangeContext);
178
+ if (rowSelectionContext === undefined || rowSelectionChangeContext === undefined) {
179
+ throw new Error('useRowSelection must be used within DataGrid cells');
180
+ }
181
+ return [rowSelectionContext, rowSelectionChangeContext];
182
+ }
183
+
184
+ function getColSpan(column, lastFrozenColumnIndex, args) {
185
+ const colSpan = typeof column.colSpan === 'function' ? column.colSpan(args) : 1;
186
+ if (Number.isInteger(colSpan) && colSpan > 1 && (!column.frozen || column.idx + colSpan - 1 <= lastFrozenColumnIndex)) {
187
+ return colSpan;
188
+ }
189
+ return undefined;
190
+ }
191
+
192
+ function stopPropagation(event) {
193
+ event.stopPropagation();
194
+ }
195
+
196
+ const nonInputKeys = new Set(['Unidentified', 'Alt', 'AltGraph', 'CapsLock', 'Control', 'Fn', 'FnLock', 'Meta', 'NumLock', 'ScrollLock', 'Shift', 'Tab', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'End', 'Home', 'PageDown', 'PageUp', 'Insert', 'ContextMenu', 'Escape', 'Pause', 'Play', 'PrintScreen', 'F1', 'F3', 'F4', 'F5', 'F6', 'F7', 'F8', 'F9', 'F10', 'F11', 'F12']);
197
+ function isCtrlKeyHeldDown(e) {
198
+ return (e.ctrlKey || e.metaKey) && e.key !== 'Control';
199
+ }
200
+ function isDefaultCellInput(event) {
201
+ return !nonInputKeys.has(event.key);
202
+ }
203
+ function onEditorNavigation({
204
+ key,
205
+ target
206
+ }) {
207
+ if (key === 'Tab' && (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target instanceof HTMLSelectElement)) {
208
+ return target.matches('.rdg-editor-container > :only-child, .rdg-editor-container > label:only-child > :only-child');
209
+ }
210
+ return false;
211
+ }
212
+
213
+ function isSelectedCellEditable({
214
+ selectedPosition,
215
+ columns,
216
+ rows,
217
+ isGroupRow
218
+ }) {
219
+ const column = columns[selectedPosition.idx];
220
+ const row = rows[selectedPosition.rowIdx];
221
+ return !isGroupRow(row) && isCellEditable(column, row);
222
+ }
223
+ function isCellEditable(column, row) {
224
+ return column.editor != null && !column.rowGroup && (typeof column.editable === 'function' ? column.editable(row) : column.editable) !== false;
225
+ }
226
+ function getSelectedCellColSpan({
227
+ rows,
228
+ summaryRows,
229
+ rowIdx,
230
+ lastFrozenColumnIndex,
231
+ column,
232
+ isGroupRow
233
+ }) {
234
+ if (rowIdx === -1) {
235
+ return getColSpan(column, lastFrozenColumnIndex, {
236
+ type: 'HEADER'
237
+ });
238
+ }
239
+ if (rowIdx >= 0 && rowIdx < rows.length) {
240
+ const row = rows[rowIdx];
241
+ if (!isGroupRow(row)) {
242
+ return getColSpan(column, lastFrozenColumnIndex, {
243
+ type: 'ROW',
244
+ row
245
+ });
246
+ }
247
+ return undefined;
248
+ }
249
+ if (summaryRows) {
250
+ return getColSpan(column, lastFrozenColumnIndex, {
251
+ type: 'SUMMARY',
252
+ row: summaryRows[rowIdx - rows.length]
253
+ });
254
+ }
255
+ return undefined;
256
+ }
257
+ function getNextSelectedCellPosition({
258
+ cellNavigationMode,
259
+ columns,
260
+ colSpanColumns,
261
+ rows,
262
+ summaryRows,
263
+ minRowIdx,
264
+ maxRowIdx,
265
+ currentPosition: {
266
+ idx: currentIdx
267
+ },
268
+ nextPosition,
269
+ lastFrozenColumnIndex,
270
+ isCellWithinBounds,
271
+ isGroupRow
272
+ }) {
273
+ let {
274
+ idx: nextIdx,
275
+ rowIdx: nextRowIdx
276
+ } = nextPosition;
277
+ const setColSpan = moveRight => {
278
+ if (nextRowIdx >= 0 && nextRowIdx < rows.length) {
279
+ const row = rows[nextRowIdx];
280
+ if (isGroupRow(row)) return;
281
+ }
282
+ for (const column of colSpanColumns) {
283
+ const colIdx = column.idx;
284
+ if (colIdx > nextIdx) break;
285
+ const colSpan = getSelectedCellColSpan({
286
+ rows,
287
+ summaryRows,
288
+ rowIdx: nextRowIdx,
289
+ lastFrozenColumnIndex,
290
+ column,
291
+ isGroupRow
292
+ });
293
+ if (colSpan && nextIdx > colIdx && nextIdx < colSpan + colIdx) {
294
+ nextIdx = colIdx + (moveRight ? colSpan : 0);
295
+ break;
296
+ }
297
+ }
298
+ };
299
+ if (isCellWithinBounds(nextPosition)) {
300
+ setColSpan(nextIdx - currentIdx > 0);
301
+ }
302
+ if (cellNavigationMode !== 'NONE') {
303
+ const columnsCount = columns.length;
304
+ const isAfterLastColumn = nextIdx === columnsCount;
305
+ const isBeforeFirstColumn = nextIdx === -1;
306
+ if (isAfterLastColumn) {
307
+ if (cellNavigationMode === 'CHANGE_ROW') {
308
+ const isLastRow = nextRowIdx === maxRowIdx;
309
+ if (!isLastRow) {
310
+ nextIdx = 0;
311
+ nextRowIdx += 1;
312
+ }
313
+ } else {
314
+ nextIdx = 0;
315
+ }
316
+ } else if (isBeforeFirstColumn) {
317
+ if (cellNavigationMode === 'CHANGE_ROW') {
318
+ const isFirstRow = nextRowIdx === minRowIdx;
319
+ if (!isFirstRow) {
320
+ nextRowIdx -= 1;
321
+ nextIdx = columnsCount - 1;
322
+ }
323
+ } else {
324
+ nextIdx = columnsCount - 1;
325
+ }
326
+ setColSpan(false);
327
+ }
328
+ }
329
+ return {
330
+ idx: nextIdx,
331
+ rowIdx: nextRowIdx
332
+ };
333
+ }
334
+ function canExitGrid({
335
+ cellNavigationMode,
336
+ maxColIdx,
337
+ minRowIdx,
338
+ maxRowIdx,
339
+ selectedPosition: {
340
+ rowIdx,
341
+ idx
342
+ },
343
+ shiftKey
344
+ }) {
345
+ if (cellNavigationMode === 'NONE' || cellNavigationMode === 'CHANGE_ROW') {
346
+ const atLastCellInRow = idx === maxColIdx;
347
+ const atFirstCellInRow = idx === 0;
348
+ const atLastRow = rowIdx === maxRowIdx;
349
+ const atFirstRow = rowIdx === minRowIdx;
350
+ return shiftKey ? atFirstCellInRow && atFirstRow : atLastCellInRow && atLastRow;
351
+ }
352
+ return false;
353
+ }
354
+
355
+ const {
356
+ min,
357
+ max,
358
+ floor,
359
+ sign
360
+ } = Math;
361
+ function assertIsValidKeyGetter(keyGetter) {
362
+ if (typeof keyGetter !== 'function') {
363
+ throw new Error('Please specify the rowKeyGetter prop to use selection');
364
+ }
365
+ }
366
+ function getCellStyle(column, colSpan) {
367
+ return {
368
+ gridColumnStart: column.idx + 1,
369
+ gridColumnEnd: colSpan !== undefined ? `span ${colSpan}` : undefined,
370
+ left: column.frozen ? `var(--frozen-left-${column.idx})` : undefined
371
+ };
372
+ }
373
+ function getCellClassname(column, ...extraClasses) {
374
+ return clsx(cellClassname, ...extraClasses, column.frozen && cellFrozenClassname, column.isLastFrozenColumn && cellFrozenLastClassname);
375
+ }
376
+
377
+ const SELECT_COLUMN_KEY = 'select-row';
378
+ function SelectFormatter(props) {
379
+ const [isRowSelected, onRowSelectionChange] = useRowSelection();
380
+ return /*#__PURE__*/jsx(SelectCellFormatter, {
381
+ "aria-label": "Select",
382
+ isCellSelected: props.isCellSelected,
383
+ value: isRowSelected,
384
+ onClick: stopPropagation,
385
+ onChange: (checked, isShiftClick) => {
386
+ onRowSelectionChange({
387
+ row: props.row,
388
+ checked,
389
+ isShiftClick
390
+ });
391
+ }
392
+ });
393
+ }
394
+ function SelectGroupFormatter(props) {
395
+ const [isRowSelected, onRowSelectionChange] = useRowSelection();
396
+ return /*#__PURE__*/jsx(SelectCellFormatter, {
397
+ "aria-label": "Select Group",
398
+ isCellSelected: props.isCellSelected,
399
+ value: isRowSelected,
400
+ onChange: checked => {
401
+ onRowSelectionChange({
402
+ row: props.row,
403
+ checked,
404
+ isShiftClick: false
405
+ });
406
+ },
407
+ onClick: stopPropagation
408
+ });
409
+ }
410
+ const SelectColumn = {
411
+ key: SELECT_COLUMN_KEY,
412
+ name: '',
413
+ width: 35,
414
+ maxWidth: 35,
415
+ resizable: false,
416
+ sortable: false,
417
+ frozen: true,
418
+ headerRenderer(props) {
419
+ return /*#__PURE__*/jsx(SelectCellFormatter, {
420
+ "aria-label": "Select All",
421
+ isCellSelected: props.isCellSelected,
422
+ value: props.allRowsSelected,
423
+ onChange: props.onAllRowsSelectionChange,
424
+ onClick: stopPropagation
425
+ });
426
+ },
427
+ formatter: SelectFormatter,
428
+ groupFormatter: SelectGroupFormatter
429
+ };
430
+
431
+ function useCalculatedColumns({
432
+ rawColumns,
433
+ columnWidths,
434
+ viewportWidth,
435
+ scrollLeft,
436
+ defaultColumnOptions,
437
+ rawGroupBy,
438
+ enableVirtualization
439
+ }) {
440
+ const minColumnWidth = defaultColumnOptions?.minWidth ?? 80;
441
+ const defaultFormatter = defaultColumnOptions?.formatter ?? ValueFormatter;
442
+ const defaultSortable = defaultColumnOptions?.sortable ?? false;
443
+ const defaultResizable = defaultColumnOptions?.resizable ?? false;
444
+ const {
445
+ columns,
446
+ colSpanColumns,
447
+ lastFrozenColumnIndex,
448
+ groupBy
449
+ } = useMemo(() => {
450
+ const groupBy = [];
451
+ let lastFrozenColumnIndex = -1;
452
+ const columns = rawColumns.map(rawColumn => {
453
+ const rowGroup = rawGroupBy?.includes(rawColumn.key) ?? false;
454
+ const frozen = rowGroup || rawColumn.frozen || false;
455
+ const column = {
456
+ ...rawColumn,
457
+ idx: 0,
458
+ frozen,
459
+ isLastFrozenColumn: false,
460
+ rowGroup,
461
+ sortable: rawColumn.sortable ?? defaultSortable,
462
+ resizable: rawColumn.resizable ?? defaultResizable,
463
+ formatter: rawColumn.formatter ?? defaultFormatter
464
+ };
465
+ if (rowGroup) {
466
+ column.groupFormatter ??= ToggleGroupFormatter;
467
+ }
468
+ if (frozen) {
469
+ lastFrozenColumnIndex++;
470
+ }
471
+ return column;
472
+ });
473
+ columns.sort(({
474
+ key: aKey,
475
+ frozen: frozenA
476
+ }, {
477
+ key: bKey,
478
+ frozen: frozenB
479
+ }) => {
480
+ if (aKey === SELECT_COLUMN_KEY) return -1;
481
+ if (bKey === SELECT_COLUMN_KEY) return 1;
482
+ if (rawGroupBy?.includes(aKey)) {
483
+ if (rawGroupBy.includes(bKey)) {
484
+ return rawGroupBy.indexOf(aKey) - rawGroupBy.indexOf(bKey);
485
+ }
486
+ return -1;
487
+ }
488
+ if (rawGroupBy?.includes(bKey)) return 1;
489
+ if (frozenA) {
490
+ if (frozenB) return 0;
491
+ return -1;
492
+ }
493
+ if (frozenB) return 1;
494
+ return 0;
495
+ });
496
+ const colSpanColumns = [];
497
+ columns.forEach((column, idx) => {
498
+ column.idx = idx;
499
+ if (column.rowGroup) {
500
+ groupBy.push(column.key);
501
+ }
502
+ if (column.colSpan != null) {
503
+ colSpanColumns.push(column);
504
+ }
505
+ });
506
+ if (lastFrozenColumnIndex !== -1) {
507
+ columns[lastFrozenColumnIndex].isLastFrozenColumn = true;
508
+ }
509
+ return {
510
+ columns,
511
+ colSpanColumns,
512
+ lastFrozenColumnIndex,
513
+ groupBy
514
+ };
515
+ }, [rawColumns, defaultFormatter, defaultResizable, defaultSortable, rawGroupBy]);
516
+ const {
517
+ layoutCssVars,
518
+ totalColumnWidth,
519
+ totalFrozenColumnWidth,
520
+ columnMetrics
521
+ } = useMemo(() => {
522
+ const columnMetrics = new Map();
523
+ let left = 0;
524
+ let totalColumnWidth = 0;
525
+ let totalFrozenColumnWidth = 0;
526
+ let templateColumns = '';
527
+ let allocatedWidth = 0;
528
+ let unassignedColumnsCount = 0;
529
+ for (const column of columns) {
530
+ let width = getSpecifiedWidth(column, columnWidths, viewportWidth);
531
+ if (width === undefined) {
532
+ unassignedColumnsCount++;
533
+ } else {
534
+ width = clampColumnWidth(width, column, minColumnWidth);
535
+ allocatedWidth += width;
536
+ columnMetrics.set(column, {
537
+ width,
538
+ left: 0
539
+ });
540
+ }
541
+ }
542
+ const unallocatedWidth = viewportWidth - allocatedWidth;
543
+ const unallocatedColumnWidth = unallocatedWidth / unassignedColumnsCount;
544
+ for (const column of columns) {
545
+ let width;
546
+ if (columnMetrics.has(column)) {
547
+ const columnMetric = columnMetrics.get(column);
548
+ columnMetric.left = left;
549
+ ({
550
+ width
551
+ } = columnMetric);
552
+ } else {
553
+ width = clampColumnWidth(unallocatedColumnWidth, column, minColumnWidth);
554
+ columnMetrics.set(column, {
555
+ width,
556
+ left
557
+ });
558
+ }
559
+ totalColumnWidth += width;
560
+ left += width;
561
+ templateColumns += `${width}px `;
562
+ }
563
+ if (lastFrozenColumnIndex !== -1) {
564
+ const columnMetric = columnMetrics.get(columns[lastFrozenColumnIndex]);
565
+ totalFrozenColumnWidth = columnMetric.left + columnMetric.width;
566
+ }
567
+ const layoutCssVars = {
568
+ '--template-columns': templateColumns
569
+ };
570
+ for (let i = 0; i <= lastFrozenColumnIndex; i++) {
571
+ const column = columns[i];
572
+ layoutCssVars[`--frozen-left-${column.idx}`] = `${columnMetrics.get(column).left}px`;
573
+ }
574
+ return {
575
+ layoutCssVars,
576
+ totalColumnWidth,
577
+ totalFrozenColumnWidth,
578
+ columnMetrics
579
+ };
580
+ }, [columnWidths, columns, viewportWidth, minColumnWidth, lastFrozenColumnIndex]);
581
+ const [colOverscanStartIdx, colOverscanEndIdx] = useMemo(() => {
582
+ if (!enableVirtualization) {
583
+ return [0, columns.length - 1];
584
+ }
585
+ const viewportLeft = scrollLeft + totalFrozenColumnWidth;
586
+ const viewportRight = scrollLeft + viewportWidth;
587
+ const lastColIdx = columns.length - 1;
588
+ const firstUnfrozenColumnIdx = min(lastFrozenColumnIndex + 1, lastColIdx);
589
+ if (viewportLeft >= viewportRight) {
590
+ return [firstUnfrozenColumnIdx, firstUnfrozenColumnIdx];
591
+ }
592
+ let colVisibleStartIdx = firstUnfrozenColumnIdx;
593
+ while (colVisibleStartIdx < lastColIdx) {
594
+ const {
595
+ left,
596
+ width
597
+ } = columnMetrics.get(columns[colVisibleStartIdx]);
598
+ if (left + width > viewportLeft) {
599
+ break;
600
+ }
601
+ colVisibleStartIdx++;
602
+ }
603
+ let colVisibleEndIdx = colVisibleStartIdx;
604
+ while (colVisibleEndIdx < lastColIdx) {
605
+ const {
606
+ left,
607
+ width
608
+ } = columnMetrics.get(columns[colVisibleEndIdx]);
609
+ if (left + width >= viewportRight) {
610
+ break;
611
+ }
612
+ colVisibleEndIdx++;
613
+ }
614
+ const colOverscanStartIdx = max(firstUnfrozenColumnIdx, colVisibleStartIdx - 1);
615
+ const colOverscanEndIdx = min(lastColIdx, colVisibleEndIdx + 1);
616
+ return [colOverscanStartIdx, colOverscanEndIdx];
617
+ }, [columnMetrics, columns, lastFrozenColumnIndex, scrollLeft, totalFrozenColumnWidth, viewportWidth, enableVirtualization]);
618
+ return {
619
+ columns,
620
+ colSpanColumns,
621
+ colOverscanStartIdx,
622
+ colOverscanEndIdx,
623
+ layoutCssVars,
624
+ columnMetrics,
625
+ totalColumnWidth,
626
+ lastFrozenColumnIndex,
627
+ totalFrozenColumnWidth,
628
+ groupBy
629
+ };
630
+ }
631
+ function getSpecifiedWidth({
632
+ key,
633
+ width
634
+ }, columnWidths, viewportWidth) {
635
+ if (columnWidths.has(key)) {
636
+ return columnWidths.get(key);
637
+ }
638
+ if (typeof width === 'number') {
639
+ return width;
640
+ }
641
+ if (typeof width === 'string' && /^\d+%$/.test(width)) {
642
+ return floor(viewportWidth * parseInt(width, 10) / 100);
643
+ }
644
+ return undefined;
645
+ }
646
+ function clampColumnWidth(width, {
647
+ minWidth,
648
+ maxWidth
649
+ }, minColumnWidth) {
650
+ width = max(width, minWidth ?? minColumnWidth);
651
+ if (typeof maxWidth === 'number') {
652
+ return min(width, maxWidth);
653
+ }
654
+ return width;
655
+ }
656
+
657
+ function useCombinedRefs(...refs) {
658
+ return useCallback(handle => {
659
+ for (const ref of refs) {
660
+ if (typeof ref === 'function') {
661
+ ref(handle);
662
+ } else if (ref !== null && 'current' in ref) {
663
+ ref.current = handle;
664
+ }
665
+ }
666
+ }, refs);
667
+ }
668
+
669
+ function useGridDimensions() {
670
+ const gridRef = useRef(null);
671
+ const [gridWidth, setGridWidth] = useState(1);
672
+ const [gridHeight, setGridHeight] = useState(1);
673
+ useLayoutEffect(() => {
674
+ const {
675
+ ResizeObserver
676
+ } = window;
677
+ if (ResizeObserver == null) return;
678
+ const resizeObserver = new ResizeObserver(() => {
679
+ const {
680
+ clientWidth,
681
+ clientHeight
682
+ } = gridRef.current;
683
+ setGridWidth(clientWidth - (devicePixelRatio % 1 === 0 ? 0 : 1));
684
+ setGridHeight(clientHeight);
685
+ });
686
+ resizeObserver.observe(gridRef.current);
687
+ return () => {
688
+ resizeObserver.disconnect();
689
+ };
690
+ }, []);
691
+ return [gridRef, gridWidth, gridHeight];
692
+ }
693
+
694
+ function useLatestFunc(fn) {
695
+ const ref = useRef(fn);
696
+ useEffect(() => {
697
+ ref.current = fn;
698
+ });
699
+ return useCallback((...args) => {
700
+ ref.current(...args);
701
+ }, []);
702
+ }
703
+
704
+ function useRovingCellRef(isSelected) {
705
+ const ref = useRef(null);
706
+ const isChildFocused = useRef(false);
707
+ const [, forceRender] = useState({});
708
+ useLayoutEffect(() => {
709
+ if (!isSelected) {
710
+ isChildFocused.current = false;
711
+ return;
712
+ }
713
+ if (isChildFocused.current) {
714
+ forceRender({});
715
+ return;
716
+ }
717
+ ref.current?.focus();
718
+ }, [isSelected]);
719
+ function onFocus(event) {
720
+ if (event.target !== ref.current) {
721
+ isChildFocused.current = true;
722
+ }
723
+ }
724
+ const isFocused = isSelected && !isChildFocused.current;
725
+ return {
726
+ ref,
727
+ tabIndex: isFocused ? 0 : -1,
728
+ onFocus
729
+ };
730
+ }
731
+
732
+ var css_248z$9 = ".r1v67ork700-beta711{outline:none}.r1v67ork700-beta711:after{box-shadow:inset 0 0 0 2px var(--selection-color);content:\"\";inset:0;pointer-events:none;position:absolute;z-index:2}.r1v67ork700-beta711>.cj343x0700-beta711:first-child{box-shadow:inset 2px 0 0 0 var(--selection-color)}";
733
+ styleInject(css_248z$9,{"insertAt":"top"});
734
+
735
+ const rowSelected = "r1v67ork700-beta711";
736
+ const rowSelectedClassname = `rdg-row-selected ${rowSelected}`;
737
+ function useRovingRowRef(selectedCellIdx) {
738
+ const isSelected = selectedCellIdx === -1;
739
+ const {
740
+ ref,
741
+ tabIndex
742
+ } = useFocusRef(isSelected);
743
+ return {
744
+ ref,
745
+ tabIndex,
746
+ className: isSelected ? rowSelectedClassname : undefined
747
+ };
748
+ }
749
+
750
+ function useViewportColumns({
751
+ columns,
752
+ colSpanColumns,
753
+ rows,
754
+ summaryRows,
755
+ colOverscanStartIdx,
756
+ colOverscanEndIdx,
757
+ lastFrozenColumnIndex,
758
+ rowOverscanStartIdx,
759
+ rowOverscanEndIdx,
760
+ isGroupRow
761
+ }) {
762
+ const startIdx = useMemo(() => {
763
+ if (colOverscanStartIdx === 0) return 0;
764
+ let startIdx = colOverscanStartIdx;
765
+ const updateStartIdx = (colIdx, colSpan) => {
766
+ if (colSpan !== undefined && colIdx + colSpan > colOverscanStartIdx) {
767
+ startIdx = colIdx;
768
+ return true;
769
+ }
770
+ return false;
771
+ };
772
+ for (const column of colSpanColumns) {
773
+ const colIdx = column.idx;
774
+ if (colIdx >= startIdx) break;
775
+ if (updateStartIdx(colIdx, getColSpan(column, lastFrozenColumnIndex, {
776
+ type: 'HEADER'
777
+ }))) {
778
+ break;
779
+ }
780
+ for (let rowIdx = rowOverscanStartIdx; rowIdx <= rowOverscanEndIdx; rowIdx++) {
781
+ const row = rows[rowIdx];
782
+ if (isGroupRow(row)) continue;
783
+ if (updateStartIdx(colIdx, getColSpan(column, lastFrozenColumnIndex, {
784
+ type: 'ROW',
785
+ row
786
+ }))) {
787
+ break;
788
+ }
789
+ }
790
+ if (summaryRows != null) {
791
+ for (const row of summaryRows) {
792
+ if (updateStartIdx(colIdx, getColSpan(column, lastFrozenColumnIndex, {
793
+ type: 'SUMMARY',
794
+ row
795
+ }))) {
796
+ break;
797
+ }
798
+ }
799
+ }
800
+ }
801
+ return startIdx;
802
+ }, [rowOverscanStartIdx, rowOverscanEndIdx, rows, summaryRows, colOverscanStartIdx, lastFrozenColumnIndex, colSpanColumns, isGroupRow]);
803
+ return useMemo(() => {
804
+ const viewportColumns = [];
805
+ for (let colIdx = 0; colIdx <= colOverscanEndIdx; colIdx++) {
806
+ const column = columns[colIdx];
807
+ if (colIdx < startIdx && !column.frozen) continue;
808
+ viewportColumns.push(column);
809
+ }
810
+ return viewportColumns;
811
+ }, [startIdx, colOverscanEndIdx, columns]);
812
+ }
813
+
814
+ function isReadonlyArray(arr) {
815
+ return Array.isArray(arr);
816
+ }
817
+ function useViewportRows({
818
+ rawRows,
819
+ rowHeight,
820
+ clientHeight,
821
+ scrollTop,
822
+ groupBy,
823
+ rowGrouper,
824
+ expandedGroupIds,
825
+ enableVirtualization
826
+ }) {
827
+ const [groupedRows, rowsCount] = useMemo(() => {
828
+ if (groupBy.length === 0 || rowGrouper == null) return [undefined, rawRows.length];
829
+ const groupRows = (rows, [groupByKey, ...remainingGroupByKeys], startRowIndex) => {
830
+ let groupRowsCount = 0;
831
+ const groups = {};
832
+ for (const [key, childRows] of Object.entries(rowGrouper(rows, groupByKey))) {
833
+ const [childGroups, childRowsCount] = remainingGroupByKeys.length === 0 ? [childRows, childRows.length] : groupRows(childRows, remainingGroupByKeys, startRowIndex + groupRowsCount + 1);
834
+ groups[key] = {
835
+ childRows,
836
+ childGroups,
837
+ startRowIndex: startRowIndex + groupRowsCount
838
+ };
839
+ groupRowsCount += childRowsCount + 1;
840
+ }
841
+ return [groups, groupRowsCount];
842
+ };
843
+ return groupRows(rawRows, groupBy, 0);
844
+ }, [groupBy, rowGrouper, rawRows]);
845
+ const [rows, isGroupRow] = useMemo(() => {
846
+ const allGroupRows = new Set();
847
+ if (!groupedRows) return [rawRows, isGroupRow];
848
+ const flattenedRows = [];
849
+ const expandGroup = (rows, parentId, level) => {
850
+ if (isReadonlyArray(rows)) {
851
+ flattenedRows.push(...rows);
852
+ return;
853
+ }
854
+ Object.keys(rows).forEach((groupKey, posInSet, keys) => {
855
+ const id = parentId !== undefined ? `${parentId}__${groupKey}` : groupKey;
856
+ const isExpanded = expandedGroupIds?.has(id) ?? false;
857
+ const {
858
+ childRows,
859
+ childGroups,
860
+ startRowIndex
861
+ } = rows[groupKey];
862
+ const groupRow = {
863
+ id,
864
+ parentId,
865
+ groupKey,
866
+ isExpanded,
867
+ childRows,
868
+ level,
869
+ posInSet,
870
+ startRowIndex,
871
+ setSize: keys.length
872
+ };
873
+ flattenedRows.push(groupRow);
874
+ allGroupRows.add(groupRow);
875
+ if (isExpanded) {
876
+ expandGroup(childGroups, id, level + 1);
877
+ }
878
+ });
879
+ };
880
+ expandGroup(groupedRows, undefined, 0);
881
+ return [flattenedRows, isGroupRow];
882
+ function isGroupRow(row) {
883
+ return allGroupRows.has(row);
884
+ }
885
+ }, [expandedGroupIds, groupedRows, rawRows]);
886
+ const {
887
+ totalRowHeight,
888
+ getRowTop,
889
+ getRowHeight,
890
+ findRowIdx
891
+ } = useMemo(() => {
892
+ if (typeof rowHeight === 'number') {
893
+ return {
894
+ totalRowHeight: rowHeight * rows.length,
895
+ getRowTop: rowIdx => rowIdx * rowHeight,
896
+ getRowHeight: () => rowHeight,
897
+ findRowIdx: offset => floor(offset / rowHeight)
898
+ };
899
+ }
900
+ let totalRowHeight = 0;
901
+ const rowPositions = rows.map(row => {
902
+ const currentRowHeight = isGroupRow(row) ? rowHeight({
903
+ type: 'GROUP',
904
+ row
905
+ }) : rowHeight({
906
+ type: 'ROW',
907
+ row
908
+ });
909
+ const position = {
910
+ top: totalRowHeight,
911
+ height: currentRowHeight
912
+ };
913
+ totalRowHeight += currentRowHeight;
914
+ return position;
915
+ });
916
+ const validateRowIdx = rowIdx => {
917
+ return max(0, min(rows.length - 1, rowIdx));
918
+ };
919
+ return {
920
+ totalRowHeight,
921
+ getRowTop: rowIdx => rowPositions[validateRowIdx(rowIdx)].top,
922
+ getRowHeight: rowIdx => rowPositions[validateRowIdx(rowIdx)].height,
923
+ findRowIdx(offset) {
924
+ let start = 0;
925
+ let end = rowPositions.length - 1;
926
+ while (start <= end) {
927
+ const middle = start + floor((end - start) / 2);
928
+ const currentOffset = rowPositions[middle].top;
929
+ if (currentOffset === offset) return middle;
930
+ if (currentOffset < offset) {
931
+ start = middle + 1;
932
+ } else if (currentOffset > offset) {
933
+ end = middle - 1;
934
+ }
935
+ if (start > end) return end;
936
+ }
937
+ return 0;
938
+ }
939
+ };
940
+ }, [isGroupRow, rowHeight, rows]);
941
+ let rowOverscanStartIdx = 0;
942
+ let rowOverscanEndIdx = rows.length - 1;
943
+ if (enableVirtualization) {
944
+ const overscanThreshold = 4;
945
+ const rowVisibleStartIdx = findRowIdx(scrollTop);
946
+ const rowVisibleEndIdx = findRowIdx(scrollTop + clientHeight);
947
+ rowOverscanStartIdx = max(0, rowVisibleStartIdx - overscanThreshold);
948
+ rowOverscanEndIdx = min(rows.length - 1, rowVisibleEndIdx + overscanThreshold);
949
+ }
950
+ return {
951
+ rowOverscanStartIdx,
952
+ rowOverscanEndIdx,
953
+ rows,
954
+ rowsCount,
955
+ totalRowHeight,
956
+ isGroupRow,
957
+ getRowTop,
958
+ getRowHeight,
959
+ findRowIdx
960
+ };
961
+ }
962
+
963
+ var css_248z$8 = ".h1j9yp5q700-beta711{cursor:pointer;display:flex}.h1j9yp5q700-beta711:focus{outline:none}.h1e6at1o700-beta711{flex-grow:1;overflow:hidden;overflow:clip;text-overflow:ellipsis}.a1t8izji700-beta711{fill:currentColor}.a1t8izji700-beta711>path{transition:d .1s}";
964
+ styleInject(css_248z$8,{"insertAt":"top"});
965
+
966
+ const headerSortCell = "h1j9yp5q700-beta711";
967
+ const headerSortCellClassname = `rdg-header-sort-cell ${headerSortCell}`;
968
+ const headerSortName = "h1e6at1o700-beta711";
969
+ const headerSortNameClassname = `rdg-header-sort-name ${headerSortName}`;
970
+ const arrow = "a1t8izji700-beta711";
971
+ const arrowClassname = `rdg-sort-arrow ${arrow}`;
972
+ function SortableHeaderCell({
973
+ onSort,
974
+ sortDirection,
975
+ priority,
976
+ children,
977
+ isCellSelected
978
+ }) {
979
+ const {
980
+ ref,
981
+ tabIndex
982
+ } = useFocusRef(isCellSelected);
983
+ function handleKeyDown(event) {
984
+ if (event.key === ' ' || event.key === 'Enter') {
985
+ event.preventDefault();
986
+ onSort(event.ctrlKey || event.metaKey);
987
+ }
988
+ }
989
+ function handleClick(event) {
990
+ onSort(event.ctrlKey || event.metaKey);
991
+ }
992
+ return /*#__PURE__*/jsxs("span", {
993
+ ref: ref,
994
+ tabIndex: tabIndex,
995
+ className: headerSortCellClassname,
996
+ onMouseDown: handleClick,
997
+ onKeyDown: handleKeyDown,
998
+ children: [/*#__PURE__*/jsx("span", {
999
+ className: headerSortNameClassname,
1000
+ children: children
1001
+ }), /*#__PURE__*/jsxs("span", {
1002
+ children: [sortDirection !== undefined && /*#__PURE__*/jsx("svg", {
1003
+ viewBox: "0 0 12 8",
1004
+ width: "12",
1005
+ height: "8",
1006
+ className: arrowClassname,
1007
+ "aria-hidden": true,
1008
+ children: /*#__PURE__*/jsx("path", {
1009
+ d: sortDirection === 'ASC' ? 'M0 8 6 0 12 8' : 'M0 0 6 8 12 0'
1010
+ })
1011
+ }), priority]
1012
+ })]
1013
+ });
1014
+ }
1015
+
1016
+ var css_248z$7 = ".c6l2wv1700-beta711{touch-action:none}.c6l2wv1700-beta711:after{bottom:0;content:\"\";cursor:col-resize;position:absolute;right:0;top:0;width:10px}";
1017
+ styleInject(css_248z$7,{"insertAt":"top"});
1018
+
1019
+ const cellResizable = "c6l2wv1700-beta711";
1020
+ const cellResizableClassname = `rdg-cell-resizable ${cellResizable}`;
1021
+ function HeaderCell({
1022
+ column,
1023
+ colSpan,
1024
+ isCellSelected,
1025
+ onColumnResize,
1026
+ allRowsSelected,
1027
+ onAllRowsSelectionChange,
1028
+ sortColumns,
1029
+ onSortColumnsChange,
1030
+ selectCell,
1031
+ shouldFocusGrid
1032
+ }) {
1033
+ const {
1034
+ ref,
1035
+ tabIndex,
1036
+ onFocus
1037
+ } = useRovingCellRef(isCellSelected);
1038
+ const sortIndex = sortColumns?.findIndex(sort => sort.columnKey === column.key);
1039
+ const sortColumn = sortIndex !== undefined && sortIndex > -1 ? sortColumns[sortIndex] : undefined;
1040
+ const sortDirection = sortColumn?.direction;
1041
+ const priority = sortColumn !== undefined && sortColumns.length > 1 ? sortIndex + 1 : undefined;
1042
+ const ariaSort = sortDirection && !priority ? sortDirection === 'ASC' ? 'ascending' : 'descending' : undefined;
1043
+ const className = getCellClassname(column, column.headerCellClass, column.resizable && cellResizableClassname);
1044
+ function onPointerDown(event) {
1045
+ if (event.pointerType === 'mouse' && event.buttons !== 1) {
1046
+ return;
1047
+ }
1048
+ const {
1049
+ currentTarget,
1050
+ pointerId
1051
+ } = event;
1052
+ const {
1053
+ right
1054
+ } = currentTarget.getBoundingClientRect();
1055
+ const offset = right - event.clientX;
1056
+ if (offset > 11) {
1057
+ return;
1058
+ }
1059
+ function onPointerMove(event) {
1060
+ const width = event.clientX + offset - currentTarget.getBoundingClientRect().left;
1061
+ if (width > 0) {
1062
+ onColumnResize(column, width);
1063
+ }
1064
+ }
1065
+ function onLostPointerCapture() {
1066
+ currentTarget.removeEventListener('pointermove', onPointerMove);
1067
+ currentTarget.removeEventListener('lostpointercapture', onLostPointerCapture);
1068
+ }
1069
+ currentTarget.setPointerCapture(pointerId);
1070
+ currentTarget.addEventListener('pointermove', onPointerMove);
1071
+ currentTarget.addEventListener('lostpointercapture', onLostPointerCapture);
1072
+ }
1073
+ function onSort(ctrlClick) {
1074
+ if (onSortColumnsChange == null) return;
1075
+ const {
1076
+ sortDescendingFirst
1077
+ } = column;
1078
+ if (sortColumn === undefined) {
1079
+ const nextSort = {
1080
+ columnKey: column.key,
1081
+ direction: sortDescendingFirst ? 'DESC' : 'ASC'
1082
+ };
1083
+ onSortColumnsChange(sortColumns && ctrlClick ? [...sortColumns, nextSort] : [nextSort]);
1084
+ } else {
1085
+ let nextSortColumn;
1086
+ if (sortDescendingFirst && sortDirection === 'DESC' || !sortDescendingFirst && sortDirection === 'ASC') {
1087
+ nextSortColumn = {
1088
+ columnKey: column.key,
1089
+ direction: sortDirection === 'ASC' ? 'DESC' : 'ASC'
1090
+ };
1091
+ }
1092
+ if (ctrlClick) {
1093
+ const nextSortColumns = [...sortColumns];
1094
+ if (nextSortColumn) {
1095
+ nextSortColumns[sortIndex] = nextSortColumn;
1096
+ } else {
1097
+ nextSortColumns.splice(sortIndex, 1);
1098
+ }
1099
+ onSortColumnsChange(nextSortColumns);
1100
+ } else {
1101
+ onSortColumnsChange(nextSortColumn ? [nextSortColumn] : []);
1102
+ }
1103
+ }
1104
+ }
1105
+ function onClick() {
1106
+ selectCell(column.idx);
1107
+ }
1108
+ function handleFocus(event) {
1109
+ onFocus(event);
1110
+ if (shouldFocusGrid) {
1111
+ selectCell(0);
1112
+ }
1113
+ }
1114
+ function getCell() {
1115
+ if (column.headerRenderer) {
1116
+ return /*#__PURE__*/jsx(column.headerRenderer, {
1117
+ column: column,
1118
+ sortDirection: sortDirection,
1119
+ priority: priority,
1120
+ onSort: onSort,
1121
+ allRowsSelected: allRowsSelected,
1122
+ onAllRowsSelectionChange: onAllRowsSelectionChange,
1123
+ isCellSelected: isCellSelected
1124
+ });
1125
+ }
1126
+ if (column.sortable) {
1127
+ return /*#__PURE__*/jsx(SortableHeaderCell, {
1128
+ onSort: onSort,
1129
+ sortDirection: sortDirection,
1130
+ priority: priority,
1131
+ isCellSelected: isCellSelected,
1132
+ children: column.name
1133
+ });
1134
+ }
1135
+ return column.name;
1136
+ }
1137
+ return /*#__PURE__*/jsx("div", {
1138
+ role: "columnheader",
1139
+ "aria-colindex": column.idx + 1,
1140
+ "aria-selected": isCellSelected,
1141
+ "aria-sort": ariaSort,
1142
+ "aria-colspan": colSpan,
1143
+ ref: ref,
1144
+ tabIndex: shouldFocusGrid ? 0 : tabIndex,
1145
+ className: className,
1146
+ style: getCellStyle(column, colSpan),
1147
+ onFocus: handleFocus,
1148
+ onClick: onClick,
1149
+ onPointerDown: column.resizable ? onPointerDown : undefined,
1150
+ children: getCell()
1151
+ });
1152
+ }
1153
+
1154
+ var css_248z$6 = ".h10tskcx700-beta711{background-color:var(--header-background-color);contain:strict;contain:size layout style paint;display:grid;font-weight:700;grid-template-columns:var(--template-columns);grid-template-rows:var(--header-row-height);height:var(--header-row-height);line-height:var(--header-row-height);outline:none;position:sticky;top:0;width:var(--row-width);z-index:3}.h10tskcx700-beta711[aria-selected=true]{box-shadow:inset 0 0 0 2px var(--selection-color)}";
1155
+ styleInject(css_248z$6,{"insertAt":"top"});
1156
+
1157
+ const headerRow = "h10tskcx700-beta711";
1158
+ const headerRowClassname = `rdg-header-row ${headerRow}`;
1159
+ function HeaderRow({
1160
+ columns,
1161
+ allRowsSelected,
1162
+ onAllRowsSelectionChange,
1163
+ onColumnResize,
1164
+ sortColumns,
1165
+ onSortColumnsChange,
1166
+ lastFrozenColumnIndex,
1167
+ selectedCellIdx,
1168
+ selectCell,
1169
+ shouldFocusGrid
1170
+ }) {
1171
+ const {
1172
+ ref,
1173
+ tabIndex,
1174
+ className
1175
+ } = useRovingRowRef(selectedCellIdx);
1176
+ const cells = [];
1177
+ for (let index = 0; index < columns.length; index++) {
1178
+ const column = columns[index];
1179
+ const colSpan = getColSpan(column, lastFrozenColumnIndex, {
1180
+ type: 'HEADER'
1181
+ });
1182
+ if (colSpan !== undefined) {
1183
+ index += colSpan - 1;
1184
+ }
1185
+ cells.push(/*#__PURE__*/jsx(HeaderCell, {
1186
+ column: column,
1187
+ colSpan: colSpan,
1188
+ isCellSelected: selectedCellIdx === column.idx,
1189
+ onColumnResize: onColumnResize,
1190
+ allRowsSelected: allRowsSelected,
1191
+ onAllRowsSelectionChange: onAllRowsSelectionChange,
1192
+ onSortColumnsChange: onSortColumnsChange,
1193
+ sortColumns: sortColumns,
1194
+ selectCell: selectCell,
1195
+ shouldFocusGrid: shouldFocusGrid && index === 0
1196
+ }, column.key));
1197
+ }
1198
+ return /*#__PURE__*/jsx("div", {
1199
+ role: "row",
1200
+ "aria-rowindex": 1,
1201
+ ref: ref,
1202
+ tabIndex: tabIndex,
1203
+ className: clsx(headerRowClassname, className),
1204
+ children: cells
1205
+ });
1206
+ }
1207
+ const HeaderRow$1 = /*#__PURE__*/memo(HeaderRow);
1208
+
1209
+ var css_248z$5 = ".c6ra8a3700-beta711,.cq910m0700-beta711{background-color:#ccf}.cq910m0700-beta711.c6ra8a3700-beta711{background-color:#99f}";
1210
+ styleInject(css_248z$5,{"insertAt":"top"});
1211
+
1212
+ const cellCopied = "c6ra8a3700-beta711";
1213
+ const cellCopiedClassname = `rdg-cell-copied ${cellCopied}`;
1214
+ const cellDraggedOver = "cq910m0700-beta711";
1215
+ const cellDraggedOverClassname = `rdg-cell-dragged-over ${cellDraggedOver}`;
1216
+ function Cell({
1217
+ column,
1218
+ colSpan,
1219
+ isCellSelected,
1220
+ isCopied,
1221
+ isDraggedOver,
1222
+ row,
1223
+ rowIdx,
1224
+ dragHandle,
1225
+ onRowClick,
1226
+ onRowDoubleClick,
1227
+ onRowChange,
1228
+ selectCell,
1229
+ ...props
1230
+ }) {
1231
+ const {
1232
+ ref,
1233
+ tabIndex,
1234
+ onFocus
1235
+ } = useRovingCellRef(isCellSelected);
1236
+ const {
1237
+ cellClass
1238
+ } = column;
1239
+ const className = getCellClassname(column, typeof cellClass === 'function' ? cellClass(row) : cellClass, isCopied && cellCopiedClassname, isDraggedOver && cellDraggedOverClassname);
1240
+ function selectCellWrapper(openEditor) {
1241
+ selectCell(row, column, openEditor);
1242
+ }
1243
+ function handleClick() {
1244
+ selectCellWrapper(column.editorOptions?.editOnClick);
1245
+ onRowClick?.(row, column);
1246
+ }
1247
+ function handleContextMenu() {
1248
+ selectCellWrapper();
1249
+ }
1250
+ function handleDoubleClick() {
1251
+ selectCellWrapper(true);
1252
+ onRowDoubleClick?.(row, column);
1253
+ }
1254
+ return /*#__PURE__*/jsx("div", {
1255
+ role: "gridcell",
1256
+ "aria-colindex": column.idx + 1,
1257
+ "aria-selected": isCellSelected,
1258
+ "aria-colspan": colSpan,
1259
+ "aria-readonly": !isCellEditable(column, row) || undefined,
1260
+ ref: ref,
1261
+ tabIndex: tabIndex,
1262
+ className: className,
1263
+ style: getCellStyle(column, colSpan),
1264
+ onClick: handleClick,
1265
+ onDoubleClick: handleDoubleClick,
1266
+ onContextMenu: handleContextMenu,
1267
+ onFocus: onFocus,
1268
+ ...props,
1269
+ children: !column.rowGroup && /*#__PURE__*/jsxs(Fragment, {
1270
+ children: [/*#__PURE__*/jsx(column.formatter, {
1271
+ column: column,
1272
+ row: row,
1273
+ rowIdx: rowIdx,
1274
+ isCellSelected: isCellSelected,
1275
+ onRowChange: onRowChange
1276
+ }), dragHandle]
1277
+ })
1278
+ });
1279
+ }
1280
+ const Cell$1 = /*#__PURE__*/memo(Cell);
1281
+
1282
+ function Row({
1283
+ className,
1284
+ rowIdx,
1285
+ selectedCellIdx,
1286
+ isRowSelected,
1287
+ copiedCellIdx,
1288
+ draggedOverCellIdx,
1289
+ lastFrozenColumnIndex,
1290
+ row,
1291
+ viewportColumns,
1292
+ selectedCellEditor,
1293
+ selectedCellDragHandle,
1294
+ onRowClick,
1295
+ onRowDoubleClick,
1296
+ rowClass,
1297
+ setDraggedOverRowIdx,
1298
+ onMouseEnter,
1299
+ top,
1300
+ height,
1301
+ onRowChange,
1302
+ selectCell,
1303
+ ...props
1304
+ }, ref) {
1305
+ const {
1306
+ ref: rowRef,
1307
+ tabIndex,
1308
+ className: rovingClassName
1309
+ } = useRovingRowRef(selectedCellIdx);
1310
+ const handleRowChange = useLatestFunc(newRow => {
1311
+ onRowChange(rowIdx, newRow);
1312
+ });
1313
+ function handleDragEnter(event) {
1314
+ setDraggedOverRowIdx?.(rowIdx);
1315
+ onMouseEnter?.(event);
1316
+ }
1317
+ className = clsx(rowClassname, `rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`, rovingClassName, rowClass?.(row), className);
1318
+ const cells = [];
1319
+ for (let index = 0; index < viewportColumns.length; index++) {
1320
+ const column = viewportColumns[index];
1321
+ const {
1322
+ idx
1323
+ } = column;
1324
+ const colSpan = getColSpan(column, lastFrozenColumnIndex, {
1325
+ type: 'ROW',
1326
+ row
1327
+ });
1328
+ if (colSpan !== undefined) {
1329
+ index += colSpan - 1;
1330
+ }
1331
+ const isCellSelected = selectedCellIdx === idx;
1332
+ if (isCellSelected && selectedCellEditor) {
1333
+ cells.push(selectedCellEditor);
1334
+ } else {
1335
+ cells.push(/*#__PURE__*/jsx(Cell$1, {
1336
+ column: column,
1337
+ colSpan: colSpan,
1338
+ row: row,
1339
+ isCopied: copiedCellIdx === idx,
1340
+ isDraggedOver: draggedOverCellIdx === idx,
1341
+ isCellSelected: isCellSelected,
1342
+ dragHandle: isCellSelected ? selectedCellDragHandle : undefined,
1343
+ onRowClick: onRowClick,
1344
+ onRowDoubleClick: onRowDoubleClick,
1345
+ onRowChange: handleRowChange,
1346
+ selectCell: selectCell,
1347
+ rowIdx: rowIdx
1348
+ }, column.key));
1349
+ }
1350
+ }
1351
+ return /*#__PURE__*/jsx(RowSelectionProvider, {
1352
+ value: isRowSelected,
1353
+ children: /*#__PURE__*/jsx("div", {
1354
+ role: "row",
1355
+ ref: useCombinedRefs(ref, rowRef),
1356
+ tabIndex: tabIndex,
1357
+ className: className,
1358
+ onMouseEnter: handleDragEnter,
1359
+ style: {
1360
+ top,
1361
+ '--row-height': `${height}px`
1362
+ },
1363
+ ...props,
1364
+ children: cells
1365
+ })
1366
+ });
1367
+ }
1368
+ const Row$1 = /*#__PURE__*/memo(Row);
1369
+ const RowWithRef = /*#__PURE__*/memo(/*#__PURE__*/forwardRef(Row));
1370
+
1371
+ function GroupCell({
1372
+ id,
1373
+ groupKey,
1374
+ childRows,
1375
+ isExpanded,
1376
+ isCellSelected,
1377
+ column,
1378
+ row,
1379
+ groupColumnIndex,
1380
+ toggleGroup: toggleGroupWrapper
1381
+ }) {
1382
+ const {
1383
+ ref,
1384
+ tabIndex,
1385
+ onFocus
1386
+ } = useRovingCellRef(isCellSelected);
1387
+ function toggleGroup() {
1388
+ toggleGroupWrapper(id);
1389
+ }
1390
+ const isLevelMatching = column.rowGroup && groupColumnIndex === column.idx;
1391
+ return /*#__PURE__*/jsx("div", {
1392
+ role: "gridcell",
1393
+ "aria-colindex": column.idx + 1,
1394
+ "aria-selected": isCellSelected,
1395
+ ref: ref,
1396
+ tabIndex: tabIndex,
1397
+ className: getCellClassname(column),
1398
+ style: {
1399
+ ...getCellStyle(column),
1400
+ cursor: isLevelMatching ? 'pointer' : 'default'
1401
+ },
1402
+ onClick: isLevelMatching ? toggleGroup : undefined,
1403
+ onFocus: onFocus,
1404
+ children: (!column.rowGroup || groupColumnIndex === column.idx) && column.groupFormatter && /*#__PURE__*/jsx(column.groupFormatter, {
1405
+ groupKey: groupKey,
1406
+ childRows: childRows,
1407
+ column: column,
1408
+ row: row,
1409
+ isExpanded: isExpanded,
1410
+ isCellSelected: isCellSelected,
1411
+ toggleGroup: toggleGroup
1412
+ })
1413
+ }, column.key);
1414
+ }
1415
+ const GroupCell$1 = /*#__PURE__*/memo(GroupCell);
1416
+
1417
+ var css_248z$4 = ".g1yxluv3700-beta711:not([aria-selected=true]){background-color:var(--header-background-color)}.g1yxluv3700-beta711>.cj343x0700-beta711:not(:last-child):not(.ch2wcw8700-beta711){border-right:none}";
1418
+ styleInject(css_248z$4,{"insertAt":"top"});
1419
+
1420
+ const groupRow = "g1yxluv3700-beta711";
1421
+ const groupRowClassname = `rdg-group-row ${groupRow}`;
1422
+ function GroupedRow({
1423
+ id,
1424
+ groupKey,
1425
+ viewportColumns,
1426
+ childRows,
1427
+ rowIdx,
1428
+ row,
1429
+ top,
1430
+ height,
1431
+ level,
1432
+ isExpanded,
1433
+ selectedCellIdx,
1434
+ isRowSelected,
1435
+ selectGroup,
1436
+ toggleGroup,
1437
+ ...props
1438
+ }) {
1439
+ const {
1440
+ ref,
1441
+ tabIndex,
1442
+ className
1443
+ } = useRovingRowRef(selectedCellIdx);
1444
+ const idx = viewportColumns[0].key === SELECT_COLUMN_KEY ? level + 1 : level;
1445
+ function handleSelectGroup() {
1446
+ selectGroup(rowIdx);
1447
+ }
1448
+ return /*#__PURE__*/jsx(RowSelectionProvider, {
1449
+ value: isRowSelected,
1450
+ children: /*#__PURE__*/jsx("div", {
1451
+ role: "row",
1452
+ "aria-level": level,
1453
+ "aria-expanded": isExpanded,
1454
+ ref: ref,
1455
+ tabIndex: tabIndex,
1456
+ className: clsx(rowClassname, groupRowClassname, `rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`, className),
1457
+ onClick: handleSelectGroup,
1458
+ style: {
1459
+ top,
1460
+ '--row-height': `${height}px`
1461
+ },
1462
+ ...props,
1463
+ children: viewportColumns.map(column => /*#__PURE__*/jsx(GroupCell$1, {
1464
+ id: id,
1465
+ groupKey: groupKey,
1466
+ childRows: childRows,
1467
+ isExpanded: isExpanded,
1468
+ isCellSelected: selectedCellIdx === column.idx,
1469
+ column: column,
1470
+ row: row,
1471
+ groupColumnIndex: idx,
1472
+ toggleGroup: toggleGroup
1473
+ }, column.key))
1474
+ })
1475
+ });
1476
+ }
1477
+ const GroupRowRenderer = /*#__PURE__*/memo(GroupedRow);
1478
+
1479
+ function SummaryCell({
1480
+ column,
1481
+ colSpan,
1482
+ row,
1483
+ isCellSelected,
1484
+ selectCell
1485
+ }) {
1486
+ const {
1487
+ ref,
1488
+ tabIndex,
1489
+ onFocus
1490
+ } = useRovingCellRef(isCellSelected);
1491
+ const {
1492
+ summaryFormatter: SummaryFormatter,
1493
+ summaryCellClass
1494
+ } = column;
1495
+ const className = getCellClassname(column, typeof summaryCellClass === 'function' ? summaryCellClass(row) : summaryCellClass);
1496
+ function onClick() {
1497
+ selectCell(row, column);
1498
+ }
1499
+ return /*#__PURE__*/jsx("div", {
1500
+ role: "gridcell",
1501
+ "aria-colindex": column.idx + 1,
1502
+ "aria-colspan": colSpan,
1503
+ "aria-selected": isCellSelected,
1504
+ ref: ref,
1505
+ tabIndex: tabIndex,
1506
+ className: className,
1507
+ style: getCellStyle(column, colSpan),
1508
+ onClick: onClick,
1509
+ onFocus: onFocus,
1510
+ children: SummaryFormatter && /*#__PURE__*/jsx(SummaryFormatter, {
1511
+ column: column,
1512
+ row: row,
1513
+ isCellSelected: isCellSelected
1514
+ })
1515
+ });
1516
+ }
1517
+ const SummaryCell$1 = /*#__PURE__*/memo(SummaryCell);
1518
+
1519
+ var css_248z$3 = ".skuhp55700-beta711.r1upfr80700-beta711{grid-template-rows:var(--summary-row-height);height:var(--summary-row-height);line-height:var(--summary-row-height);position:sticky;z-index:3}.sf8l5ub700-beta711>.cj343x0700-beta711{border-top:2px solid var(--summary-border-color)}";
1520
+ styleInject(css_248z$3,{"insertAt":"top"});
1521
+
1522
+ const summaryRow = "skuhp55700-beta711";
1523
+ const summaryRowBorderClassname = "sf8l5ub700-beta711";
1524
+ const summaryRowClassname = `rdg-summary-row ${summaryRow}`;
1525
+ function SummaryRow({
1526
+ rowIdx,
1527
+ row,
1528
+ viewportColumns,
1529
+ bottom,
1530
+ lastFrozenColumnIndex,
1531
+ selectedCellIdx,
1532
+ selectCell,
1533
+ 'aria-rowindex': ariaRowIndex
1534
+ }) {
1535
+ const {
1536
+ ref,
1537
+ tabIndex,
1538
+ className
1539
+ } = useRovingRowRef(selectedCellIdx);
1540
+ const cells = [];
1541
+ for (let index = 0; index < viewportColumns.length; index++) {
1542
+ const column = viewportColumns[index];
1543
+ const colSpan = getColSpan(column, lastFrozenColumnIndex, {
1544
+ type: 'SUMMARY',
1545
+ row
1546
+ });
1547
+ if (colSpan !== undefined) {
1548
+ index += colSpan - 1;
1549
+ }
1550
+ const isCellSelected = selectedCellIdx === column.idx;
1551
+ cells.push(/*#__PURE__*/jsx(SummaryCell$1, {
1552
+ column: column,
1553
+ colSpan: colSpan,
1554
+ row: row,
1555
+ isCellSelected: isCellSelected,
1556
+ selectCell: selectCell
1557
+ }, column.key));
1558
+ }
1559
+ return /*#__PURE__*/jsx("div", {
1560
+ role: "row",
1561
+ "aria-rowindex": ariaRowIndex,
1562
+ ref: ref,
1563
+ tabIndex: tabIndex,
1564
+ className: clsx(rowClassname, `rdg-row-${rowIdx % 2 === 0 ? 'even' : 'odd'}`, summaryRowClassname, className, rowIdx === 0 && summaryRowBorderClassname),
1565
+ style: {
1566
+ bottom
1567
+ },
1568
+ children: cells
1569
+ });
1570
+ }
1571
+ const SummaryRow$1 = /*#__PURE__*/memo(SummaryRow);
1572
+
1573
+ var css_248z$2 = ".cis5rrm700-beta711.rdg-cell{padding:0}";
1574
+ styleInject(css_248z$2,{"insertAt":"top"});
1575
+
1576
+ const cellEditing = "cis5rrm700-beta711";
1577
+ function EditCell({
1578
+ column,
1579
+ colSpan,
1580
+ row,
1581
+ rowIdx,
1582
+ onRowChange,
1583
+ onClose
1584
+ }) {
1585
+ const frameRequestRef = useRef();
1586
+ const commitOnOutsideClick = column.editorOptions?.commitOnOutsideClick !== false;
1587
+ const commitOnOutsideMouseDown = useLatestFunc(() => {
1588
+ onRowChange(row, true);
1589
+ });
1590
+ function cancelFrameRequest() {
1591
+ cancelAnimationFrame(frameRequestRef.current);
1592
+ }
1593
+ useEffect(() => {
1594
+ if (!commitOnOutsideClick) return;
1595
+ function onWindowCaptureMouseDown() {
1596
+ frameRequestRef.current = requestAnimationFrame(commitOnOutsideMouseDown);
1597
+ }
1598
+ addEventListener('mousedown', onWindowCaptureMouseDown, {
1599
+ capture: true
1600
+ });
1601
+ return () => {
1602
+ removeEventListener('mousedown', onWindowCaptureMouseDown, {
1603
+ capture: true
1604
+ });
1605
+ cancelFrameRequest();
1606
+ };
1607
+ }, [commitOnOutsideClick, commitOnOutsideMouseDown]);
1608
+ const {
1609
+ cellClass
1610
+ } = column;
1611
+ const className = getCellClassname(column, 'rdg-editor-container', typeof cellClass === 'function' ? cellClass(row) : cellClass, !column.editorOptions?.renderFormatter && cellEditing);
1612
+ return /*#__PURE__*/jsx("div", {
1613
+ role: "gridcell",
1614
+ "aria-colindex": column.idx + 1,
1615
+ "aria-colspan": colSpan,
1616
+ "aria-selected": true,
1617
+ className: className,
1618
+ style: getCellStyle(column, colSpan),
1619
+ onMouseDownCapture: commitOnOutsideClick ? cancelFrameRequest : undefined,
1620
+ children: column.editor != null && /*#__PURE__*/jsxs(Fragment, {
1621
+ children: [/*#__PURE__*/jsx(column.editor, {
1622
+ column: column,
1623
+ row: row,
1624
+ onRowChange: onRowChange,
1625
+ onClose: onClose
1626
+ }), column.editorOptions?.renderFormatter && /*#__PURE__*/jsx(column.formatter, {
1627
+ column: column,
1628
+ row: row,
1629
+ rowIdx: rowIdx,
1630
+ isCellSelected: true,
1631
+ onRowChange: onRowChange
1632
+ })]
1633
+ })
1634
+ });
1635
+ }
1636
+
1637
+ var css_248z$1 = ".c1w9bbhr700-beta711{background-color:var(--selection-color);bottom:0;cursor:move;height:8px;position:absolute;right:0;width:8px}.c1w9bbhr700-beta711:hover{background-color:var(--background-color);border:2px solid var(--selection-color);height:16px;width:16px}";
1638
+ styleInject(css_248z$1,{"insertAt":"top"});
1639
+
1640
+ const cellDragHandle = "c1w9bbhr700-beta711";
1641
+ const cellDragHandleClassname = `rdg-cell-drag-handle ${cellDragHandle}`;
1642
+ function DragHandle({
1643
+ rows,
1644
+ columns,
1645
+ selectedPosition,
1646
+ latestDraggedOverRowIdx,
1647
+ isCellEditable,
1648
+ onRowsChange,
1649
+ onFill,
1650
+ setDragging,
1651
+ setDraggedOverRowIdx
1652
+ }) {
1653
+ function handleMouseDown(event) {
1654
+ if (event.buttons !== 1) return;
1655
+ setDragging(true);
1656
+ window.addEventListener('mouseover', onMouseOver);
1657
+ window.addEventListener('mouseup', onMouseUp);
1658
+ function onMouseOver(event) {
1659
+ if (event.buttons !== 1) onMouseUp();
1660
+ }
1661
+ function onMouseUp() {
1662
+ window.removeEventListener('mouseover', onMouseOver);
1663
+ window.removeEventListener('mouseup', onMouseUp);
1664
+ setDragging(false);
1665
+ handleDragEnd();
1666
+ }
1667
+ }
1668
+ function handleDragEnd() {
1669
+ const overRowIdx = latestDraggedOverRowIdx.current;
1670
+ if (overRowIdx === undefined) return;
1671
+ const {
1672
+ rowIdx
1673
+ } = selectedPosition;
1674
+ const startRowIndex = rowIdx < overRowIdx ? rowIdx + 1 : overRowIdx;
1675
+ const endRowIndex = rowIdx < overRowIdx ? overRowIdx + 1 : rowIdx;
1676
+ updateRows(startRowIndex, endRowIndex);
1677
+ setDraggedOverRowIdx(undefined);
1678
+ }
1679
+ function handleDoubleClick(event) {
1680
+ event.stopPropagation();
1681
+ updateRows(selectedPosition.rowIdx + 1, rows.length);
1682
+ }
1683
+ function updateRows(startRowIdx, endRowIdx) {
1684
+ const {
1685
+ idx,
1686
+ rowIdx
1687
+ } = selectedPosition;
1688
+ const column = columns[idx];
1689
+ const sourceRow = rows[rowIdx];
1690
+ const updatedRows = [...rows];
1691
+ const indexes = [];
1692
+ for (let i = startRowIdx; i < endRowIdx; i++) {
1693
+ if (isCellEditable({
1694
+ rowIdx: i,
1695
+ idx
1696
+ })) {
1697
+ const updatedRow = onFill({
1698
+ columnKey: column.key,
1699
+ sourceRow,
1700
+ targetRow: rows[i]
1701
+ });
1702
+ if (updatedRow !== rows[i]) {
1703
+ updatedRows[i] = updatedRow;
1704
+ indexes.push(i);
1705
+ }
1706
+ }
1707
+ }
1708
+ if (indexes.length > 0) {
1709
+ onRowsChange?.(updatedRows, {
1710
+ indexes,
1711
+ column
1712
+ });
1713
+ }
1714
+ }
1715
+ return /*#__PURE__*/jsx("div", {
1716
+ className: cellDragHandleClassname,
1717
+ onMouseDown: handleMouseDown,
1718
+ onDoubleClick: handleDoubleClick
1719
+ });
1720
+ }
1721
+
1722
+ const initialPosition = {
1723
+ idx: -1,
1724
+ rowIdx: -2,
1725
+ mode: 'SELECT'
1726
+ };
1727
+ function DataGrid({
1728
+ columns: rawColumns,
1729
+ rows: rawRows,
1730
+ summaryRows,
1731
+ rowKeyGetter,
1732
+ onRowsChange,
1733
+ rowHeight,
1734
+ headerRowHeight: rawHeaderRowHeight,
1735
+ summaryRowHeight: rawSummaryRowHeight,
1736
+ selectedRows,
1737
+ onSelectedRowsChange,
1738
+ sortColumns,
1739
+ onSortColumnsChange,
1740
+ defaultColumnOptions,
1741
+ groupBy: rawGroupBy,
1742
+ rowGrouper,
1743
+ expandedGroupIds,
1744
+ onExpandedGroupIdsChange,
1745
+ onRowClick,
1746
+ onRowDoubleClick,
1747
+ onScroll,
1748
+ onColumnResize,
1749
+ onFill,
1750
+ onPaste,
1751
+ cellNavigationMode: rawCellNavigationMode,
1752
+ enableVirtualization,
1753
+ rowRenderer,
1754
+ noRowsFallback,
1755
+ className,
1756
+ style,
1757
+ rowClass,
1758
+ 'aria-label': ariaLabel,
1759
+ 'aria-labelledby': ariaLabelledBy,
1760
+ 'aria-describedby': ariaDescribedBy,
1761
+ 'data-testid': testId,
1762
+ editableRowIdxs
1763
+ }, ref) {
1764
+ rowHeight ??= 35;
1765
+ const headerRowHeight = rawHeaderRowHeight ?? (typeof rowHeight === 'number' ? rowHeight : 35);
1766
+ const summaryRowHeight = rawSummaryRowHeight ?? (typeof rowHeight === 'number' ? rowHeight : 35);
1767
+ const RowRenderer = rowRenderer ?? Row$1;
1768
+ const cellNavigationMode = rawCellNavigationMode ?? 'NONE';
1769
+ enableVirtualization ??= true;
1770
+ const [scrollTop, setScrollTop] = useState(0);
1771
+ const [scrollLeft, setScrollLeft] = useState(0);
1772
+ const [columnWidths, setColumnWidths] = useState(() => new Map());
1773
+ const [selectedPosition, setSelectedPosition] = useState(initialPosition);
1774
+ const [copiedCell, setCopiedCell] = useState(null);
1775
+ const [isDragging, setDragging] = useState(false);
1776
+ const [draggedOverRowIdx, setOverRowIdx] = useState(undefined);
1777
+ const prevSelectedPosition = useRef(selectedPosition);
1778
+ const latestDraggedOverRowIdx = useRef(draggedOverRowIdx);
1779
+ const lastSelectedRowIdx = useRef(-1);
1780
+ const [gridRef, gridWidth, gridHeight] = useGridDimensions();
1781
+ const headerRowsCount = 1;
1782
+ const summaryRowsCount = summaryRows?.length ?? 0;
1783
+ const clientHeight = gridHeight - headerRowHeight - summaryRowsCount * summaryRowHeight;
1784
+ const isSelectable = selectedRows != null && onSelectedRowsChange != null;
1785
+ const isHeaderRowSelected = selectedPosition.rowIdx === -1;
1786
+ const allRowsSelected = useMemo(() => {
1787
+ const {
1788
+ length
1789
+ } = rawRows;
1790
+ return length !== 0 && selectedRows != null && rowKeyGetter != null && selectedRows.size >= length && rawRows.every(row => selectedRows.has(rowKeyGetter(row)));
1791
+ }, [rawRows, selectedRows, rowKeyGetter]);
1792
+ const {
1793
+ columns,
1794
+ colSpanColumns,
1795
+ colOverscanStartIdx,
1796
+ colOverscanEndIdx,
1797
+ layoutCssVars,
1798
+ columnMetrics,
1799
+ totalColumnWidth,
1800
+ lastFrozenColumnIndex,
1801
+ totalFrozenColumnWidth,
1802
+ groupBy
1803
+ } = useCalculatedColumns({
1804
+ rawColumns,
1805
+ columnWidths,
1806
+ scrollLeft,
1807
+ viewportWidth: gridWidth,
1808
+ defaultColumnOptions,
1809
+ rawGroupBy: rowGrouper ? rawGroupBy : undefined,
1810
+ enableVirtualization
1811
+ });
1812
+ const {
1813
+ rowOverscanStartIdx,
1814
+ rowOverscanEndIdx,
1815
+ rows,
1816
+ rowsCount,
1817
+ totalRowHeight,
1818
+ isGroupRow,
1819
+ getRowTop,
1820
+ getRowHeight,
1821
+ findRowIdx
1822
+ } = useViewportRows({
1823
+ rawRows,
1824
+ groupBy,
1825
+ rowGrouper,
1826
+ rowHeight,
1827
+ clientHeight,
1828
+ scrollTop,
1829
+ expandedGroupIds,
1830
+ enableVirtualization
1831
+ });
1832
+ const viewportColumns = useViewportColumns({
1833
+ columns,
1834
+ colSpanColumns,
1835
+ colOverscanStartIdx,
1836
+ colOverscanEndIdx,
1837
+ lastFrozenColumnIndex,
1838
+ rowOverscanStartIdx,
1839
+ rowOverscanEndIdx,
1840
+ rows,
1841
+ summaryRows,
1842
+ isGroupRow
1843
+ });
1844
+ const hasGroups = groupBy.length > 0 && typeof rowGrouper === 'function';
1845
+ const minColIdx = hasGroups ? -1 : 0;
1846
+ const maxColIdx = columns.length - 1;
1847
+ const minRowIdx = -1;
1848
+ const maxRowIdx = headerRowsCount + rows.length + summaryRowsCount - 2;
1849
+ const selectedCellIsWithinSelectionBounds = isCellWithinSelectionBounds(selectedPosition);
1850
+ const selectedCellIsWithinViewportBounds = isCellWithinViewportBounds(selectedPosition);
1851
+ const selectRowLatest = useLatestFunc(selectRow);
1852
+ const selectAllRowsLatest = useLatestFunc(selectAllRows);
1853
+ const handleFormatterRowChangeLatest = useLatestFunc(updateRow);
1854
+ const selectViewportCellLatest = useLatestFunc((row, column, enableEditor) => {
1855
+ const rowIdx = rows.indexOf(row);
1856
+ selectCell({
1857
+ rowIdx,
1858
+ idx: column.idx
1859
+ }, enableEditor);
1860
+ });
1861
+ const selectGroupLatest = useLatestFunc(rowIdx => {
1862
+ selectCell({
1863
+ rowIdx,
1864
+ idx: -1
1865
+ });
1866
+ });
1867
+ const selectHeaderCellLatest = useLatestFunc(idx => {
1868
+ selectCell({
1869
+ rowIdx: -1,
1870
+ idx
1871
+ });
1872
+ });
1873
+ const selectSummaryCellLatest = useLatestFunc((summaryRow, column) => {
1874
+ const rowIdx = summaryRows.indexOf(summaryRow) + headerRowsCount + rows.length - 1;
1875
+ selectCell({
1876
+ rowIdx,
1877
+ idx: column.idx
1878
+ });
1879
+ });
1880
+ const toggleGroupLatest = useLatestFunc(toggleGroup);
1881
+ useLayoutEffect(() => {
1882
+ if (!selectedCellIsWithinSelectionBounds || selectedPosition.idx === prevSelectedPosition.current.idx && selectedPosition.rowIdx === prevSelectedPosition.current.rowIdx || selectedPosition.mode === 'EDIT') {
1883
+ prevSelectedPosition.current = selectedPosition;
1884
+ return;
1885
+ }
1886
+ prevSelectedPosition.current = selectedPosition;
1887
+ scrollToCell(selectedPosition);
1888
+ });
1889
+ useImperativeHandle(ref, () => ({
1890
+ element: gridRef.current,
1891
+ scrollToColumn(idx) {
1892
+ scrollToCell({
1893
+ idx
1894
+ });
1895
+ },
1896
+ scrollToRow(rowIdx) {
1897
+ const {
1898
+ current
1899
+ } = gridRef;
1900
+ if (!current) return;
1901
+ current.scrollTo({
1902
+ top: getRowTop(rowIdx),
1903
+ behavior: 'smooth'
1904
+ });
1905
+ },
1906
+ selectCell,
1907
+ reInitSelectPosition() {
1908
+ setSelectedPosition(initialPosition);
1909
+ }
1910
+ }));
1911
+ const handleColumnResize = useCallback((column, width) => {
1912
+ setColumnWidths(columnWidths => {
1913
+ const newColumnWidths = new Map(columnWidths);
1914
+ newColumnWidths.set(column.key, width);
1915
+ return newColumnWidths;
1916
+ });
1917
+ onColumnResize?.(column.idx, width);
1918
+ }, [onColumnResize]);
1919
+ const setDraggedOverRowIdx = useCallback(rowIdx => {
1920
+ setOverRowIdx(rowIdx);
1921
+ latestDraggedOverRowIdx.current = rowIdx;
1922
+ }, []);
1923
+ function selectRow({
1924
+ row,
1925
+ checked,
1926
+ isShiftClick
1927
+ }) {
1928
+ if (!onSelectedRowsChange) return;
1929
+ assertIsValidKeyGetter(rowKeyGetter);
1930
+ const newSelectedRows = new Set(selectedRows);
1931
+ if (isGroupRow(row)) {
1932
+ for (const childRow of row.childRows) {
1933
+ const rowKey = rowKeyGetter(childRow);
1934
+ if (checked) {
1935
+ newSelectedRows.add(rowKey);
1936
+ } else {
1937
+ newSelectedRows.delete(rowKey);
1938
+ }
1939
+ }
1940
+ onSelectedRowsChange(newSelectedRows);
1941
+ return;
1942
+ }
1943
+ const rowKey = rowKeyGetter(row);
1944
+ if (checked) {
1945
+ newSelectedRows.add(rowKey);
1946
+ const previousRowIdx = lastSelectedRowIdx.current;
1947
+ const rowIdx = rows.indexOf(row);
1948
+ lastSelectedRowIdx.current = rowIdx;
1949
+ if (isShiftClick && previousRowIdx !== -1 && previousRowIdx !== rowIdx) {
1950
+ const step = sign(rowIdx - previousRowIdx);
1951
+ for (let i = previousRowIdx + step; i !== rowIdx; i += step) {
1952
+ const row = rows[i];
1953
+ if (isGroupRow(row)) continue;
1954
+ newSelectedRows.add(rowKeyGetter(row));
1955
+ }
1956
+ }
1957
+ } else {
1958
+ newSelectedRows.delete(rowKey);
1959
+ lastSelectedRowIdx.current = -1;
1960
+ }
1961
+ onSelectedRowsChange(newSelectedRows);
1962
+ }
1963
+ function selectAllRows(checked) {
1964
+ if (!onSelectedRowsChange) return;
1965
+ assertIsValidKeyGetter(rowKeyGetter);
1966
+ const newSelectedRows = new Set(selectedRows);
1967
+ for (const row of rawRows) {
1968
+ const rowKey = rowKeyGetter(row);
1969
+ if (checked) {
1970
+ newSelectedRows.add(rowKey);
1971
+ } else {
1972
+ newSelectedRows.delete(rowKey);
1973
+ }
1974
+ }
1975
+ onSelectedRowsChange(newSelectedRows);
1976
+ }
1977
+ function toggleGroup(expandedGroupId) {
1978
+ if (!onExpandedGroupIdsChange) return;
1979
+ const newExpandedGroupIds = new Set(expandedGroupIds);
1980
+ if (newExpandedGroupIds.has(expandedGroupId)) {
1981
+ newExpandedGroupIds.delete(expandedGroupId);
1982
+ } else {
1983
+ newExpandedGroupIds.add(expandedGroupId);
1984
+ }
1985
+ onExpandedGroupIdsChange(newExpandedGroupIds);
1986
+ }
1987
+ function handleKeyDown(event) {
1988
+ if (!(event.target instanceof Element)) return;
1989
+ const isCellEvent = event.target.closest('.rdg-cell') !== null;
1990
+ const isRowEvent = hasGroups && event.target.matches('.rdg-row, .rdg-header-row');
1991
+ if (!isCellEvent && !isRowEvent) return;
1992
+ const {
1993
+ key,
1994
+ keyCode
1995
+ } = event;
1996
+ const {
1997
+ rowIdx
1998
+ } = selectedPosition;
1999
+ if (selectedCellIsWithinViewportBounds && onPaste != null && isCtrlKeyHeldDown(event) && !isGroupRow(rows[rowIdx]) && selectedPosition.mode === 'SELECT') {
2000
+ const cKey = 67;
2001
+ const vKey = 86;
2002
+ if (keyCode === cKey) {
2003
+ handleCopy();
2004
+ return;
2005
+ }
2006
+ if (keyCode === vKey) {
2007
+ handlePaste();
2008
+ return;
2009
+ }
2010
+ }
2011
+ if (isRowIdxWithinViewportBounds(rowIdx)) {
2012
+ const row = rows[rowIdx];
2013
+ if (isGroupRow(row) && selectedPosition.idx === -1 && (key === 'ArrowLeft' && row.isExpanded || key === 'ArrowRight' && !row.isExpanded)) {
2014
+ event.preventDefault();
2015
+ toggleGroup(row.id);
2016
+ return;
2017
+ }
2018
+ }
2019
+ switch (event.key) {
2020
+ case 'Escape':
2021
+ setCopiedCell(null);
2022
+ closeEditor();
2023
+ return;
2024
+ case 'ArrowUp':
2025
+ case 'ArrowDown':
2026
+ case 'ArrowLeft':
2027
+ case 'ArrowRight':
2028
+ case 'Tab':
2029
+ case 'Home':
2030
+ case 'End':
2031
+ case 'PageUp':
2032
+ case 'PageDown':
2033
+ navigate(event);
2034
+ break;
2035
+ default:
2036
+ handleCellInput(event);
2037
+ break;
2038
+ }
2039
+ }
2040
+ function handleScroll(event) {
2041
+ const {
2042
+ scrollTop,
2043
+ scrollLeft
2044
+ } = event.currentTarget;
2045
+ setScrollTop(scrollTop);
2046
+ setScrollLeft(scrollLeft);
2047
+ onScroll?.(event);
2048
+ }
2049
+ function getRawRowIdx(rowIdx) {
2050
+ return hasGroups ? rawRows.indexOf(rows[rowIdx]) : rowIdx;
2051
+ }
2052
+ function updateRow(rowIdx, row) {
2053
+ if (typeof onRowsChange !== 'function') return;
2054
+ const rawRowIdx = getRawRowIdx(rowIdx);
2055
+ if (row === rawRows[rawRowIdx]) return;
2056
+ const updatedRows = [...rawRows];
2057
+ updatedRows[rawRowIdx] = row;
2058
+ onRowsChange(updatedRows, {
2059
+ indexes: [rawRowIdx],
2060
+ column: columns[selectedPosition.idx]
2061
+ });
2062
+ }
2063
+ function commitEditorChanges() {
2064
+ if (columns[selectedPosition.idx]?.editor == null || selectedPosition.mode === 'SELECT' || selectedPosition.row === selectedPosition.originalRow) {
2065
+ return;
2066
+ }
2067
+ updateRow(selectedPosition.rowIdx, selectedPosition.row);
2068
+ }
2069
+ function handleCopy() {
2070
+ const {
2071
+ idx,
2072
+ rowIdx
2073
+ } = selectedPosition;
2074
+ setCopiedCell({
2075
+ row: rawRows[getRawRowIdx(rowIdx)],
2076
+ columnKey: columns[idx].key
2077
+ });
2078
+ }
2079
+ function handlePaste() {
2080
+ if (!onPaste || !onRowsChange || copiedCell === null || !isCellEditable(selectedPosition)) {
2081
+ return;
2082
+ }
2083
+ const {
2084
+ idx,
2085
+ rowIdx
2086
+ } = selectedPosition;
2087
+ const targetRow = rawRows[getRawRowIdx(rowIdx)];
2088
+ const updatedTargetRow = onPaste({
2089
+ sourceRow: copiedCell.row,
2090
+ sourceColumnKey: copiedCell.columnKey,
2091
+ targetRow,
2092
+ targetColumnKey: columns[idx].key
2093
+ });
2094
+ updateRow(rowIdx, updatedTargetRow);
2095
+ }
2096
+ function handleCellInput(event) {
2097
+ if (!selectedCellIsWithinViewportBounds) return;
2098
+ const row = rows[selectedPosition.rowIdx];
2099
+ if (isGroupRow(row)) return;
2100
+ const {
2101
+ key,
2102
+ shiftKey
2103
+ } = event;
2104
+ if (selectedPosition.mode === 'EDIT') {
2105
+ if (key === 'Enter') {
2106
+ commitEditorChanges();
2107
+ closeEditor();
2108
+ }
2109
+ return;
2110
+ }
2111
+ if (isSelectable && shiftKey && key === ' ') {
2112
+ assertIsValidKeyGetter(rowKeyGetter);
2113
+ const rowKey = rowKeyGetter(row);
2114
+ selectRow({
2115
+ row,
2116
+ checked: !selectedRows.has(rowKey),
2117
+ isShiftClick: false
2118
+ });
2119
+ event.preventDefault();
2120
+ return;
2121
+ }
2122
+ const column = columns[selectedPosition.idx];
2123
+ column.editorOptions?.onCellKeyDown?.(event);
2124
+ if (event.isDefaultPrevented()) return;
2125
+ if (isCellEditable(selectedPosition) && isDefaultCellInput(event)) {
2126
+ setSelectedPosition(({
2127
+ idx,
2128
+ rowIdx
2129
+ }) => ({
2130
+ idx,
2131
+ rowIdx,
2132
+ mode: 'EDIT',
2133
+ row,
2134
+ originalRow: row
2135
+ }));
2136
+ }
2137
+ }
2138
+ function handleEditorRowChange(row, commitChanges) {
2139
+ if (selectedPosition.mode === 'SELECT') return;
2140
+ if (commitChanges) {
2141
+ updateRow(selectedPosition.rowIdx, row);
2142
+ closeEditor();
2143
+ } else {
2144
+ setSelectedPosition(position => ({
2145
+ ...position,
2146
+ row
2147
+ }));
2148
+ }
2149
+ }
2150
+ function handleOnClose(commitChanges) {
2151
+ if (commitChanges) {
2152
+ commitEditorChanges();
2153
+ }
2154
+ closeEditor();
2155
+ }
2156
+ function isColIdxWithinSelectionBounds(idx) {
2157
+ return idx >= minColIdx && idx <= maxColIdx;
2158
+ }
2159
+ function isRowIdxWithinViewportBounds(rowIdx) {
2160
+ return rowIdx >= 0 && rowIdx < rows.length;
2161
+ }
2162
+ function isCellWithinSelectionBounds({
2163
+ idx,
2164
+ rowIdx
2165
+ }) {
2166
+ return rowIdx >= minRowIdx && rowIdx <= maxRowIdx && isColIdxWithinSelectionBounds(idx);
2167
+ }
2168
+ function isCellWithinViewportBounds({
2169
+ idx,
2170
+ rowIdx
2171
+ }) {
2172
+ return isRowIdxWithinViewportBounds(rowIdx) && isColIdxWithinSelectionBounds(idx);
2173
+ }
2174
+ function isCellEditable(position) {
2175
+ return isCellWithinViewportBounds(position) && isSelectedCellEditable({
2176
+ columns,
2177
+ rows,
2178
+ selectedPosition: position,
2179
+ isGroupRow
2180
+ });
2181
+ }
2182
+ function selectCell(position, enableEditor) {
2183
+ if (!isCellWithinSelectionBounds(position)) return;
2184
+ commitEditorChanges();
2185
+ if (enableEditor && isCellEditable(position)) {
2186
+ const row = rows[position.rowIdx];
2187
+ setSelectedPosition({
2188
+ ...position,
2189
+ mode: 'EDIT',
2190
+ row,
2191
+ originalRow: row
2192
+ });
2193
+ } else if (selectedPosition.mode !== 'SELECT' || selectedPosition.idx !== position.idx || selectedPosition.rowIdx !== position.rowIdx) {
2194
+ setSelectedPosition({
2195
+ ...position,
2196
+ mode: 'SELECT'
2197
+ });
2198
+ }
2199
+ }
2200
+ function closeEditor() {
2201
+ if (selectedPosition.mode === 'SELECT') return;
2202
+ setSelectedPosition(({
2203
+ idx,
2204
+ rowIdx
2205
+ }) => ({
2206
+ idx,
2207
+ rowIdx,
2208
+ mode: 'SELECT'
2209
+ }));
2210
+ }
2211
+ function scrollToCell({
2212
+ idx,
2213
+ rowIdx
2214
+ }) {
2215
+ const {
2216
+ current
2217
+ } = gridRef;
2218
+ if (!current) return;
2219
+ if (typeof idx === 'number' && idx > lastFrozenColumnIndex) {
2220
+ rowIdx ??= selectedPosition.rowIdx;
2221
+ if (!isCellWithinSelectionBounds({
2222
+ rowIdx,
2223
+ idx
2224
+ })) return;
2225
+ const {
2226
+ clientWidth
2227
+ } = current;
2228
+ const column = columns[idx];
2229
+ const {
2230
+ left,
2231
+ width
2232
+ } = columnMetrics.get(column);
2233
+ let right = left + width;
2234
+ const colSpan = getSelectedCellColSpan({
2235
+ rows,
2236
+ summaryRows,
2237
+ rowIdx,
2238
+ lastFrozenColumnIndex,
2239
+ column,
2240
+ isGroupRow
2241
+ });
2242
+ if (colSpan !== undefined) {
2243
+ const {
2244
+ left,
2245
+ width
2246
+ } = columnMetrics.get(columns[column.idx + colSpan - 1]);
2247
+ right = left + width;
2248
+ }
2249
+ const isCellAtLeftBoundary = left < scrollLeft + totalFrozenColumnWidth;
2250
+ const isCellAtRightBoundary = right > clientWidth + scrollLeft;
2251
+ if (isCellAtLeftBoundary) {
2252
+ current.scrollLeft = left - totalFrozenColumnWidth;
2253
+ } else if (isCellAtRightBoundary) {
2254
+ current.scrollLeft = right - clientWidth;
2255
+ }
2256
+ }
2257
+ if (typeof rowIdx === 'number' && isRowIdxWithinViewportBounds(rowIdx)) {
2258
+ const rowTop = getRowTop(rowIdx);
2259
+ const rowHeight = getRowHeight(rowIdx);
2260
+ if (rowTop < scrollTop) {
2261
+ current.scrollTop = rowTop;
2262
+ } else if (rowTop + rowHeight > scrollTop + clientHeight) {
2263
+ current.scrollTop = rowTop + rowHeight - clientHeight;
2264
+ }
2265
+ }
2266
+ }
2267
+ function getNextPosition(key, ctrlKey, shiftKey) {
2268
+ const {
2269
+ idx,
2270
+ rowIdx
2271
+ } = selectedPosition;
2272
+ const row = rows[rowIdx];
2273
+ const isRowSelected = selectedCellIsWithinSelectionBounds && idx === -1;
2274
+ if (key === 'ArrowLeft' && isRowSelected && isGroupRow(row) && !row.isExpanded && row.level !== 0) {
2275
+ let parentRowIdx = -1;
2276
+ for (let i = selectedPosition.rowIdx - 1; i >= 0; i--) {
2277
+ const parentRow = rows[i];
2278
+ if (isGroupRow(parentRow) && parentRow.id === row.parentId) {
2279
+ parentRowIdx = i;
2280
+ break;
2281
+ }
2282
+ }
2283
+ if (parentRowIdx !== -1) {
2284
+ return {
2285
+ idx,
2286
+ rowIdx: parentRowIdx
2287
+ };
2288
+ }
2289
+ }
2290
+ switch (key) {
2291
+ case 'ArrowUp':
2292
+ return {
2293
+ idx,
2294
+ rowIdx: rowIdx - 1
2295
+ };
2296
+ case 'ArrowDown':
2297
+ return {
2298
+ idx,
2299
+ rowIdx: rowIdx + 1
2300
+ };
2301
+ case 'ArrowLeft':
2302
+ return {
2303
+ idx: idx - 1,
2304
+ rowIdx
2305
+ };
2306
+ case 'ArrowRight':
2307
+ return {
2308
+ idx: idx + 1,
2309
+ rowIdx
2310
+ };
2311
+ case 'Tab':
2312
+ return {
2313
+ idx: idx + (shiftKey ? -1 : 1),
2314
+ rowIdx
2315
+ };
2316
+ case 'Home':
2317
+ if (isRowSelected) return {
2318
+ idx,
2319
+ rowIdx: 0
2320
+ };
2321
+ return {
2322
+ idx: 0,
2323
+ rowIdx: ctrlKey ? minRowIdx : rowIdx
2324
+ };
2325
+ case 'End':
2326
+ if (isRowSelected) return {
2327
+ idx,
2328
+ rowIdx: rows.length - 1
2329
+ };
2330
+ return {
2331
+ idx: maxColIdx,
2332
+ rowIdx: ctrlKey ? maxRowIdx : rowIdx
2333
+ };
2334
+ case 'PageUp':
2335
+ {
2336
+ if (selectedPosition.rowIdx === minRowIdx) return selectedPosition;
2337
+ const nextRowY = getRowTop(rowIdx) + getRowHeight(rowIdx) - clientHeight;
2338
+ return {
2339
+ idx,
2340
+ rowIdx: nextRowY > 0 ? findRowIdx(nextRowY) : 0
2341
+ };
2342
+ }
2343
+ case 'PageDown':
2344
+ {
2345
+ if (selectedPosition.rowIdx >= rows.length) return selectedPosition;
2346
+ const nextRowY = getRowTop(rowIdx) + clientHeight;
2347
+ return {
2348
+ idx,
2349
+ rowIdx: nextRowY < totalRowHeight ? findRowIdx(nextRowY) : rows.length - 1
2350
+ };
2351
+ }
2352
+ default:
2353
+ return selectedPosition;
2354
+ }
2355
+ }
2356
+ function navigate(event) {
2357
+ if (selectedPosition.mode === 'EDIT') {
2358
+ const onNavigation = columns[selectedPosition.idx].editorOptions?.onNavigation ?? onEditorNavigation;
2359
+ if (!onNavigation(event)) return;
2360
+ }
2361
+ const {
2362
+ key,
2363
+ shiftKey
2364
+ } = event;
2365
+ let mode = cellNavigationMode;
2366
+ if (key === 'Tab') {
2367
+ if (canExitGrid({
2368
+ shiftKey,
2369
+ cellNavigationMode,
2370
+ maxColIdx,
2371
+ minRowIdx,
2372
+ maxRowIdx,
2373
+ selectedPosition
2374
+ })) {
2375
+ commitEditorChanges();
2376
+ return;
2377
+ }
2378
+ mode = cellNavigationMode === 'NONE' ? 'CHANGE_ROW' : cellNavigationMode;
2379
+ }
2380
+ event.preventDefault();
2381
+ const ctrlKey = isCtrlKeyHeldDown(event);
2382
+ const nextPosition = getNextPosition(key, ctrlKey, shiftKey);
2383
+ if (nextPosition.rowIdx === selectedPosition.rowIdx && nextPosition.idx === selectedPosition.idx) {
2384
+ return;
2385
+ }
2386
+ const nextSelectedCellPosition = getNextSelectedCellPosition({
2387
+ columns,
2388
+ colSpanColumns,
2389
+ rows,
2390
+ summaryRows,
2391
+ minRowIdx,
2392
+ maxRowIdx,
2393
+ lastFrozenColumnIndex,
2394
+ cellNavigationMode: mode,
2395
+ currentPosition: selectedPosition,
2396
+ nextPosition,
2397
+ isCellWithinBounds: isCellWithinSelectionBounds,
2398
+ isGroupRow
2399
+ });
2400
+ selectCell(nextSelectedCellPosition);
2401
+ }
2402
+ function getDraggedOverCellIdx(currentRowIdx) {
2403
+ if (draggedOverRowIdx === undefined) return;
2404
+ const {
2405
+ rowIdx
2406
+ } = selectedPosition;
2407
+ const isDraggedOver = rowIdx < draggedOverRowIdx ? rowIdx < currentRowIdx && currentRowIdx <= draggedOverRowIdx : rowIdx > currentRowIdx && currentRowIdx >= draggedOverRowIdx;
2408
+ return isDraggedOver ? selectedPosition.idx : undefined;
2409
+ }
2410
+ function getDragHandle(rowIdx) {
2411
+ if (selectedPosition.rowIdx !== rowIdx || selectedPosition.mode === 'EDIT' || hasGroups || onFill == null) {
2412
+ return;
2413
+ }
2414
+ return /*#__PURE__*/jsx(DragHandle, {
2415
+ rows: rawRows,
2416
+ columns: columns,
2417
+ selectedPosition: selectedPosition,
2418
+ isCellEditable: isCellEditable,
2419
+ latestDraggedOverRowIdx: latestDraggedOverRowIdx,
2420
+ onRowsChange: onRowsChange,
2421
+ onFill: onFill,
2422
+ setDragging: setDragging,
2423
+ setDraggedOverRowIdx: setDraggedOverRowIdx
2424
+ });
2425
+ }
2426
+ function getCellEditor(rowIdx) {
2427
+ const isOutsideEditableRows = Array.isArray(editableRowIdxs) ? !editableRowIdxs.includes(selectedPosition.rowIdx) : selectedPosition.rowIdx !== rowIdx;
2428
+ if (isOutsideEditableRows || selectedPosition.mode === 'SELECT') return;
2429
+ const {
2430
+ idx,
2431
+ row
2432
+ } = selectedPosition;
2433
+ const column = columns[idx];
2434
+ const colSpan = getColSpan(column, lastFrozenColumnIndex, {
2435
+ type: 'ROW',
2436
+ row
2437
+ });
2438
+ return /*#__PURE__*/jsx(EditCell, {
2439
+ column: column,
2440
+ colSpan: colSpan,
2441
+ row: row,
2442
+ rowIdx: selectedPosition.rowIdx,
2443
+ onRowChange: handleEditorRowChange,
2444
+ onClose: handleOnClose
2445
+ }, column.key);
2446
+ }
2447
+ function getViewportRows() {
2448
+ const rowElements = [];
2449
+ let startRowIndex = 0;
2450
+ const {
2451
+ idx: selectedIdx,
2452
+ rowIdx: selectedRowIdx
2453
+ } = selectedPosition;
2454
+ const startRowIdx = selectedCellIsWithinViewportBounds && selectedRowIdx < rowOverscanStartIdx ? rowOverscanStartIdx - 1 : rowOverscanStartIdx;
2455
+ const endRowIdx = selectedCellIsWithinViewportBounds && selectedRowIdx > rowOverscanEndIdx ? rowOverscanEndIdx + 1 : rowOverscanEndIdx;
2456
+ for (let viewportRowIdx = startRowIdx; viewportRowIdx <= endRowIdx; viewportRowIdx++) {
2457
+ const isRowOutsideViewport = viewportRowIdx === rowOverscanStartIdx - 1 || viewportRowIdx === rowOverscanEndIdx + 1;
2458
+ const rowIdx = isRowOutsideViewport ? selectedRowIdx : viewportRowIdx;
2459
+ let rowColumns = viewportColumns;
2460
+ const selectedColumn = columns[selectedIdx];
2461
+ if (selectedColumn !== undefined) {
2462
+ if (isRowOutsideViewport) {
2463
+ rowColumns = [selectedColumn];
2464
+ } else if (selectedRowIdx === rowIdx && !viewportColumns.includes(selectedColumn)) {
2465
+ rowColumns = selectedIdx > viewportColumns[viewportColumns.length - 1].idx ? [...viewportColumns, selectedColumn] : [...viewportColumns.slice(0, lastFrozenColumnIndex + 1), selectedColumn, ...viewportColumns.slice(lastFrozenColumnIndex + 1)];
2466
+ }
2467
+ }
2468
+ const row = rows[rowIdx];
2469
+ const top = getRowTop(rowIdx) + headerRowHeight;
2470
+ if (isGroupRow(row)) {
2471
+ ({
2472
+ startRowIndex
2473
+ } = row);
2474
+ const isGroupRowSelected = isSelectable && row.childRows.every(cr => selectedRows.has(rowKeyGetter(cr)));
2475
+ rowElements.push(/*#__PURE__*/jsx(GroupRowRenderer, {
2476
+ "aria-level": row.level + 1,
2477
+ "aria-setsize": row.setSize,
2478
+ "aria-posinset": row.posInSet + 1,
2479
+ "aria-rowindex": headerRowsCount + startRowIndex + 1,
2480
+ "aria-selected": isSelectable ? isGroupRowSelected : undefined,
2481
+ id: row.id,
2482
+ groupKey: row.groupKey,
2483
+ viewportColumns: rowColumns,
2484
+ childRows: row.childRows,
2485
+ rowIdx: rowIdx,
2486
+ row: row,
2487
+ top: top,
2488
+ height: getRowHeight(rowIdx),
2489
+ level: row.level,
2490
+ isExpanded: row.isExpanded,
2491
+ selectedCellIdx: selectedRowIdx === rowIdx ? selectedIdx : undefined,
2492
+ isRowSelected: isGroupRowSelected,
2493
+ selectGroup: selectGroupLatest,
2494
+ toggleGroup: toggleGroupLatest
2495
+ }, row.id));
2496
+ continue;
2497
+ }
2498
+ startRowIndex++;
2499
+ let key;
2500
+ let isRowSelected = false;
2501
+ if (typeof rowKeyGetter === 'function') {
2502
+ key = rowKeyGetter(row);
2503
+ isRowSelected = selectedRows?.has(key) ?? false;
2504
+ } else {
2505
+ key = hasGroups ? startRowIndex : rowIdx;
2506
+ }
2507
+ rowElements.push(/*#__PURE__*/jsx(RowRenderer, {
2508
+ "aria-rowindex": headerRowsCount + (hasGroups ? startRowIndex : rowIdx) + 1,
2509
+ "aria-selected": isSelectable ? isRowSelected : undefined,
2510
+ rowIdx: rowIdx,
2511
+ row: row,
2512
+ viewportColumns: rowColumns,
2513
+ isRowSelected: isRowSelected,
2514
+ onRowClick: onRowClick,
2515
+ onRowDoubleClick: onRowDoubleClick,
2516
+ rowClass: rowClass,
2517
+ top: top,
2518
+ height: getRowHeight(rowIdx),
2519
+ copiedCellIdx: copiedCell !== null && copiedCell.row === row ? columns.findIndex(c => c.key === copiedCell.columnKey) : undefined,
2520
+ selectedCellIdx: selectedRowIdx === rowIdx ? selectedIdx : undefined,
2521
+ draggedOverCellIdx: getDraggedOverCellIdx(rowIdx),
2522
+ setDraggedOverRowIdx: isDragging ? setDraggedOverRowIdx : undefined,
2523
+ lastFrozenColumnIndex: lastFrozenColumnIndex,
2524
+ onRowChange: handleFormatterRowChangeLatest,
2525
+ selectCell: selectViewportCellLatest,
2526
+ selectedCellDragHandle: getDragHandle(rowIdx),
2527
+ selectedCellEditor: getCellEditor(rowIdx)
2528
+ }, key));
2529
+ }
2530
+ return rowElements;
2531
+ }
2532
+ if (selectedPosition.idx > maxColIdx || selectedPosition.rowIdx > maxRowIdx) {
2533
+ setSelectedPosition(initialPosition);
2534
+ setDraggedOverRowIdx(undefined);
2535
+ }
2536
+ if (selectedPosition.mode === 'EDIT' && rows[selectedPosition.rowIdx] !== selectedPosition.originalRow) {
2537
+ closeEditor();
2538
+ }
2539
+ return /*#__PURE__*/jsxs("div", {
2540
+ role: hasGroups ? 'treegrid' : 'grid',
2541
+ "aria-label": ariaLabel,
2542
+ "aria-labelledby": ariaLabelledBy,
2543
+ "aria-describedby": ariaDescribedBy,
2544
+ "aria-multiselectable": isSelectable ? true : undefined,
2545
+ "aria-colcount": columns.length,
2546
+ "aria-rowcount": headerRowsCount + rowsCount + summaryRowsCount,
2547
+ className: clsx(rootClassname, className, isDragging && viewportDraggingClassname),
2548
+ style: {
2549
+ ...style,
2550
+ '--header-row-height': `${headerRowHeight}px`,
2551
+ '--row-width': `${totalColumnWidth}px`,
2552
+ '--summary-row-height': `${summaryRowHeight}px`,
2553
+ ...layoutCssVars
2554
+ },
2555
+ ref: gridRef,
2556
+ onScroll: handleScroll,
2557
+ onKeyDown: handleKeyDown,
2558
+ "data-testid": testId,
2559
+ children: [/*#__PURE__*/jsx(HeaderRow$1, {
2560
+ columns: viewportColumns,
2561
+ onColumnResize: handleColumnResize,
2562
+ allRowsSelected: allRowsSelected,
2563
+ onAllRowsSelectionChange: selectAllRowsLatest,
2564
+ sortColumns: sortColumns,
2565
+ onSortColumnsChange: onSortColumnsChange,
2566
+ lastFrozenColumnIndex: lastFrozenColumnIndex,
2567
+ selectedCellIdx: isHeaderRowSelected ? selectedPosition.idx : undefined,
2568
+ selectCell: selectHeaderCellLatest,
2569
+ shouldFocusGrid: !selectedCellIsWithinSelectionBounds
2570
+ }), rows.length === 0 && noRowsFallback ? noRowsFallback : /*#__PURE__*/jsxs(Fragment, {
2571
+ children: [/*#__PURE__*/jsx("div", {
2572
+ style: {
2573
+ height: max(totalRowHeight, clientHeight)
2574
+ }
2575
+ }), /*#__PURE__*/jsx(RowSelectionChangeProvider, {
2576
+ value: selectRowLatest,
2577
+ children: getViewportRows()
2578
+ }), summaryRows?.map((row, rowIdx) => {
2579
+ const isSummaryRowSelected = selectedPosition.rowIdx === headerRowsCount + rows.length + rowIdx - 1;
2580
+ return /*#__PURE__*/jsx(SummaryRow$1, {
2581
+ "aria-rowindex": headerRowsCount + rowsCount + rowIdx + 1,
2582
+ rowIdx: rowIdx,
2583
+ row: row,
2584
+ bottom: summaryRowHeight * (summaryRows.length - 1 - rowIdx),
2585
+ viewportColumns: viewportColumns,
2586
+ lastFrozenColumnIndex: lastFrozenColumnIndex,
2587
+ selectedCellIdx: isSummaryRowSelected ? selectedPosition.idx : undefined,
2588
+ selectCell: selectSummaryCellLatest
2589
+ }, rowIdx);
2590
+ })]
2591
+ })]
2592
+ });
2593
+ }
2594
+ const DataGrid$1 = /*#__PURE__*/forwardRef(DataGrid);
2595
+
2596
+ var css_248z = ".t1u15qzo700-beta711{appearance:none;background-color:var(--background-color);border:2px solid #ccc;box-sizing:border-box;color:var(--color);font-family:inherit;font-size:var(--font-size);height:100%;padding:0 6px;vertical-align:top;width:100%}.t1u15qzo700-beta711:focus{border-color:var(--selection-color);outline:none}.t1u15qzo700-beta711::placeholder{color:#999;opacity:1}";
2597
+ styleInject(css_248z,{"insertAt":"top"});
2598
+
2599
+ const textEditor = "t1u15qzo700-beta711";
2600
+ const textEditorClassname = `rdg-text-editor ${textEditor}`;
2601
+ function autoFocusAndSelect(input) {
2602
+ input?.focus();
2603
+ input?.select();
2604
+ }
2605
+ function TextEditor({
2606
+ row,
2607
+ column,
2608
+ onRowChange,
2609
+ onClose
2610
+ }) {
2611
+ return /*#__PURE__*/jsx("input", {
2612
+ className: textEditorClassname,
2613
+ ref: autoFocusAndSelect,
2614
+ value: row[column.key],
2615
+ onChange: event => onRowChange({
2616
+ ...row,
2617
+ [column.key]: event.target.value
2618
+ }),
2619
+ onBlur: () => onClose(true)
2620
+ });
2621
+ }
2622
+
2623
+ export { RowWithRef as Row, SELECT_COLUMN_KEY, SelectCellFormatter, SelectColumn, SortableHeaderCell, TextEditor, ToggleGroupFormatter, ValueFormatter, DataGrid$1 as default, useRowSelection };
2624
+ //# sourceMappingURL=bundle.js.map