material-react-table-narender 2.13.19 → 2.13.21

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.d.ts CHANGED
@@ -376,6 +376,7 @@ interface MRT_Localization {
376
376
  thenBy: string;
377
377
  toggleDensity: string;
378
378
  toggleFullScreen: string;
379
+ keyboardNavigation: string;
379
380
  toggleSelectAll: string;
380
381
  toggleSelectRow: string;
381
382
  toggleVisibility: string;
package/dist/index.esm.js CHANGED
@@ -435,43 +435,43 @@ const openEditingCell = ({ cell, table, }) => {
435
435
  }
436
436
  };
437
437
  const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement, event, header, parentElement, table, }) => {
438
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
438
+ var _a, _b, _c, _d, _e, _f, _g, _h;
439
439
  debugger;
440
440
  const { getState, setEnableKeyboardShortcuts, } = table;
441
441
  const { enableKeyboardShortcuts } = getState();
442
- if (event.altKey) {
443
- event.preventDefault();
444
- setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
445
- const currentCell = event.currentTarget;
446
- if (enableKeyboardShortcuts) {
447
- const input = currentCell.querySelector('input');
448
- const select = currentCell.querySelector('select');
449
- const checkbox = currentCell.querySelector('input[type="checkbox"]');
450
- const button = currentCell.querySelector('button');
451
- const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]');
452
- if (autocomplete) {
453
- autocomplete.focus();
454
- (_a = autocomplete.select) === null || _a === void 0 ? void 0 : _a.call(autocomplete);
455
- }
456
- else if (input) {
457
- input.focus();
458
- (_b = input.select) === null || _b === void 0 ? void 0 : _b.call(input);
459
- }
460
- else if (select) {
461
- select.focus();
462
- }
463
- else if (checkbox) {
464
- checkbox.focus();
465
- // checkbox.click();
466
- }
467
- else if (button) {
468
- button.focus();
469
- }
470
- else {
471
- currentCell.focus();
472
- }
473
- }
474
- }
442
+ // alt + n
443
+ // if (event.altKey && event.key.toLocaleLowerCase() === 'n') {
444
+ // event.preventDefault();
445
+ // setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
446
+ // const currentCell = event.currentTarget;
447
+ // if (enableKeyboardShortcuts) {
448
+ // const input = currentCell.querySelector('input') as HTMLInputElement;
449
+ // const select = currentCell.querySelector('select') as HTMLSelectElement;
450
+ // const checkbox = currentCell.querySelector('input[type="checkbox"]') as HTMLInputElement;
451
+ // const button = currentCell.querySelector('button') as HTMLButtonElement;
452
+ // const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]') as HTMLInputElement;
453
+ // if (autocomplete) {
454
+ // autocomplete.focus();
455
+ // autocomplete.select?.();
456
+ // } else if (input) {
457
+ // input.focus();
458
+ // input.select?.();
459
+ // } else if (select) {
460
+ // select.focus();
461
+ // } else if (checkbox) {
462
+ // checkbox.focus();
463
+ // // checkbox.click();
464
+ // } else if (button) {
465
+ // button.focus();
466
+ // } else {
467
+ // currentCell.focus();
468
+ // }
469
+ // }
470
+ // }
471
+ // if (event.altKey && event.key.toLocaleLowerCase() === 'n') {
472
+ // event.preventDefault();
473
+ // setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
474
+ // }
475
475
  // if (!table.options.enableKeyboardShortcuts) return;
476
476
  if (!enableKeyboardShortcuts)
477
477
  return;
@@ -482,7 +482,7 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
482
482
  navigator.clipboard.writeText(cellValue);
483
483
  }
