@apia/table 3.0.9 → 3.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -266,6 +266,7 @@ type TResponsiveTableContextProps = TResponsiveTableStoreProps & Pick<ISelectabl
266
266
  * en true**, este comportamiento es deshabilitado.
267
267
  */
268
268
  avoidReparseSelectionOnRowChange?: boolean;
269
+ avoidAutoEllipsis?: boolean;
269
270
  children?: React__default.ReactNode;
270
271
  className?: string;
271
272
  /**
@@ -298,6 +299,10 @@ type TResponsiveTableContextProps = TResponsiveTableStoreProps & Pick<ISelectabl
298
299
  * filas no vacía y presione la tecla Enter.
299
300
  */
300
301
  onSelectRows?: (ev: TResponsiveTableRowsSelectionEvent, focusedRowIndex: number) => unknown;
302
+ /**
303
+ * Este evento será llamado cada vez que el usuario haga click en una fila
304
+ */
305
+ onRowClick?: (ev: TResponsiveTableRowsSelectionEvent[0], focusedRowIndex: number) => unknown;
301
306
  /**
302
307
  * Es llamado cada vez que el usuario hace click en el botón
303
308
  * del cabezal de la columna. **Importante:** la tabla no
@@ -319,7 +324,7 @@ type TResponsiveTableContextProps = TResponsiveTableStoreProps & Pick<ISelectabl
319
324
  * desee informar de un evento en particular
320
325
  * pueda hacerlo en forma sencilla.
321
326
  */