484
484
  else if (['Enter', ' '].includes(event.key)) {
485
- if (((_c = cell === null || cell === void 0 ? void 0 : cell.column) === null || _c === void 0 ? void 0 : _c.id) === 'mrt-row-select') {
485
+ if (((_a = cell === null || cell === void 0 ? void 0 : cell.column) === null || _a === void 0 ? void 0 : _a.id) === 'mrt-row-select') {
486
486
  event.preventDefault();
487
487
  getMRT_RowSelectionHandler({
488
488
  row: cell.row,
@@ -491,20 +491,20 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
491
491
  staticRowIndex: +event.target.getAttribute('data-index'),
492
492
  })(event);
493
493
  }
494
- else if (((_d = header === null || header === void 0 ? void 0 : header.column) === null || _d === void 0 ? void 0 : _d.id) === 'mrt-row-select' &&
494
+ else if (((_b = header === null || header === void 0 ? void 0 : header.column) === null || _b === void 0 ? void 0 : _b.id) === 'mrt-row-select' &&
495
495
  table.options.enableSelectAll) {
496
496
  event.preventDefault();
497
497
  getMRT_SelectAllHandler({
498
498
  table,
499
499
  })(event);
500
500
  }
501
- else if (((_e = cell === null || cell === void 0 ? void 0 : cell.column) === null || _e === void 0 ? void 0 : _e.id) === 'mrt-row-expand' &&
501
+ else if (((_c = cell === null || cell === void 0 ? void 0 : cell.column) === null || _c === void 0 ? void 0 : _c.id) === 'mrt-row-expand' &&
502
502
  (cell.row.getCanExpand() ||
503
- ((_g = (_f = table.options).renderDetailPanel) === null || _g === void 0 ? void 0 : _g.call(_f, { row: cell.row, table })))) {
503
+ ((_e = (_d = table.options).renderDetailPanel) === null || _e === void 0 ? void 0 : _e.call(_d, { row: cell.row, table })))) {
504
504
  event.preventDefault();
505
505
  cell.row.toggleExpanded();
506
506
  }
507
- else if (((_h = header === null || header === void 0 ? void 0 : header.column) === null || _h === void 0 ? void 0 : _h.id) === 'mrt-row-expand' &&
507
+ else if (((_f = header === null || header === void 0 ? void 0 : header.column) === null || _f === void 0 ? void 0 : _f.id) === 'mrt-row-expand' &&
508
508
  table.options.enableExpandAll) {
509
509
  event.preventDefault();
510
510
  table.toggleAllRowsExpanded();
@@ -513,7 +513,7 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
513
513
  event.preventDefault();
514
514
  cell.row.getIsPinned()
515
515
  ? cell.row.pin(false)
516
- : cell.row.pin(((_j = table.options.rowPinningDisplayMode) === null || _j === void 0 ? void 0 : _j.includes('bottom'))
516
+ : cell.row.pin(((_g = table.options.rowPinningDisplayMode) === null || _g === void 0 ? void 0 : _g.includes('bottom'))
517
517
  ? 'bottom'
518
518
  : 'top');
519
519
  }
@@ -523,7 +523,7 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
523
523
  actionsButton.click();
524
524
  }
525
525
  }
526
- else if ((_k = header === null || header === void 0 ? void 0 : header.column) === null || _k === void 0 ? void 0 : _k.getCanSort()) {
526
+ else if ((_h = header === null || header === void 0 ? void 0 : header.column) === null || _h === void 0 ? void 0 : _h.getCanSort()) {
527
527
  event.preventDefault();
528
528
  header.column.toggleSorting();
529
529
  }
@@ -538,11 +538,11 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
538
538
  // Focus the appropriate element
539
539
  if (autocomplete) {
540
540
  autocomplete.focus();
541
- (_l = autocomplete.select) === null || _l === void 0 ? void 0 : _l.call(autocomplete);
541
+ // autocomplete.select?.();
542
542
  }
543
543
  else if (input) {
544
544
  input.focus();
545
- (_m = input.select) === null || _m === void 0 ? void 0 : _m.call(input);
545
+ // input.select?.();
546
546
  }
547
547
  else if (select) {
548
548
  select.focus();
@@ -580,7 +580,6 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
580
580
  // }
581
581
  if (['ArrowDown', 'ArrowUp'].includes(event.key)) {
582
582
  const autocomplete = currentCell.querySelector('.MuiAutocomplete-root input[type="text"]');
583
- // Check if the autocomplete input exists and is focused
584
583
  if (autocomplete && document.activeElement === autocomplete) {
585
584
  if (event.key === 'ArrowDown') {
586
585
  // Do something with the autocomplete input
@@ -594,7 +593,6 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
594
593
  }
595
594
  }
596
595
  }
597
- // Additional logic if not an Autocomplete or not focused
598
596
  }
599
597
  const currentRow = parentElement || currentCell.closest('tr');
600
598
  const tableElement = containerElement || currentCell.closest('table');
@@ -631,6 +629,11 @@ const cellKeyboardShortcuts = ({ cell, cellElements, cellValue, containerElement
631
629
  : allCells.slice(0, currentCellIndex).reverse();
632
630
  return searchArray.find((cell) => cell.matches(`[data-index="${columnIndex}"]`));
633
631
  };
632
+ // const findCurrentCell = () => {
633
+ // return allCells.find((cell) =>
634
+ // cell.matches(`[data-index="${currentIndex}"]`),
635
+ // );
636
+ // }
634
637
  switch (event.key) {
635
638
  case 'ArrowRight':
636
639
  nextCell = findAdjacentCell(currentIndex + 1, 'f');
@@ -4170,7 +4173,9 @@ const MRT_ShowHideColumnsMenuItems = (_a) => {
4170
4173
 
4171
4174
  const MRT_ShowHideColumnsMenu = (_a) => {
4172
4175
  var { anchorEl, setAnchorEl, table } = _a, rest = __rest(_a, ["anchorEl", "setAnchorEl", "table"]);
4173
- const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, options: { enableColumnOrdering, enableColumnPinning, enableHiding, localization, enableColumnResizing, mrtTheme: { menuBackgroundColor }, }, } = table;
4176
+ const { getAllColumns, getAllLeafColumns, getCenterLeafColumns, getIsAllColumnsVisible, getIsSomeColumnsPinned, getIsSomeColumnsVisible, getLeftLeafColumns, getRightLeafColumns, getState, options: { enableColumnOrdering, enableColumnPinning, enableHiding, localization,
4177
+ // enableColumnResizing,
4178
+ mrtTheme: { menuBackgroundColor }, }, } = table;
4174
4179
  const { columnOrder, columnPinning, density } = getState();
4175
4180
  const handleToggleAllColumns = (value) => {
4176
4181
  getAllLeafColumns()
@@ -4208,9 +4213,7 @@ const MRT_ShowHideColumnsMenu = (_a) => {
4208
4213
  justifyContent: 'space-between',
4209
4214
  p: '0.5rem',
4210
4215
  pt: 0,
4211
- }, children: [enableHiding && (jsx(Button, { disabled: !getIsSomeColumnsVisible(), onClick: () => handleToggleAllColumns(false), children: localization.hideAll })), enableColumnOrdering && (jsx(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options, true)), children: localization.resetOrder })), enableColumnPinning && (jsx(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true), children: localization.unpinAll })), enableHiding && (jsx(Button, { disabled: getIsAllColumnsVisible(), onClick: () => handleToggleAllColumns(true), children: localization.showAll })), enableColumnResizing && (jsx(Button, { onClick: () => {
4212
- table.resetColumnSizing(true);
4213
- }, children: localization.resetColumnSize }))] }), jsx(Divider, {}), allColumns.map((column, index) => (jsx(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, isNestedColumns: isNestedColumns, setHoveredColumn: setHoveredColumn, table: table }, `${index}-${column.id}`)))] })));
4216
+ }, children: [enableHiding && (jsx(Button, { disabled: !getIsSomeColumnsVisible(), onClick: () => handleToggleAllColumns(false), children: localization.hideAll })), enableColumnOrdering && (jsx(Button, { onClick: () => table.setColumnOrder(getDefaultColumnOrderIds(table.options, true)), children: localization.resetOrder })), enableColumnPinning && (jsx(Button, { disabled: !getIsSomeColumnsPinned(), onClick: () => table.resetColumnPinning(true), children: localization.unpinAll })), enableHiding && (jsx(Button, { disabled: getIsAllColumnsVisible(), onClick: () => handleToggleAllColumns(true), children: localization.showAll }))] }), jsx(Divider, {}), allColumns.map((column, index) => (jsx(MRT_ShowHideColumnsMenuItems, { allColumns: allColumns, column: column, hoveredColumn: hoveredColumn, isNestedColumns: isNestedColumns, setHoveredColumn: setHoveredColumn, table: table }, `${index}-${column.id}`)))] })));
4214
4217
  };
4215
4218
 
4216
4219
  const MRT_ShowHideColumnsButton = (_a) => {
@@ -4276,17 +4279,30 @@ const MRT_ToggleGlobalFilterButton = (_a) => {
4276
4279
  return (jsx(Tooltip, { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.showHideSearch, children: jsx(IconButton, Object.assign({ "aria-label": (_c = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _c !== void 0 ? _c : localization.showHideSearch, disabled: !!globalFilter, onClick: handleToggleSearch }, rest, { title: undefined, children: showGlobalFilter ? jsx(SearchOffIcon, {}) : jsx(SearchIcon, {}) })) }));
4277
4280
  };
4278
4281
 
4282
+ const MRT_ToggleNavigationButton = (_a) => {
4283
+ var _b;
4284
+ var { table } = _a, rest = __rest(_a, ["table"]);
4285
+ const { getState, options: { icons: { FullscreenExitIcon, FullscreenIcon }, localization, }, setEnableKeyboardShortcuts, } = table;
4286
+ const { enableKeyboardShortcuts } = getState();
4287
+ const [tooltipOpened, setTooltipOpened] = useState(false);
4288
+ const handleToggleFullScreen = () => {
4289
+ setTooltipOpened(false);
4290
+ setEnableKeyboardShortcuts(!enableKeyboardShortcuts);
4291
+ };
4292
+ return (jsx(Tooltip, { open: tooltipOpened, title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.keyboardNavigation, children: jsx(IconButton, Object.assign({ "aria-label": localization.keyboardNavigation, onClick: handleToggleFullScreen, onMouseEnter: () => setTooltipOpened(true), onMouseLeave: () => setTooltipOpened(false) }, rest, { title: undefined, children: enableKeyboardShortcuts ? jsx(FullscreenExitIcon, {}) : jsx(FullscreenIcon, {}) })) }));
4293
+ };
4294
+
4279
4295
  const MRT_ToolbarInternalButtons = (_a) => {
4280
4296
  var _b;
4281
4297
  var { table } = _a, rest = __rest(_a, ["table"]);
4282
- const { options: { columnFilterDisplayMode, enableColumnFilters, enableColumnOrdering, enableColumnPinning, enableDensityToggle, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableHiding, initialState, renderToolbarInternalActions, }, } = table;
4298
+ const { options: { columnFilterDisplayMode, enableColumnFilters, enableColumnOrdering, enableColumnPinning, enableDensityToggle, enableFilters, enableFullScreenToggle, enableGlobalFilter, enableHiding, initialState, renderToolbarInternalActions, enableKeyboardShortcuts }, } = table;
4283
4299
  return (jsx(Box, Object.assign({}, rest, { sx: (theme) => (Object.assign({ alignItems: 'center', display: 'flex', zIndex: 3 }, parseFromValuesOrFunc(rest === null || rest === void 0 ? void 0 : rest.sx, theme))), children: (_b = renderToolbarInternalActions === null || renderToolbarInternalActions === void 0 ? void 0 : renderToolbarInternalActions({
4284
4300
  table,
4285
4301
  })) !== null && _b !== void 0 ? _b : (jsxs(Fragment, { children: [enableFilters &&
4286
4302
  enableGlobalFilter &&
4287
4303
  !(initialState === null || initialState === void 0 ? void 0 : initialState.showGlobalFilter) && (jsx(MRT_ToggleGlobalFilterButton, { table: table })), enableFilters &&
4288
4304
  enableColumnFilters &&
4289
- columnFilterDisplayMode !== 'popover' && (jsx(MRT_ToggleFiltersButton, { table: table })), (enableHiding || enableColumnOrdering || enableColumnPinning) && (jsx(MRT_ShowHideColumnsButton, { table: table })), enableDensityToggle && (jsx(MRT_ToggleDensePaddingButton, { table: table })), enableFullScreenToggle && (jsx(MRT_ToggleFullScreenButton, { table: table }))] })) })));
4305
+ columnFilterDisplayMode !== 'popover' && (jsx(MRT_ToggleFiltersButton, { table: table })), (enableHiding || enableColumnOrdering || enableColumnPinning) && (jsx(MRT_ShowHideColumnsButton, { table: table })), enableDensityToggle && (jsx(MRT_ToggleDensePaddingButton, { table: table })), enableFullScreenToggle && (jsx(MRT_ToggleFullScreenButton, { table: table })), enableKeyboardShortcuts && (jsx(MRT_ToggleNavigationButton, { table: table }))] })) })));
4290
4306
  };
4291
4307
 
4292
4308
  const MRT_GlobalFilterTextField = (_a) => {