322
- type TResponsiveTableContext = TModify<Pick<TResponsiveTableContextProps, 'currentBreakPoint' | 'name' | 'onChangeSelection' | 'onFilterBlur' | 'onFilterChange' | 'onFilterPressEnter' | 'onSelectRows' | 'onSortChange' | 'label' | 'SelectionHandler'>, {
327
+ type TResponsiveTableContext = TModify<Pick<TResponsiveTableContextProps, 'avoidAutoEllipsis' | 'currentBreakPoint' | 'name' | 'onChangeSelection' | 'onFilterBlur' | 'onFilterChange' | 'onFilterPressEnter' | 'onSelectRows' | 'onRowClick' | 'onSortChange' | 'label' | 'SelectionHandler'>, {
323
328
  labels: typeof defaultLabels;
324
329
  name: string;
325
330
  }>;
@@ -516,6 +521,7 @@ type TKeyHandlerProps = BoxProps & {
516
521
  * la selección actual.
517
522
  */
518
523
  onChangeSelection?: (newRows: TResponsiveTableRowsSelectionEvent) => unknown;
524
+ onRowClick?: (row: TResponsiveTableRowsSelectionEvent[0], focusedIndex: number) => unknown;
519
525
  onSelectRows?: (newRows: TResponsiveTableRowsSelectionEvent, focusedIndex: number) => unknown;
520
526
  };
521
527
 
@@ -576,7 +582,7 @@ interface IPagination {
576
582
  declare const Pagination: React__default.MemoExoticComponent<({ appliedFilters, areAllFiltersApplied, className, currentPage, disabled, disableReduced, hasMore, hideMaximizeButton, hideRefreshButton, isLoading, isPerforming, listId: outerListId, onDeleteFilters, onPageChange, onRefresh, pageCount, recordsCount: outerRecordsCount, reachedMax, showMaximizeOnSmallBreakpoints, variant, }: IPagination) => React__default.JSX.Element>;
577
583
 
578
584
  declare function useResponsiveTableContext(tableName?: string): TResponsiveTableContext;
579
- declare const ResponsiveTableContext: React__default.MemoExoticComponent<({ allowEdition, allowRowsKeyboardSorting, allowSelection, allowSorting, avoidReparseSelectionOnRowChange, children, className, currentBreakPoint, customLabels, columns, filters, rows, label, isMultiple, name, onChangeSelection, onFilterBlur, onFilterChange, onFilterPressEnter, onSelectRows, onSortChange, reserveColumnsForStates, SelectionHandler, variant, }: TResponsiveTableContextProps) => React__default.JSX.Element>;
585
+ declare const ResponsiveTableContext: React__default.MemoExoticComponent<({ allowEdition, allowRowsKeyboardSorting, avoidAutoEllipsis, allowSelection, allowSorting, avoidReparseSelectionOnRowChange, children, className, currentBreakPoint, customLabels, columns, filters, rows, label, isMultiple, name, onChangeSelection, onFilterBlur, onFilterChange, onFilterPressEnter, onRowClick, onSelectRows, onSortChange, reserveColumnsForStates, SelectionHandler, variant, }: TResponsiveTableContextProps) => React__default.JSX.Element>;
580
586
 
581
587
  type TypedUseSelectorHook<TState> = <TSelected>(selector: (state: TState) => TSelected, equalityFn?: (a: TSelected, b: TSelected) => boolean) => TSelected;
582
588
  declare const responsiveTableStore: _reduxjs_toolkit_dist_configureStore.ToolkitStore<{
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { jsx, jsxs, Fragment } from '@apia/theme/jsx-runtime';
2
- import React, { useMemo, useState, useRef, memo, useEffect, useCallback, createRef, forwardRef } from 'react';
3
- import { Box, getVariant, Input, useBreakpointIndex, Label, Select, Link, Spinner } from '@apia/theme';
2
+ import React, { useMemo, useRef, useState, memo, useEffect, useCallback, createRef, forwardRef } from 'react';
3
+ import { Box, getVariant, Input, Select, useBreakpointIndex, Label, Link, Spinner } from '@apia/theme';
4
4
  import { useMount, useUpdateEffect, useUnmount, useThrottleFn } from 'ahooks';
5
5
  import uniqueId from 'lodash-es/uniqueId';
6
6
  import { createSlice, injectReducers, shallowEqual as shallowEqual$1 } from '@apia/store';
7
- import { addBoundary, useLatest, useUpdateEffect as useUpdateEffect$1, getSpecificParent, isChild, autoDisconnectMutationObserver, getFocusSelector, cantFocusSelector, globalFocus, scrollParentIntoElement, customEvents, debugDispatcher, persistentStorage, EventEmitter, getLabel, getDateFormat, formatMessage, noNaN, downloadUrl, arrayOrArray, useMount as useMount$1 } from '@apia/util';
7
+ import { addBoundary, useLatest, useUpdateEffect as useUpdateEffect$1, getSpecificParent, isChild, autoDisconnectMutationObserver, getFocusSelector, cantFocusSelector, globalFocus, scrollParentIntoElement, customEvents, debugDispatcher, persistentStorage, EventEmitter, usePrevious, useIntermediateValue, getLabel, getDateFormat, formatMessage, noNaN, downloadUrl, arrayOrArray, useMount as useMount$1 } from '@apia/util';
8
8
  import { shallowEqual } from 'react-redux';
9
9
  import { useOtherTagButton, AutoEllipsis, ApiaFilter, IconButton, AccordionItem, Accordion, RequiredMark, ApiaUtil, SimpleButton } from '@apia/components';
10
10
  import { Icon } from '@apia/icons';
@@ -458,6 +458,7 @@ function useResponsiveTableContext(tableName) {
458
458
  const NoMemoResponsiveTableContext = ({
459
459
  allowEdition,
460
460
  allowRowsKeyboardSorting,
461
+ avoidAutoEllipsis,
461
462
  allowSelection,
462
463
  allowSorting,
463
464
  avoidReparseSelectionOnRowChange,
@@ -475,6 +476,7 @@ const NoMemoResponsiveTableContext = ({
475
476
  onFilterBlur,
476
477
  onFilterChange,
477
478
  onFilterPressEnter,
479
+ onRowClick,
478
480
  onSelectRows,
479
481
  onSortChange,
480
482
  reserveColumnsForStates,
@@ -494,24 +496,28 @@ const NoMemoResponsiveTableContext = ({
494
496
  currentBreakPoint,
495
497
  label,
496
498
  labels,
499
+ avoidAutoEllipsis,
497
500
  name: actualName,
498
501
  onChangeSelection,
499
502
  onFilterBlur,
500
503
  onFilterChange,
501
504
  onFilterPressEnter,
505
+ onRowClick,
502
506
  onSelectRows,
503
507
  onSortChange,
504
508
  SelectionHandler
505
509
  }),
506
510
  [
507
- actualName,
508
511
  currentBreakPoint,
509
512
  label,
510
513
  labels,
514
+ avoidAutoEllipsis,
515
+ actualName,
511
516
  onChangeSelection,
512
517
  onFilterBlur,
513
518
  onFilterChange,
514
519
  onFilterPressEnter,
520
+ onRowClick,
515
521
  onSelectRows,
516
522
  onSortChange,
517
523
  SelectionHandler
@@ -593,6 +599,7 @@ function makeKeyHandler(actions, id, config) {
593
599
  return function KeyHandler({
594
600
  children,
595
601
  onChangeSelection,
602
+ onRowClick: onClickRows,
596
603
  onSelectRows,
597
604
  ...props
598
605
  }) {
@@ -673,9 +680,14 @@ function makeKeyHandler(actions, id, config) {
673
680
  shiftKey: ev.shiftKey
674
681
  })
675
682
  );
683
+ if (onClickRows && ev.type === "mousedown")
684
+ onClickRows(
685
+ selectedRowsRef.current?.[0],
686
+ config.stateSelector(responsiveTableStore.getState()).focusedRow
687
+ );
676
688
  }
677
689
  },
678
- []
690
+ [onClickRows, selectedRowsRef]
679
691
  );
680
692
  const handleDoubleClick = React.useCallback(
681
693
  (ev) => {
@@ -905,7 +917,13 @@ function makeKeyHandler(actions, id, config) {
905
917
  }
906
918
 
907
919
  const NoMemoKeyHandler = (props) => {
908
- const { name, onChangeSelection, onSelectRows, SelectionHandler } = useResponsiveTableContext();
920
+ const {
921
+ name,
922
+ onChangeSelection,
923
+ onRowClick,
924
+ onSelectRows,
925
+ SelectionHandler
926
+ } = useResponsiveTableContext();
909
927
  const Handler = React.useMemo(
910
928
  () => SelectionHandler || makeKeyHandler(responsiveTableActions, name, {
911
929
  throttleOptions: { wait: 50 },
@@ -918,6 +936,7 @@ const NoMemoKeyHandler = (props) => {
918
936
  {
919
937
  onChangeSelection,
920
938
  onSelectRows,
939
+ onRowClick,
921
940
  ...props
922
941
  }
923
942
  );
@@ -1370,60 +1389,134 @@ const StateCell = ({ index, rowIndex, state, isHeader }) => {
1370
1389
  return /* @__PURE__ */ jsx(Box, { as: "td", className: "stateCell", ...domProps, children: state ? /* @__PURE__ */ jsx(RowStatesRenderer, { state }) : "" });
1371
1390
  };
1372
1391
 
1392
+ const units = ["B", "KB", "MB", "GB"];
1373
1393
  const NoMemoRangeFilter = ({
1374
1394
  filter,
1375
- tableName
1395
+ tableName,
1396
+ className
1376
1397
  }) => {
1377
1398
  const { onFilterBlur, onFilterChange, onFilterPressEnter } = useResponsiveTableContext(tableName);
1378
1399
  const filterLow = {
1379
- id: filter.id,
1400
+ ...filter,
1401
+ changeFiltersTimestamp: filter.changeFiltersTimestamp,
1380
1402
  currentValue: filter.currentValue,
1381
- type: "number"
1403
+ deleteFiltersTimestamp: filter.deleteFiltersTimestamp,
1404
+ id: filter.id,
1405
+ toolTip: filter.toolTip,
1406
+ type: "apiaNumber"
1382
1407
  };
1383
- const filterHigh = {
1384
- id: filter.filterToId ?? "",
1385
- currentValue: filter.filterToValue ?? "",
1386
- type: "number"
1408
+ const multiplier = useRef(1);
1409
+ const lastEmittedHigh = useRef(null);
1410
+ const lastEmittedLow = useRef(null);
1411
+ const lastEmittedMultiplier = useRef(1);
1412
+ const previousChangeTimestamp = usePrevious(filter.changeFiltersTimestamp);
1413
+ const previousDeleteTimestamp = usePrevious(filter.deleteFiltersTimestamp);
1414
+ if (previousChangeTimestamp.current !== filter.changeFiltersTimestamp) {
1415
+ lastEmittedLow.current = filterLow.currentValue;
1416
+ lastEmittedHigh.current = filterLow.filterToValue || "";
1417
+ }
1418
+ if (previousDeleteTimestamp.current !== filter.deleteFiltersTimestamp) {
1419
+ lastEmittedLow.current = "";
1420
+ lastEmittedHigh.current = "";
1421
+ }
1422
+ const emitLow = (method, currentValue) => {
1423
+ const numberValue = currentValue ?? "";
1424
+ if (lastEmittedLow.current === numberValue && lastEmittedMultiplier.current === multiplier.current) {
1425
+ return;
1426
+ }
1427
+ lastEmittedLow.current = numberValue;
1428
+ lastEmittedMultiplier.current = multiplier.current;
1429
+ const emitValue = numberValue;
1430
+ void method?.({
1431
+ ...filterLow,
1432
+ currentValue: emitValue,
1433
+ filterToValue: lastEmittedHigh.current ?? "",
1434
+ sizeMultiplier: multiplier.current
1435
+ });
1387
1436
  };
1388
- return /* @__PURE__ */ jsxs(Box, { className: "ApiaFilter__Range", children: [
1389
- /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__Low", children: /* @__PURE__ */ jsx(
1390
- ApiaFilter,
1391
- {
1392
- filter: filterLow,
1393
- onChange: (currentValue) => {
1394
- if (onFilterChange)
1395
- void onFilterChange({ ...filterLow, currentValue });
1396
- },
1397
- onBlur: (currentValue) => {
1398
- if (onFilterBlur)
1399
- void onFilterBlur({ ...filterLow, currentValue });
1400
- },
1401
- onPressEnter: (currentValue) => {
1402
- if (onFilterPressEnter)
1403
- void onFilterPressEnter({ ...filterLow, currentValue });
1404
- }
1405
- }
1406
- ) }),
1407
- " - ",
1408
- /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__High", children: /* @__PURE__ */ jsx(
1409
- ApiaFilter,
1410
- {
1411
- filter: filterHigh,
1412
- onChange: (currentValue) => {
1413
- if (onFilterChange)
1414
- void onFilterChange({ ...filterHigh, currentValue });
1415
- },
1416
- onBlur: (currentValue) => {
1417
- if (onFilterBlur)
1418
- void onFilterBlur({ ...filterHigh, currentValue });
1419
- },
1420
- onPressEnter: (currentValue) => {
1421
- if (onFilterPressEnter)
1422
- void onFilterPressEnter({ ...filterHigh, currentValue });
1423
- }
1424
- }
1425
- ) })
1426
- ] });
1437
+ const emitHigh = (method, currentValue) => {
1438
+ const numberValue = currentValue ?? "";
1439
+ if (lastEmittedHigh.current === numberValue && lastEmittedMultiplier.current === multiplier.current) {
1440
+ return;
1441
+ }
1442
+ lastEmittedHigh.current = numberValue;
1443
+ lastEmittedMultiplier.current = multiplier.current;
1444
+ const emitValue = numberValue;
1445
+ void method?.({
1446
+ ...filterLow,
1447
+ currentValue: lastEmittedLow.current ?? "",
1448
+ filterToValue: emitValue,
1449
+ sizeMultiplier: multiplier.current
1450
+ });
1451
+ };
1452
+ const [lowValue, setLowValue] = useIntermediateValue(filterLow.currentValue);
1453
+ const [highValue, setHighValue] = useIntermediateValue(
1454
+ filterLow.filterToValue
1455
+ );
1456
+ const [unit, setUnit] = useIntermediateValue(filterLow.sizeMultiplier);
1457
+ return /* @__PURE__ */ jsxs(
1458
+ Box,
1459
+ {
1460
+ className: `ApiaFilter__Range ${className || ""}`,
1461
+ ...getVariant("layout.common.filters.rangeFilter"),
1462
+ children: [
1463
+ /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__Low", children: /* @__PURE__ */ jsx(
1464
+ Input,
1465
+ {
1466
+ onChange: ({ target: { value: currentValue } }) => {
1467
+ setLowValue(currentValue);
1468
+ emitLow(onFilterChange, currentValue);
1469
+ },
1470
+ onBlur: ({ target: { value: currentValue } }) => {
1471
+ emitLow(onFilterBlur, currentValue);
1472
+ },
1473
+ onKeyDown: ({ code, target }) => {
1474
+ if (code === "Enter") {
1475
+ emitLow(onFilterPressEnter, target.value);
1476
+ }
1477
+ },
1478
+ value: lowValue
1479
+ }
1480
+ ) }),
1481
+ " - ",
1482
+ /* @__PURE__ */ jsx(Box, { className: "ApiaFilter__Range__High", children: /* @__PURE__ */ jsx(
1483
+ Input,
1484
+ {
1485
+ onChange: ({ target: { value: currentValue } }) => {
1486
+ setHighValue(currentValue);
1487
+ emitHigh(onFilterChange, currentValue);
1488
+ },
1489
+ onBlur: ({ target: { value: currentValue } }) => {
1490
+ emitHigh(onFilterBlur, currentValue);
1491
+ },
1492
+ onKeyDown: ({ code, target }) => {
1493
+ if (code === "Enter") {
1494
+ emitHigh(onFilterPressEnter, target.value);
1495
+ }
1496
+ },
1497
+ value: highValue
1498
+ }
1499
+ ) }),
1500
+ filter.isSize && /* @__PURE__ */ jsx(
1501
+ Select,
1502
+ {
1503
+ className: "ApiaFilter__Range__UnitSelector",
1504
+ onChange: (ev) => {
1505
+ const unit2 = ev.target.value;
1506
+ const index = units.indexOf(unit2);
1507
+ if (index !== -1) {
1508
+ multiplier.current = 2 ** (index * 10);
1509
+ setUnit(multiplier.current);
1510
+ emitLow(onFilterChange, lastEmittedLow.current ?? "");
1511
+ }
1512
+ },
1513
+ value: units[Math.log2(unit || 1) / 10],
1514
+ children: units.map((c) => /* @__PURE__ */ jsx("option", { value: c, children: c }, c))
1515
+ }
1516
+ )
1517
+ ]
1518
+ }
1519
+ );
1427
1520
  };
1428
1521
  const RangeFilter = NoMemoRangeFilter;
1429
1522
 
@@ -1704,38 +1797,41 @@ const NoMemoDefaultCellRenderer = React.forwardRef(
1704
1797
  column,
1705
1798
  row,
1706
1799
  ...props
1707
- }, currentRef) => /* @__PURE__ */ jsx(
1708
- Box,
1709
- {
1710
- as: "td",
1711
- sx: useMemo(
1712
- () => ({
1713
- "&.colored": {
1714
- background: cell.background,
1715
- color: cell.color,
1716
- fontWeight: "bold"
1800
+ }, currentRef) => {
1801
+ const { avoidAutoEllipsis } = useResponsiveTableContext();
1802
+ return /* @__PURE__ */ jsx(
1803
+ Box,
1804
+ {
1805
+ as: "td",
1806
+ sx: useMemo(
1807
+ () => ({
1808
+ "&.colored": {
1809
+ background: cell.background,
1810
+ color: cell.color,
1811
+ fontWeight: "bold"
1812
+ }
1813
+ }),
1814
+ [cell.background, cell.color]
1815
+ ),
1816
+ ref: currentRef,
1817
+ ...props,
1818
+ ...cell,
1819
+ "aria-label": ariaLabel,
1820
+ children: !avoidAutoEllipsis ? /* @__PURE__ */ jsx(
1821
+ AutoEllipsis,
1822
+ {
1823
+ overrideStyles: (el) => {
1824
+ const td = el.closest("td");
1825
+ return {
1826
+ width: window.getComputedStyle(td).width
1827
+ };
1828
+ },
1829
+ children: props.children ?? cell.children
1717
1830
  }
1718
- }),
1719
- [cell.background, cell.color]
1720
- ),
1721
- ref: currentRef,
1722
- ...props,
1723
- ...cell,
1724
- "aria-label": ariaLabel,
1725
- children: /* @__PURE__ */ jsx(
1726
- AutoEllipsis,
1727
- {
1728
- overrideStyles: (el) => {
1729
- const td = el.closest("td");
1730
- return {
1731
- width: window.getComputedStyle(td).width
1732
- };
1733
- },
1734
- children: props.children ?? cell.children
1735
- }
1736
- )
1737
- }
1738
- )
1831
+ ) : props.children ?? cell.children
1832
+ }
1833
+ );
1834
+ }
1739
1835
  );
1740
1836
  NoMemoDefaultCellRenderer.displayName = "DefaultCellRenderer";
1741
1837
  const DefaultCellRenderer = NoMemoDefaultCellRenderer;
@@ -2874,7 +2970,6 @@ function applyFocusAttributes(table, _previousState, state, focus = state.isFocu
2874
2970
  const focusedCell = table.querySelector(
2875
2971
  `tr[data-rowindex="${state.focusedRow}"] td[aria-colindex="${state.focusedColumn}"], tr[data-rowindex="${state.focusedRow}"] th[aria-colindex="${state.focusedColumn}"]`
2876
2972
  );
2877
- console.log(focusedCell);
2878
2973
  if (focusedCell instanceof HTMLElement) {
2879
2974
  const widgets = [];
2880
2975
  if (state.isEditionMode) {
@@ -2888,7 +2983,6 @@ function applyFocusAttributes(table, _previousState, state, focus = state.isFocu
2888
2983
  }
2889
2984
  }
2890
2985
  if (widgets.length) {
2891
- console.log(widgets);
2892
2986
  widgets.forEach((widget, i) => {
2893
2987
  widget.tabIndex = 0;
2894
2988
  if (i === 0)