@economic/taco 2.33.1 → 2.34.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. package/dist/components/Icon/components/DocumentSigned.d.ts +3 -0
  2. package/dist/components/Icon/components/Home2.d.ts +3 -0
  3. package/dist/components/Icon/components/Id.d.ts +3 -0
  4. package/dist/components/Icon/components/MastercardOs.d.ts +3 -0
  5. package/dist/components/Icon/components/NovemberFirst.d.ts +3 -0
  6. package/dist/components/Icon/components/index.d.ts +1 -1
  7. package/dist/components/Input/Input.d.ts +1 -1
  8. package/dist/components/Menu/components/Item.d.ts +1 -1
  9. package/dist/components/Menu/components/Link.d.ts +1 -1
  10. package/dist/components/Navigation2/components/Link.d.ts +1 -1
  11. package/dist/components/Select2/components/Option.d.ts +2 -2
  12. package/dist/components/Select2/components/Search.d.ts +1 -1
  13. package/dist/components/Table3/components/Columns/Internal/EditingActionsMenu.d.ts +1 -0
  14. package/dist/components/Table3/features/useTableEditing.d.ts +0 -1
  15. package/dist/components/Table3/listeners/useTableEditingListener.d.ts +3 -1
  16. package/dist/components/Tag/Tag.d.ts +1 -1
  17. package/dist/esm/index.css +4 -4
  18. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js +4 -5
  19. package/dist/esm/packages/taco/src/components/Combobox/useCombobox.js.map +1 -1
  20. package/dist/esm/packages/taco/src/components/Icon/components/DocumentSigned.js +19 -0
  21. package/dist/esm/packages/taco/src/components/Icon/components/DocumentSigned.js.map +1 -0
  22. package/dist/esm/packages/taco/src/components/Icon/components/Home2.js +19 -0
  23. package/dist/esm/packages/taco/src/components/Icon/components/Home2.js.map +1 -0
  24. package/dist/esm/packages/taco/src/components/Icon/components/Id.js +19 -0
  25. package/dist/esm/packages/taco/src/components/Icon/components/Id.js.map +1 -0
  26. package/dist/esm/packages/taco/src/components/Icon/components/MastercardOs.js +23 -0
  27. package/dist/esm/packages/taco/src/components/Icon/components/MastercardOs.js.map +1 -0
  28. package/dist/esm/packages/taco/src/components/Icon/components/NovemberFirst.js +20 -0
  29. package/dist/esm/packages/taco/src/components/Icon/components/NovemberFirst.js.map +1 -0
  30. package/dist/esm/packages/taco/src/components/Icon/components/index.js +10 -0
  31. package/dist/esm/packages/taco/src/components/Icon/components/index.js.map +1 -1
  32. package/dist/esm/packages/taco/src/components/Input/Input.js +5 -0
  33. package/dist/esm/packages/taco/src/components/Input/Input.js.map +1 -1
  34. package/dist/esm/packages/taco/src/components/Menu/components/Trigger.js +9 -7
  35. package/dist/esm/packages/taco/src/components/Menu/components/Trigger.js.map +1 -1
  36. package/dist/esm/packages/taco/src/components/Select2/Select2.js +3 -1
  37. package/dist/esm/packages/taco/src/components/Select2/Select2.js.map +1 -1
  38. package/dist/esm/packages/taco/src/components/Table3/Table3.js +1 -7
  39. package/dist/esm/packages/taco/src/components/Table3/Table3.js.map +1 -1
  40. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/Editing/RowMoveIndicator.js +1 -1
  41. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/Editing/RowMoveIndicator.js.map +1 -1
  42. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js +3 -1
  43. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Cell/EditingControlCell.js.map +1 -1
  44. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js +9 -1
  45. package/dist/esm/packages/taco/src/components/Table3/components/Columns/Internal/EditingActionsMenu.js.map +1 -1
  46. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js +1 -1
  47. package/dist/esm/packages/taco/src/components/Table3/components/Row/Row.js.map +1 -1
  48. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js +1 -13
  49. package/dist/esm/packages/taco/src/components/Table3/features/useTableEditing.js.map +1 -1
  50. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js +16 -1
  51. package/dist/esm/packages/taco/src/components/Table3/listeners/useTableEditingListener.js.map +1 -1
  52. package/dist/esm/packages/taco/src/components/Table3/useTable3.js +3 -2
  53. package/dist/esm/packages/taco/src/components/Table3/useTable3.js.map +1 -1
  54. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js +2 -1
  55. package/dist/esm/packages/taco/src/primitives/Table/Core/Table.js.map +1 -1
  56. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Body/Body.js +21 -1
  57. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Body/Body.js.map +1 -1
  58. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js +1 -2
  59. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Row/BuiltIns/DisplayRow.js.map +1 -1
  60. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/Filter.js +12 -3
  61. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/Filter.js.map +1 -1
  62. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterComparator.js +3 -47
  63. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterComparator.js.map +1 -1
  64. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/util.js +44 -1
  65. package/dist/esm/packages/taco/src/primitives/Table/Core/components/Toolbar/components/Filters/util.js.map +1 -1
  66. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js +1 -1
  67. package/dist/esm/packages/taco/src/primitives/Table/Core/features/useTableRenderer.js.map +1 -1
  68. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js +5 -5
  69. package/dist/esm/packages/taco/src/primitives/Table/useTableManager/features/useTableRowActive.js.map +1 -1
  70. package/dist/esm/packages/taco/src/utils/dom.js +4 -1
  71. package/dist/esm/packages/taco/src/utils/dom.js.map +1 -1
  72. package/dist/index.css +4 -4
  73. package/dist/primitives/Table/Core/components/Body/Body.d.ts +2 -0
  74. package/dist/primitives/Table/Core/components/Toolbar/components/Filters/util.d.ts +2 -1
  75. package/dist/taco.cjs.development.js +221 -97
  76. package/dist/taco.cjs.development.js.map +1 -1
  77. package/dist/taco.cjs.production.min.js +1 -1
  78. package/dist/taco.cjs.production.min.js.map +1 -1
  79. package/dist/utils/dom.d.ts +1 -0
  80. package/package.json +2 -2
@@ -2,6 +2,7 @@ import React__default from 'react';
2
2
  import { IconButton } from '../../../../../../../../components/IconButton/IconButton.js';
3
3
  import { useLocalization } from '../../../../../../../../components/Provider/Localization.js';
4
4
  import { TableFilterComparator } from '../../../../../../types.js';
5
+ import { guessComparatorsBasedOnControl } from '../util.js';
5
6
  import { FilterColumn } from './FilterColumn.js';
6
7
  import { FilterComparator } from './FilterComparator.js';
7
8
  import { FilterValue } from './FilterValue.js';
@@ -28,14 +29,22 @@ function Filter(props) {
28
29
  }
29
30
  } = filter;
30
31
  const handleChangeColumn = columnId => {
31
- var _previousColumn$colum, _nextColumn$columnDef;
32
+ var _previousColumn$colum, _previousColumn$colum2, _nextColumn$columnDef;
32
33
  const previousColumn = allColumns.find(column => column.id === id);
33
34
  const nextColumn = allColumns.find(column => column.id === columnId);
34
35
  // UX requirement: if old column data type is the same as next column data type,
35
36
  // then we applying the same filter value for the next column,
36
37
  // but when data types are different, we're reseting comparator ans value for the next column
37
- const value = (previousColumn === null || previousColumn === void 0 ? void 0 : (_previousColumn$colum = previousColumn.columnDef.meta) === null || _previousColumn$colum === void 0 ? void 0 : _previousColumn$colum.dataType) === (nextColumn === null || nextColumn === void 0 ? void 0 : (_nextColumn$columnDef = nextColumn.columnDef.meta) === null || _nextColumn$columnDef === void 0 ? void 0 : _nextColumn$columnDef.dataType) ? filter.value : {
38
- comparator: TableFilterComparator.Contains,
38
+ if (previousColumn !== null && previousColumn !== void 0 && (_previousColumn$colum = previousColumn.columnDef.meta) !== null && _previousColumn$colum !== void 0 && _previousColumn$colum.dataType && (previousColumn === null || previousColumn === void 0 ? void 0 : (_previousColumn$colum2 = previousColumn.columnDef.meta) === null || _previousColumn$colum2 === void 0 ? void 0 : _previousColumn$colum2.dataType) === (nextColumn === null || nextColumn === void 0 ? void 0 : (_nextColumn$columnDef = nextColumn.columnDef.meta) === null || _nextColumn$columnDef === void 0 ? void 0 : _nextColumn$columnDef.dataType)) {
39
+ handleChange(position, {
40
+ id: columnId,
41
+ value: filter.value
42
+ });
43
+ return;
44
+ }
45
+ const validComparators = guessComparatorsBasedOnControl(nextColumn);
46
+ const value = {
47
+ comparator: validComparators[0],
39
48
  value: undefined
40
49
  };
41
50
  handleChange(position, {
@@ -1 +1 @@
1
- {"version":3,"file":"Filter.js","sources":["../../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Filters/components/Filter.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as ReactTableColumn } from '@tanstack/react-table';\nimport { IconButton } from '../../../../../../../../components/IconButton/IconButton';\nimport { useLocalization } from '../../../../../../../../components/Provider/Localization';\nimport { FilterColumn } from './FilterColumn';\nimport { FilterComparator } from './FilterComparator';\nimport { FilterValue } from './FilterValue';\nimport { TableFilter, TableFilterComparator } from '../../../../../../types';\n\nexport type FilterProps<TType = unknown> = {\n allColumns: ReactTableColumn<TType, unknown>[];\n filter: TableFilter;\n filters: TableFilter[];\n position: number;\n onChange: (position: number, value: TableFilter) => void;\n onRemove?: (position: number) => void;\n};\n\nexport function Filter<TType = unknown>(props: FilterProps<TType>) {\n const { allColumns, filter, filters, onChange: handleChange, onRemove, position } = props;\n const { texts } = useLocalization();\n const column = allColumns.find(c => c.id === filter.id);\n const ref = React.useRef<HTMLButtonElement>(null);\n\n const {\n id,\n value: { comparator, value },\n } = filter;\n\n const handleChangeColumn = (columnId: string) => {\n const previousColumn = allColumns.find(column => column.id === id);\n const nextColumn = allColumns.find(column => column.id === columnId);\n // UX requirement: if old column data type is the same as next column data type,\n // then we applying the same filter value for the next column,\n // but when data types are different, we're reseting comparator ans value for the next column\n const value =\n previousColumn?.columnDef.meta?.dataType === nextColumn?.columnDef.meta?.dataType\n ? filter.value\n : {\n comparator: TableFilterComparator.Contains,\n value: undefined,\n };\n\n handleChange(position, { id: columnId, value });\n };\n\n const handleChangeComparator = (comparator: TableFilterComparator) => {\n let nextValue = filter.value.value;\n\n if (comparator === TableFilterComparator.IsEmpty || comparator === TableFilterComparator.IsNotEmpty) {\n nextValue = undefined;\n }\n handleChange(position, { id, value: { comparator, value: nextValue } });\n };\n\n const handleChangeValue = (value: any) => {\n handleChange(position, { id, value: { ...filter.value, value } });\n };\n\n const handleRemove = () => onRemove?.(position);\n\n React.useEffect(() => {\n if (ref.current && !id) {\n ref.current.focus(); // after adding a new filter placeholder, we want to focus it right way.\n }\n }, [id]);\n\n return (\n <div className=\"flex items-start gap-2\">\n <div className=\"flex min-h-[theme(spacing.8)] w-14 flex-shrink-0 items-center justify-end pr-2 text-right\">\n {position > 0 ? texts.table.filters.conditions.and : texts.table.filters.conditions.where}\n </div>\n <FilterColumn\n allColumns={allColumns as any}\n filters={filters}\n onChange={handleChangeColumn as any}\n value={id}\n ref={ref}\n />\n <FilterComparator column={column} onChange={handleChangeComparator as any} value={comparator} />\n <FilterValue column={column} comparator={comparator} onChange={handleChangeValue} value={value} />\n {onRemove ? <IconButton appearance=\"discrete\" className=\"ml-auto\" icon=\"close\" onClick={handleRemove} /> : null}\n </div>\n );\n}\n"],"names":["Filter","props","allColumns","filter","filters","onChange","handleChange","onRemove","position","texts","useLocalization","column","find","c","id","ref","React","useRef","value","comparator","handleChangeColumn","columnId","previousColumn","nextColumn","_previousColumn$colum","columnDef","meta","dataType","_nextColumn$columnDef","TableFilterComparator","Contains","undefined","handleChangeComparator","nextValue","IsEmpty","IsNotEmpty","handleChangeValue","handleRemove","useEffect","current","focus","className","table","conditions","and","where","FilterColumn","FilterComparator","FilterValue","IconButton","appearance","icon","onClick"],"mappings":";;;;;;;;SAkBgBA,MAAMA,CAAkBC,KAAyB;EAC7D,MAAM;IAAEC,UAAU;IAAEC,MAAM;IAAEC,OAAO;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,QAAQ;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AAGS,6BAACiC,UAAU;IAACC,UAAU,EAAC,UAAU;IAACT,SAAS,EAAC,SAAS;IAACU,IAAI,EAAC,OAAO;IAACC,OAAO,EAAEf;IAAgB,GAAG,IAAI,CAC7G;AAEd;;;;"}
1
+ {"version":3,"file":"Filter.js","sources":["../../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Filters/components/Filter.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as ReactTableColumn } from '@tanstack/react-table';\nimport { IconButton } from '../../../../../../../../components/IconButton/IconButton';\nimport { useLocalization } from '../../../../../../../../components/Provider/Localization';\nimport { FilterColumn } from './FilterColumn';\nimport { FilterComparator } from './FilterComparator';\nimport { FilterValue } from './FilterValue';\nimport { TableFilter, TableFilterComparator } from '../../../../../../types';\nimport { guessComparatorsBasedOnControl } from '../util';\n\nexport type FilterProps<TType = unknown> = {\n allColumns: ReactTableColumn<TType, unknown>[];\n filter: TableFilter;\n filters: TableFilter[];\n position: number;\n onChange: (position: number, value: TableFilter) => void;\n onRemove?: (position: number) => void;\n};\n\nexport function Filter<TType = unknown>(props: FilterProps<TType>) {\n const { allColumns, filter, filters, onChange: handleChange, onRemove, position } = props;\n const { texts } = useLocalization();\n const column = allColumns.find(c => c.id === filter.id);\n const ref = React.useRef<HTMLButtonElement>(null);\n\n const {\n id,\n value: { comparator, value },\n } = filter;\n\n const handleChangeColumn = (columnId: string) => {\n const previousColumn = allColumns.find(column => column.id === id);\n const nextColumn = allColumns.find(column => column.id === columnId);\n // UX requirement: if old column data type is the same as next column data type,\n // then we applying the same filter value for the next column,\n // but when data types are different, we're reseting comparator ans value for the next column\n if (\n previousColumn?.columnDef.meta?.dataType &&\n previousColumn?.columnDef.meta?.dataType === nextColumn?.columnDef.meta?.dataType\n ) {\n handleChange(position, { id: columnId, value: filter.value });\n return;\n }\n const validComparators = guessComparatorsBasedOnControl(nextColumn);\n\n const value = {\n comparator: validComparators[0],\n value: undefined,\n };\n\n handleChange(position, { id: columnId, value });\n };\n\n const handleChangeComparator = (comparator: TableFilterComparator) => {\n let nextValue = filter.value.value;\n\n if (comparator === TableFilterComparator.IsEmpty || comparator === TableFilterComparator.IsNotEmpty) {\n nextValue = undefined;\n }\n handleChange(position, { id, value: { comparator, value: nextValue } });\n };\n\n const handleChangeValue = (value: any) => {\n handleChange(position, { id, value: { ...filter.value, value } });\n };\n\n const handleRemove = () => onRemove?.(position);\n\n React.useEffect(() => {\n if (ref.current && !id) {\n ref.current.focus(); // after adding a new filter placeholder, we want to focus it right way.\n }\n }, [id]);\n\n return (\n <div className=\"flex items-start gap-2\">\n <div className=\"flex min-h-[theme(spacing.8)] w-14 flex-shrink-0 items-center justify-end pr-2 text-right\">\n {position > 0 ? texts.table.filters.conditions.and : texts.table.filters.conditions.where}\n </div>\n <FilterColumn\n allColumns={allColumns as any}\n filters={filters}\n onChange={handleChangeColumn as any}\n value={id}\n ref={ref}\n />\n <FilterComparator column={column} onChange={handleChangeComparator as any} value={comparator} />\n <FilterValue column={column} comparator={comparator} onChange={handleChangeValue} value={value} />\n {onRemove ? <IconButton appearance=\"discrete\" className=\"ml-auto\" icon=\"close\" onClick={handleRemove} /> : null}\n </div>\n );\n}\n"],"names":["Filter","props","allColumns","filter","filters","onChange","handleChange","onRemove","position","texts","useLocalization","column","find","c","id","ref","React","useRef","value","comparator","handleChangeColumn","columnId","previousColumn","nextColumn","_previousColumn$colum","columnDef","meta","dataType","_previousColumn$colum2","_nextColumn$columnDef","validComparators","guessComparatorsBasedOnControl","undefined","handleChangeComparator","nextValue","TableFilterComparator","IsEmpty","IsNotEmpty","handleChangeValue","handleRemove","useEffect","current","focus","className","table","conditions","and","where","FilterColumn","FilterComparator","FilterValue","IconButton","appearance","icon","onClick"],"mappings":";;;;;;;;;SAmBgBA,MAAMA,CAAkBC,KAAyB;EAC7D,MAAM;IAAEC,UAAU;IAAEC,MAAM;IAAEC,OAAO;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,QAAQ;IAAEC;GAAU,GAAGP,K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EA;IACP,eACFC,6BAACiC,gBAAgB;IAACtC,MAAM,EAAEA,MAAM;IAAEN,QAAQ,EAAE4B,sBAA6B;IAAEf,KAAK,EAAEC;IAAc,eAChGH,6BAACkC,WAAW;IAACvC,MAAM,EAAEA,MAAM;IAAEQ,UAAU,EAAEA,UAAU;IAAEd,QAAQ,EAAEiC,iBAAiB;IAAEpB,KAAK,EAAEA;IAAS,EACjGX,QAAQ,gBAAGS,6BAACmC,UAAU;IAACC,UAAU,EAAC,UAAU;IAACT,SAAS,EAAC,SAAS;IAACU,IAAI,EAAC,OAAO;IAACC,OAAO,EAAEf;IAAgB,GAAG,IAAI,CAC7G;AAEd;;;;"}
@@ -2,6 +2,7 @@ import React__default from 'react';
2
2
  import { useLocalization } from '../../../../../../../../components/Provider/Localization.js';
3
3
  import { TableFilterComparator } from '../../../../../../types.js';
4
4
  import { Select2 } from '../../../../../../../../components/Select2/Select2.js';
5
+ import { guessComparatorsBasedOnControl } from '../util.js';
5
6
 
6
7
  function FilterComparator(props) {
7
8
  const {
@@ -14,11 +15,6 @@ function FilterComparator(props) {
14
15
  texts
15
16
  } = useLocalization();
16
17
  const validComparators = guessComparatorsBasedOnControl(column);
17
- React__default.useEffect(() => {
18
- if (value === undefined || !validComparators.includes(value)) {
19
- handleChange === null || handleChange === void 0 ? void 0 : handleChange(validComparators[0]);
20
- }
21
- }, [validComparators]);
22
18
  return /*#__PURE__*/React__default.createElement(Select2, Object.assign({}, attributes, {
23
19
  className: "!w-32 flex-shrink-0",
24
20
  disabled: !column,
@@ -29,49 +25,9 @@ function FilterComparator(props) {
29
25
  value: comparator
30
26
  }, getComparatorText(comparator, texts, column)))));
31
27
  }
32
- function guessComparatorsBasedOnControl(column) {
33
- var _column$columnDef$met;
34
- const columnMeta = (_column$columnDef$met = column === null || column === void 0 ? void 0 : column.columnDef.meta) !== null && _column$columnDef$met !== void 0 ? _column$columnDef$met : {};
35
- if (Array.isArray(columnMeta.filters)) {
36
- return columnMeta.filters;
37
- }
38
- if (typeof columnMeta.control === 'function') {
39
- const renderedControl = columnMeta.control({
40
- onBlur: () => undefined,
41
- onFocus: () => undefined,
42
- setValue: () => undefined,
43
- value: undefined,
44
- disabled: false,
45
- readOnly: false,
46
- ref: undefined
47
- });
48
- if ( /*#__PURE__*/React__default.isValidElement(renderedControl)) {
49
- const {
50
- props,
51
- type
52
- } = renderedControl;
53
- if (type.displayName === 'Select2') {
54
- if (props.multiple) {
55
- return [TableFilterComparator.HasAnyOf, TableFilterComparator.HasAllOf, TableFilterComparator.IsEqualTo, TableFilterComparator.HasNoneOf, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
56
- }
57
- return [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
58
- }
59
- }
60
- }
61
- if (columnMeta.dataType === 'number') {
62
- return [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsGreaterThan, TableFilterComparator.IsLessThan, TableFilterComparator.IsBetween, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
63
- }
64
- if (columnMeta.control === 'datepicker' || columnMeta.dataType === 'datetime') {
65
- return [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsBetween, TableFilterComparator.IsLessThan, TableFilterComparator.IsGreaterThan, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty, TableFilterComparator.IsLessThanOrEqualTo, TableFilterComparator.IsGreaterThanOrEqualTo];
66
- }
67
- if (columnMeta.control === 'switch') {
68
- return [TableFilterComparator.IsEqualTo];
69
- }
70
- return [TableFilterComparator.Contains, TableFilterComparator.DoesNotContain, TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
71
- }
72
28
  function getComparatorText(comparator, texts, column) {
73
- var _column$columnDef, _column$columnDef$met2;
74
- const isDate = (column === null || column === void 0 ? void 0 : (_column$columnDef = column.columnDef) === null || _column$columnDef === void 0 ? void 0 : (_column$columnDef$met2 = _column$columnDef.meta) === null || _column$columnDef$met2 === void 0 ? void 0 : _column$columnDef$met2.control) === 'datepicker';
29
+ var _column$columnDef, _column$columnDef$met;
30
+ const isDate = (column === null || column === void 0 ? void 0 : (_column$columnDef = column.columnDef) === null || _column$columnDef === void 0 ? void 0 : (_column$columnDef$met = _column$columnDef.meta) === null || _column$columnDef$met === void 0 ? void 0 : _column$columnDef$met.control) === 'datepicker';
75
31
  switch (comparator) {
76
32
  case TableFilterComparator.Contains:
77
33
  return texts.table.filters.comparators.contains;
@@ -1 +1 @@
1
- {"version":3,"file":"FilterComparator.js","sources":["../../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterComparator.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as ReactTableColumn, ColumnMeta as ReactTableColumnMeta } from '@tanstack/react-table';\nimport { Select2, Select2Props } from '../../../../../../../../components/Select2/Select2';\nimport { LocalizationTexts, useLocalization } from '../../../../../../../../components/Provider/Localization';\nimport { TableFilterComparator } from '../../../../../../types';\n\nexport type FilterComparatorProps<TType = unknown> = Omit<Select2Props, 'children'> & {\n column?: ReactTableColumn<TType, unknown>;\n};\n\nexport function FilterComparator<TType = unknown>(props: FilterComparatorProps<TType>) {\n const { column, onChange: handleChange, value, ...attributes } = props;\n const { texts } = useLocalization();\n\n const validComparators = guessComparatorsBasedOnControl(column);\n\n React.useEffect(() => {\n if (value === undefined || !validComparators.includes(value as number)) {\n handleChange?.(validComparators[0]);\n }\n }, [validComparators]);\n\n return (\n <Select2 {...attributes} className=\"!w-32 flex-shrink-0\" disabled={!column} onChange={handleChange} value={value}>\n {validComparators.map(comparator => (\n <Select2.Option key={comparator} value={comparator}>\n {getComparatorText(comparator, texts, column)}\n </Select2.Option>\n ))}\n </Select2>\n );\n}\n\nfunction guessComparatorsBasedOnControl<TType = unknown>(column?: ReactTableColumn<TType>): TableFilterComparator[] {\n const columnMeta = (column?.columnDef.meta ?? {}) as ReactTableColumnMeta<TType, unknown>;\n\n if (Array.isArray(columnMeta.filters)) {\n return (columnMeta as any).filters;\n }\n\n if (typeof columnMeta.control === 'function') {\n const renderedControl = columnMeta.control({\n onBlur: () => undefined,\n onFocus: () => undefined,\n setValue: () => undefined,\n value: undefined,\n disabled: false,\n readOnly: false,\n ref: undefined as any,\n });\n\n if (React.isValidElement(renderedControl)) {\n const { props, type } = renderedControl as any;\n\n if (type.displayName === 'Select2') {\n if (props.multiple) {\n return [\n TableFilterComparator.HasAnyOf,\n TableFilterComparator.HasAllOf,\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.HasNoneOf,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n }\n\n return [\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n }\n }\n }\n\n if (columnMeta.dataType === 'number') {\n return [\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsGreaterThan,\n TableFilterComparator.IsLessThan,\n TableFilterComparator.IsBetween,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n }\n\n if (columnMeta.control === 'datepicker' || columnMeta.dataType === 'datetime') {\n return [\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsBetween,\n TableFilterComparator.IsLessThan,\n TableFilterComparator.IsGreaterThan,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n TableFilterComparator.IsLessThanOrEqualTo,\n TableFilterComparator.IsGreaterThanOrEqualTo,\n ];\n }\n\n if (columnMeta.control === 'switch') {\n return [TableFilterComparator.IsEqualTo];\n }\n\n return [\n TableFilterComparator.Contains,\n TableFilterComparator.DoesNotContain,\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n}\n\nfunction getComparatorText<TType = unknown>(\n comparator: TableFilterComparator,\n texts: LocalizationTexts,\n column?: ReactTableColumn<TType, unknown>\n) {\n const isDate = column?.columnDef?.meta?.control === 'datepicker';\n\n switch (comparator) {\n case TableFilterComparator.Contains:\n return texts.table.filters.comparators.contains;\n\n case TableFilterComparator.DoesNotContain:\n return texts.table.filters.comparators.doesNotContain;\n\n case TableFilterComparator.IsEqualTo:\n return texts.table.filters.comparators.isEqualTo;\n\n case TableFilterComparator.IsNotEqualTo:\n return texts.table.filters.comparators.isNotEqualTo;\n\n case TableFilterComparator.IsGreaterThan:\n return isDate ? texts.table.filters.comparators.isAfter : texts.table.filters.comparators.isGreaterThan;\n\n case TableFilterComparator.IsLessThan:\n return isDate ? texts.table.filters.comparators.isBefore : texts.table.filters.comparators.isLessThan;\n\n case TableFilterComparator.IsBetween:\n return texts.table.filters.comparators.isBetween;\n\n case TableFilterComparator.IsEmpty:\n return texts.table.filters.comparators.isEmpty;\n\n case TableFilterComparator.IsNotEmpty:\n return texts.table.filters.comparators.isNotEmpty;\n\n case TableFilterComparator.IsLessThanOrEqualTo:\n return isDate ? texts.table.filters.comparators.isOnOrBefore : texts.table.filters.comparators.isLessThanOrEqualTo;\n\n case TableFilterComparator.IsGreaterThanOrEqualTo:\n return isDate ? texts.table.filters.comparators.isOnOrAfter : texts.table.filters.comparators.isGreaterThanOrEqualTo;\n\n case TableFilterComparator.HasAnyOf:\n return texts.table.filters.comparators.hasAnyOf;\n\n case TableFilterComparator.HasAllOf:\n return texts.table.filters.comparators.hasAllOf;\n\n case TableFilterComparator.HasNoneOf:\n return texts.table.filters.comparators.hasNoneOf;\n\n default:\n return '';\n }\n}\n"],"names":["FilterComparator","props","column","onChange","handleChange","value","attributes","texts","useLocalization","validComparators","guessComparatorsBasedOnControl","React","useEffect","undefined","includes","Select2","className","disabled","map","comparator","Option","key","getComparatorText","columnMeta","_column$columnDef$met","columnDef","meta","Array","isArray","filters","control","renderedControl","onBlur","onFocus","setValue","readOnly","ref","isValidElement","type","displayName","multiple","TableFilterComparator","HasAnyOf","HasAllOf","IsEqualTo","HasNoneOf","IsEmpty","IsNotEmpty","IsNotEqualTo","dataType","IsGreaterThan","IsLessThan","IsBetween","IsLessThanOrEqualTo","IsGreaterThanOrEqualTo","Contains","DoesNotContain","isDate","_column$columnDef","_column$columnDef$met2","table","comparators","contains","doesNotContain","isEqualTo","isNotEqualTo","isAfter","isGreaterThan","isBefore","isLessThan","isBetween","isEmpty","isNotEmpty","isOnOrBefore","isLessThanOrEqualTo","isOnOrAfter","isGreaterThanOrEqualTo","hasAnyOf","hasAllOf","hasNoneOf"],"mappings":";;;;;SAUgBA,gBAAgBA,CAAkBC,KAAmC;EACjF,MAAM;IAAEC,MAAM;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,KAAK;IAAE,GAAGC;GAAY,GAAGL,KAAK;EACtE,MAAM;IAAEM;GAAO,GAAGC,eAAe,EAAE;EAEnC,MAAMC,gBAAgB,GAAGC,8BAA8B,CAACR,MAAM,CAAC;EAE/DS,cAAK,CAACC,SAAS,CAAC;IACZ,IAAIP,KAAK,KAAKQ,SAAS,IAAI,CAACJ,gBAAgB,CAACK,QAAQ,CAACT,KAAe,CAAC,EAAE;MACpED,YAAY,aAAZA,YAAY,uBAAZA,YAAY,CAAGK,gBAAgB,CAAC,CAAC,CAAC,CAAC;;GAE1C,EAAE,CAACA,gBAAgB,CAAC,CAAC;EAEtB,oBACIE,6BAACI,OAAO,oBAAKT,UAAU;IAAEU,SAAS,EAAC,qBAAqB;IAACC,QAAQ,EAAE,CAACf,MAAM;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,KAAK,EAAEA;MACtGI,gBAAgB,CAACS,GAAG,CAACC,UAAU,mBAC5BR,6BAACI,OAAO,CAACK,MAAM;IAACC,GAAG,EAAEF,UAAU;IAAEd,KAAK,EAAEc;KACnCG,iBAAiB,CAACH,U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B,OAAO,CAACgC,WAAW,CAACY,YAAY,GAAGlE,KAAK,CAACqD,KAAK,CAAC/B,OAAO,CAACgC,WAAW,CAACa,mBAAmB;IAEtH,KAAKjC,qBAAqB,CAACa,sBAAsB;MAC7C,OAAOG,MAAM,GAAGlD,KAAK,CAACqD,KAAK,CAAC/B,OAAO,CAACgC,WAAW,CAACc,WAAW,GAAGpE,KAAK,CAACqD,KAAK,CAAC/B,OAAO,CAACgC,WAAW,CAACe,sBAAsB;IAExH,KAAKnC,qBAAqB,CAACC,QAAQ;MAC/B,OAAOnC,KAAK,CAACqD,KAAK,CAAC/B,OAAO,CAACgC,WAAW,CAACgB,QAAQ;IAEnD,KAAKpC,qBAAqB,CAACE,QAAQ;MAC/B,OAAOpC,KAAK,CAACqD,KAAK,CAAC/B,OAAO,CAACgC,WAAW,CAACiB,QAAQ;IAEnD,KAAKrC,qBAAqB,CAACI,SAAS;MAChC,OAAOtC,KAAK,CAACqD,KAAK,CAAC/B,OAAO,CAACgC,WAAW,CAACkB,SAAS;IAEpD;MACI,OAAO,EAAE;;AAErB;;;;"}
1
+ {"version":3,"file":"FilterComparator.js","sources":["../../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Filters/components/FilterComparator.tsx"],"sourcesContent":["import React from 'react';\nimport { Column as ReactTableColumn } from '@tanstack/react-table';\nimport { Select2, Select2Props } from '../../../../../../../../components/Select2/Select2';\nimport { LocalizationTexts, useLocalization } from '../../../../../../../../components/Provider/Localization';\nimport { TableFilterComparator } from '../../../../../../types';\nimport { guessComparatorsBasedOnControl } from '../util';\n\nexport type FilterComparatorProps<TType = unknown> = Omit<Select2Props, 'children'> & {\n column?: ReactTableColumn<TType, unknown>;\n};\n\nexport function FilterComparator<TType = unknown>(props: FilterComparatorProps<TType>) {\n const { column, onChange: handleChange, value, ...attributes } = props;\n const { texts } = useLocalization();\n\n const validComparators = guessComparatorsBasedOnControl(column);\n\n return (\n <Select2 {...attributes} className=\"!w-32 flex-shrink-0\" disabled={!column} onChange={handleChange} value={value}>\n {validComparators.map(comparator => (\n <Select2.Option key={comparator} value={comparator}>\n {getComparatorText(comparator, texts, column)}\n </Select2.Option>\n ))}\n </Select2>\n );\n}\n\nfunction getComparatorText<TType = unknown>(\n comparator: TableFilterComparator,\n texts: LocalizationTexts,\n column?: ReactTableColumn<TType, unknown>\n) {\n const isDate = column?.columnDef?.meta?.control === 'datepicker';\n\n switch (comparator) {\n case TableFilterComparator.Contains:\n return texts.table.filters.comparators.contains;\n\n case TableFilterComparator.DoesNotContain:\n return texts.table.filters.comparators.doesNotContain;\n\n case TableFilterComparator.IsEqualTo:\n return texts.table.filters.comparators.isEqualTo;\n\n case TableFilterComparator.IsNotEqualTo:\n return texts.table.filters.comparators.isNotEqualTo;\n\n case TableFilterComparator.IsGreaterThan:\n return isDate ? texts.table.filters.comparators.isAfter : texts.table.filters.comparators.isGreaterThan;\n\n case TableFilterComparator.IsLessThan:\n return isDate ? texts.table.filters.comparators.isBefore : texts.table.filters.comparators.isLessThan;\n\n case TableFilterComparator.IsBetween:\n return texts.table.filters.comparators.isBetween;\n\n case TableFilterComparator.IsEmpty:\n return texts.table.filters.comparators.isEmpty;\n\n case TableFilterComparator.IsNotEmpty:\n return texts.table.filters.comparators.isNotEmpty;\n\n case TableFilterComparator.IsLessThanOrEqualTo:\n return isDate ? texts.table.filters.comparators.isOnOrBefore : texts.table.filters.comparators.isLessThanOrEqualTo;\n\n case TableFilterComparator.IsGreaterThanOrEqualTo:\n return isDate ? texts.table.filters.comparators.isOnOrAfter : texts.table.filters.comparators.isGreaterThanOrEqualTo;\n\n case TableFilterComparator.HasAnyOf:\n return texts.table.filters.comparators.hasAnyOf;\n\n case TableFilterComparator.HasAllOf:\n return texts.table.filters.comparators.hasAllOf;\n\n case TableFilterComparator.HasNoneOf:\n return texts.table.filters.comparators.hasNoneOf;\n\n default:\n return '';\n }\n}\n"],"names":["FilterComparator","props","column","onChange","handleChange","value","attributes","texts","useLocalization","validComparators","guessComparatorsBasedOnControl","React","Select2","className","disabled","map","comparator","Option","key","getComparatorText","isDate","_column$columnDef","columnDef","_column$columnDef$met","meta","control","TableFilterComparator","Contains","table","filters","comparators","contains","DoesNotContain","doesNotContain","IsEqualTo","isEqualTo","IsNotEqualTo","isNotEqualTo","IsGreaterThan","isAfter","isGreaterThan","IsLessThan","isBefore","isLessThan","IsBetween","isBetween","IsEmpty","isEmpty","IsNotEmpty","isNotEmpty","IsLessThanOrEqualTo","isOnOrBefore","isLessThanOrEqualTo","IsGreaterThanOrEqualTo","isOnOrAfter","isGreaterThanOrEqualTo","HasAnyOf","hasAnyOf","HasAllOf","hasAllOf","HasNoneOf","hasNoneOf"],"mappings":";;;;;;SAWgBA,gBAAgBA,CAAkBC,KAAmC;EACjF,MAAM;IAAEC,MAAM;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,KAAK;IAAE,GAAGC;GAAY,GAAGL,KAAK;EACtE,MAAM;IAAEM;GAAO,GAAGC,eAAe,EAAE;EAEnC,MAAMC,gBAAgB,GAAGC,8BAA8B,CAACR,MAAM,CAAC;EAE/D,oBACIS,6BAACC,OAAO,oBAAKN,UAAU;IAAEO,SAAS,EAAC,qBAAqB;IAACC,QAAQ,EAAE,CAACZ,MAAM;IAAEC,QAAQ,EAAEC,YAAY;IAAEC,KAAK,EAAEA;MACtGI,gBAAgB,CAACM,GAAG,CAACC,UAAU,mBAC5BL,6BAACC,OAAO,CAACK,MAAM;IAACC,GAAG,EAAEF,UAAU;IAAEX,KAAK,EAAEW;KACnCG,iBAAiB,CAACH,UAAU,EAAET,KAAK,EAAEL,MAAM,CAAC,CAChC,CACpB,CAAC,CACI;AAElB;AAEA,SAASiB,iBAAiBA,CACtBH,UAAiC,EACjCT,KAAwB,EACxBL,MAAyC;;EAEzC,MAAMkB,MAAM,GAAG,CAAAlB,MAAM,aAANA,MAAM,wBAAAmB,iBAAA,GAANnB,MAAM,CAAEoB,SAAS,cAAAD,iBAAA,wBAAAE,qBAAA,GAAjBF,iBA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wB,mBAAmB;MAC1C,OAAO9B,MAAM,GAAGb,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAACqB,YAAY,GAAG5C,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAACsB,mBAAmB;IAEtH,KAAK1B,qBAAqB,CAAC2B,sBAAsB;MAC7C,OAAOjC,MAAM,GAAGb,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAACwB,WAAW,GAAG/C,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAACyB,sBAAsB;IAExH,KAAK7B,qBAAqB,CAAC8B,QAAQ;MAC/B,OAAOjD,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAAC2B,QAAQ;IAEnD,KAAK/B,qBAAqB,CAACgC,QAAQ;MAC/B,OAAOnD,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAAC6B,QAAQ;IAEnD,KAAKjC,qBAAqB,CAACkC,SAAS;MAChC,OAAOrD,KAAK,CAACqB,KAAK,CAACC,OAAO,CAACC,WAAW,CAAC+B,SAAS;IAEpD;MACI,OAAO,EAAE;;AAErB;;;;"}
@@ -1,3 +1,6 @@
1
+ import React__default from 'react';
2
+ import { TableFilterComparator } from '../../../../../types.js';
3
+
1
4
  function sortByHeader(a, b) {
2
5
  var _a$columnDef$meta, _a$columnDef$meta$hea, _a$columnDef$meta$hea2, _b$columnDef$meta;
3
6
  return (_a$columnDef$meta = a.columnDef.meta) === null || _a$columnDef$meta === void 0 ? void 0 : (_a$columnDef$meta$hea = _a$columnDef$meta.header) === null || _a$columnDef$meta$hea === void 0 ? void 0 : (_a$columnDef$meta$hea2 = _a$columnDef$meta$hea.localeCompare) === null || _a$columnDef$meta$hea2 === void 0 ? void 0 : _a$columnDef$meta$hea2.call(_a$columnDef$meta$hea, (_b$columnDef$meta = b.columnDef.meta) === null || _b$columnDef$meta === void 0 ? void 0 : _b$columnDef$meta.header);
@@ -5,6 +8,46 @@ function sortByHeader(a, b) {
5
8
  function isEmptyFilter(filter) {
6
9
  return !filter.value.hasOwnProperty('value'); // eslint-disable-line no-prototype-builtins
7
10
  }
11
+ function guessComparatorsBasedOnControl(column) {
12
+ var _column$columnDef$met;
13
+ const columnMeta = (_column$columnDef$met = column === null || column === void 0 ? void 0 : column.columnDef.meta) !== null && _column$columnDef$met !== void 0 ? _column$columnDef$met : {};
14
+ if (Array.isArray(columnMeta.filters)) {
15
+ return columnMeta.filters;
16
+ }
17
+ if (typeof columnMeta.control === 'function') {
18
+ const renderedControl = columnMeta.control({
19
+ onBlur: () => undefined,
20
+ onFocus: () => undefined,
21
+ setValue: () => undefined,
22
+ value: undefined,
23
+ disabled: false,
24
+ readOnly: false,
25
+ ref: undefined
26
+ });
27
+ if ( /*#__PURE__*/React__default.isValidElement(renderedControl)) {
28
+ const {
29
+ props,
30
+ type
31
+ } = renderedControl;
32
+ if (type.displayName === 'Select2') {
33
+ if (props.multiple) {
34
+ return [TableFilterComparator.HasAnyOf, TableFilterComparator.HasAllOf, TableFilterComparator.IsEqualTo, TableFilterComparator.HasNoneOf, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
35
+ }
36
+ return [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
37
+ }
38
+ }
39
+ }
40
+ if (columnMeta.dataType === 'number') {
41
+ return [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsGreaterThan, TableFilterComparator.IsLessThan, TableFilterComparator.IsBetween, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
42
+ }
43
+ if (columnMeta.control === 'datepicker' || columnMeta.dataType === 'datetime') {
44
+ return [TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsBetween, TableFilterComparator.IsLessThan, TableFilterComparator.IsGreaterThan, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty, TableFilterComparator.IsLessThanOrEqualTo, TableFilterComparator.IsGreaterThanOrEqualTo];
45
+ }
46
+ if (columnMeta.control === 'switch') {
47
+ return [TableFilterComparator.IsEqualTo];
48
+ }
49
+ return [TableFilterComparator.Contains, TableFilterComparator.DoesNotContain, TableFilterComparator.IsEqualTo, TableFilterComparator.IsNotEqualTo, TableFilterComparator.IsEmpty, TableFilterComparator.IsNotEmpty];
50
+ }
8
51
 
9
- export { isEmptyFilter, sortByHeader };
52
+ export { guessComparatorsBasedOnControl, isEmptyFilter, sortByHeader };
10
53
  //# sourceMappingURL=util.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sources":["../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Filters/util.ts"],"sourcesContent":["import { Column as ReactTableColumn } from '@tanstack/react-table';\nimport { TableFilter } from '../../../../../types';\n\nexport function sortByHeader<TType = unknown>(a: ReactTableColumn<TType>, b: ReactTableColumn<TType>) {\n return (a.columnDef.meta?.header as string)?.localeCompare?.(b.columnDef.meta?.header as string);\n}\n\nexport function isEmptyFilter(filter: TableFilter) {\n return !filter.value.hasOwnProperty('value'); // eslint-disable-line no-prototype-builtins\n}\n"],"names":["sortByHeader","a","b","_a$columnDef$meta","columnDef","meta","_a$columnDef$meta$hea","header","_a$columnDef$meta$hea2","localeCompare","call","_b$columnDef$meta","isEmptyFilter","filter","value","hasOwnProperty"],"mappings":"SAGgBA,YAAYA,CAAkBC,CAA0B,EAAEC,CAA0B;;EAChG,QAAAC,iBAAA,GAAQF,CAAC,CAACG,SAAS,CAACC,IAAI,cAAAF,iBAAA,wBAAAG,qBAAA,GAAhBH,iBAAA,CAAkBI,MAAiB,cAAAD,qBAAA,wBAAAE,sBAAA,GAAnCF,qBAAA,CAAqCG,aAAa,cAAAD,sBAAA,uBAAlDA,sBAAA,CAAAE,IAAA,CAAAJ,qBAAA,GAAAK,iBAAA,GAAqDT,CAAC,CAACE,SAAS,CAACC,IAAI,cAAAM,iBAAA,uBAAhBA,iBAAA,CAAkBJ,MAAgB,CAAC;AACpG;SAEgBK,aAAaA,CAACC,MAAmB;EAC7C,OAAO,CAACA,MAAM,CAACC,KAAK,CAACC,cAAc,CAAC,OAAO,CAAC,CAAC;AACjD;;;;"}
1
+ {"version":3,"file":"util.js","sources":["../../../../../../../../../../../../src/primitives/Table/Core/components/Toolbar/components/Filters/util.ts"],"sourcesContent":["import { Column as ReactTableColumn, ColumnMeta as ReactTableColumnMeta } from '@tanstack/react-table';\nimport { TableFilter, TableFilterComparator } from '../../../../../types';\nimport React from 'react';\n\nexport function sortByHeader<TType = unknown>(a: ReactTableColumn<TType>, b: ReactTableColumn<TType>) {\n return (a.columnDef.meta?.header as string)?.localeCompare?.(b.columnDef.meta?.header as string);\n}\n\nexport function isEmptyFilter(filter: TableFilter) {\n return !filter.value.hasOwnProperty('value'); // eslint-disable-line no-prototype-builtins\n}\n\nexport function guessComparatorsBasedOnControl<TType = unknown>(column?: ReactTableColumn<TType>): TableFilterComparator[] {\n const columnMeta = (column?.columnDef.meta ?? {}) as ReactTableColumnMeta<TType, unknown>;\n\n if (Array.isArray(columnMeta.filters)) {\n return columnMeta.filters;\n }\n\n if (typeof columnMeta.control === 'function') {\n const renderedControl = columnMeta.control({\n onBlur: () => undefined,\n onFocus: () => undefined,\n setValue: () => undefined,\n value: undefined,\n disabled: false,\n readOnly: false,\n ref: undefined as any,\n });\n\n if (React.isValidElement(renderedControl)) {\n const { props, type } = renderedControl as any;\n\n if (type.displayName === 'Select2') {\n if (props.multiple) {\n return [\n TableFilterComparator.HasAnyOf,\n TableFilterComparator.HasAllOf,\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.HasNoneOf,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n }\n\n return [\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n }\n }\n }\n\n if (columnMeta.dataType === 'number') {\n return [\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsGreaterThan,\n TableFilterComparator.IsLessThan,\n TableFilterComparator.IsBetween,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n }\n\n if (columnMeta.control === 'datepicker' || columnMeta.dataType === 'datetime') {\n return [\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsBetween,\n TableFilterComparator.IsLessThan,\n TableFilterComparator.IsGreaterThan,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n TableFilterComparator.IsLessThanOrEqualTo,\n TableFilterComparator.IsGreaterThanOrEqualTo,\n ];\n }\n\n if (columnMeta.control === 'switch') {\n return [TableFilterComparator.IsEqualTo];\n }\n\n return [\n TableFilterComparator.Contains,\n TableFilterComparator.DoesNotContain,\n TableFilterComparator.IsEqualTo,\n TableFilterComparator.IsNotEqualTo,\n TableFilterComparator.IsEmpty,\n TableFilterComparator.IsNotEmpty,\n ];\n}\n"],"names":["sortByHeader","a","b","_a$columnDef$meta","columnDef","meta","_a$columnDef$meta$hea","header","_a$columnDef$meta$hea2","localeCompare","call","_b$columnDef$meta","isEmptyFilter","filter","value","hasOwnProperty","guessComparatorsBasedOnControl","column","columnMeta","_column$columnDef$met","Array","isArray","filters","control","renderedControl","onBlur","undefined","onFocus","setValue","disabled","readOnly","ref","React","isValidElement","props","type","displayName","multiple","TableFilterComparator","HasAnyOf","HasAllOf","IsEqualTo","HasNoneOf","IsEmpty","IsNotEmpty","IsNotEqualTo","dataType","IsGreaterThan","IsLessThan","IsBetween","IsLessThanOrEqualTo","IsGreaterThanOrEqualTo","Contains","DoesNotContain"],"mappings":";;;SAIgBA,YAAYA,CAAkBC,CAA0B,EAAEC,CAA0B;;EAChG,QAAAC,iBAAA,GAAQF,CAAC,CAACG,SAAS,CAACC,IAAI,cAAAF,iBAAA,wBAAAG,qBAA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ableRenderer(renderers, table, tableRef, defaultRowActiveIndex) {
15
15
  } = useRowHeightVirtualisation(table);
16
16
  // row groups
17
17
  const rangeExtractor = useRowGroupVirtualisation(table);
18
- // account for thead and tfoot in the scroll area
18
+ // account for thead and tfoot in the scroll area - both are always medium row height
19
19
  const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;
20
20
  // column groups offset the bottom padding :shrug:, multiplying by 1.5 ensures the bottom padding remains
21
21
  // consistent when there are groups and when there aren't. 1.5 is relatively arbitrary, but it gives alignment
@@ -1 +1 @@
1
- {"version":3,"file":"useTableRenderer.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import React, { CSSProperties } from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {\n useVirtualizer,\n defaultRangeExtractor,\n ScrollToOptions as ReactVirtualScrollToOptions,\n VirtualItem,\n} from '@tanstack/react-virtual';\nimport { ROW_HEIGHT_ESTIMATES } from '../util/rows';\nimport { Row } from '../components/Row/Row';\nimport { useTableRenderers } from '../types';\nimport { TableRef } from '../../types';\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const isTableRowGrouped = !!table.getState().grouping?.length;\n\n // expanded rows\n const { createRowMeasurer, estimateSize } = useRowHeightVirtualisation<TType>(table);\n\n // row groups\n const rangeExtractor = useRowGroupVirtualisation<TType>(table);\n\n // account for thead and tfoot in the scroll area\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n // column groups offset the bottom padding :shrug:, multiplying by 1.5 ensures the bottom padding remains\n // consistent when there are groups and when there aren't. 1.5 is relatively arbitrary, but it gives alignment\n const scrollPaddingEnd = ROW_HEIGHT_ESTIMATES.medium * (table.getHeaderGroups().length > 1 ? 1.5 : 1);\n\n const virtualiser = useVirtualizer({\n count: rows.length,\n estimateSize,\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? rows.length : undefined,\n rangeExtractor,\n // correctly sets top and bottom spacing for the scroll container - very sensitive, don't change\n scrollMargin: isTableRowGrouped ? 0 : scrollPaddingStart,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: tableMeta.footer.isEnabled ? scrollPaddingEnd * 2 : scrollPaddingEnd,\n });\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === rows.length - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, rows.length]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && rows.length > 1 ? 1 : 0;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [\n Math.max(0, virtualItems[paddingStartIndex]?.start - virtualItems[paddingStartIndex]?.size ?? 0),\n Math.max(0, totalSize - virtualItems[virtualItems.length - 1]?.end ?? 0),\n ]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (JSX.Element | null)[] | null = null;\n\n if (rows.length) {\n style = {\n height: `${totalSize}px`,\n paddingBottom,\n paddingTop,\n };\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n const row = rows[virtualRow.index];\n const measureRow = createRowMeasurer(virtualiser.resizeItem, virtualRow);\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support varying row heights - variable row heights, row expansion\nfunction useRowHeightVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const expandedState = table.getState().expanded;\n\n const [expandedRowHeightsCache, setExpandedRowHeightsCache] = React.useState<Record<number, number>>({});\n\n // look at all registered expanded row heights and use them to form a more accurate average size\n // it might be worth considering if taking the max, or an upper bound, would be better\n const averageExpandedRowHeight = React.useMemo(() => {\n const values: number[] = Object.values(expandedRowHeightsCache);\n return values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;\n }, [expandedRowHeightsCache]);\n\n // row heights\n const estimateSize = React.useCallback(\n (index: number) => {\n const rowHeight = tableMeta.rowHeight.height\n ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height]\n : ROW_HEIGHT_ESTIMATES.medium;\n\n if (expandedState === true || rows[index]?.getIsExpanded?.()) {\n return rowHeight + averageExpandedRowHeight;\n }\n\n return rowHeight;\n },\n [tableMeta.rowHeight.height, averageExpandedRowHeight, expandedState]\n );\n\n const createRowMeasurer = React.useCallback(\n (resizeItem: (item: VirtualItem, size: number) => void, virtualRow: VirtualItem) =>\n (rowHeight: number, expansionHeight?: number) => {\n // register the expansion height so that it can be used to determine an average\n if (expansionHeight) {\n setExpandedRowHeightsCache(cache => ({ ...cache, [virtualRow.index]: expansionHeight }));\n }\n\n // update the whole row's size to include the expanded height\n resizeItem(virtualRow, rowHeight + (expansionHeight ?? 0));\n },\n []\n );\n\n return { estimateSize, createRowMeasurer };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index);\n }\n });\n }\n\n return indexes;\n }, [rows]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n range => {\n const activeRowGroupIndex =\n [...rowGroupIndexes].reverse().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n const next = new Set([activeRowGroupIndex, ...defaultRangeExtractor(range)]);\n return [...next].sort((a, b) => a - b);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["useTableRenderer","renderers","table","tableRef","defaultRowActiveIndex","tableMeta","options","meta","rows","getRowModel","isTableRowGrouped","_table$getState$group","getState","grouping","length","createRowMeasurer","estimateSize","useRowHeightVirtualisation","rangeExtractor","useRowGroupVirtualisation","scrollPaddingStart","ROW_HEIGHT_ESTIMATES","medium","scrollPaddingEnd","getHeaderGroups","virtualiser","useVirtualizer","count","getScrollElement","current","overscan","printing","isPrinting","undefined","scrollMargin","footer","isEnabled","totalSize","getTotalSize","virtualItems","getVirtualItems","scrollToIndex","React","useCallback","index","align","behavior","notSmooth","scrollToOffset","scrollTop","scrollHeight","paddingStartIndex","paddingTop","paddingBottom","Math","max","_ref","_virtualItems$padding","start","_virtualItems$padding2","size","_ref2","_virtualItems","end","useEffect","style","content","height","map","virtualRow","row","measureRow","resizeItem","Row","key","id","renderer","cellRenderer","cell","expandedState","expanded","expandedRowHeightsCache","setExpandedRowHeightsCache","useState","averageExpandedRowHeight","useMemo","values","Object","reduce","a","b","rowHeight","_rows$index","_rows$index$getIsExpa","getIsExpanded","call","expansionHeight","cache","isTableGrouped","rowGroupIndexes","indexes","forEach","getIsGrouped","push","range","activeRowGroupIndex","_reverse$find","reverse","find","startIndex","next","Set","defaultRangeExtractor","sort"],"mappings":";;;;;SAagBA,gBAAgBA,CAC5BC,SAAmC,EACnCC,KAAwB,EACxBC,QAAmC,EACnCC,qBAA0C;;EAE1C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,IAAI,GAAGN,KAAK,CAACO,WAAW,EAAE,CAACD,IAAI;EACrC,MAAME,iBAAiB,GAAG,CAAC,GAAAC,qBAAA,GAACT,KAAK,CAACU,QAAQ,EAAE,CAACC,QAAQ,cAAAF,qBAAA,eAAzBA,qBAAA,CAA2BG,MAAM;;EAG7D,MAAM;IAAEC,iBAAiB;IAAEC;GAAc,GAAGC,0BAA0B,CAAQf,KAAK,CAAC;;EAGpF,MAAMgB,cAAc,GAAGC,yBAAyB,CAAQjB,KAAK,CAAC;;EAG9D,MAAMkB,kBAAkB,GAAGC,oBAAoB,CAACC,MAAM;;;EAGtD,MAAMC,gBAAgB,GAAGF,oBAAoB,CAACC,MAAM,IAAIpB,KAAK,CAACsB,eAAe,EAAE,CAACV,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;EAErG,MAAMW,WAAW,GAAGC,cAAc,CAAC;IAC/BC,KAAK,EAAEnB,IAAI,CAACM,MAAM;IAClBE,YAAY;IACZY,gBAAgB,EAAEA,MAAMzB,QAAQ,CAAC0B,OAAO;IACxCC,QAAQ,EAAEzB,SAAS,CAAC0B,QAAQ,CAACC,UAAU,GAAGxB,IAAI,CAACM,MAAM,GAAGmB,SAAS;IACjEf,cAAc;;IAEdgB,YAAY,EAAExB,iBAAiB,GAAG,CAAC,GAAGU,kBAAkB;;IAExDA,kBAAkB;IAClBG,gBAAgB,EAAElB,SAAS,CAAC8B,MAAM,CAACC,SAAS,GAAGb,gBAAgB,G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ACC,IAAI,CAAChE,KAAK,IAAI4D,KAAK,CAACK,UAAU,IAAIjE,KAAK,CAAC,cAAA8D,aAAA,cAAAA,aAAA,GAAIP,eAAe,CAAC,CAAC,CAAC;IAEjG,MAAMW,IAAI,GAAG,IAAIC,GAAG,CAAC,CAACN,mBAAmB,EAAE,GAAGO,qBAAqB,CAACR,KAAK,CAAC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAGM,IAAI,CAAC,CAACG,IAAI,CAAC,CAACxB,CAAC,EAAEC,CAAC,KAAKD,CAAC,GAAGC,CAAC,CAAC;GACzC,EACD,CAACS,eAAe,CAAC,CACpB;EAED,OAAOD,cAAc,GAAGhF,cAAc,GAAGe,SAAS;AACtD;;;;"}
1
+ {"version":3,"file":"useTableRenderer.js","sources":["../../../../../../../../../src/primitives/Table/Core/features/useTableRenderer.tsx"],"sourcesContent":["import React, { CSSProperties } from 'react';\nimport { Table as ReactTable, TableMeta as ReactTableMeta } from '@tanstack/react-table';\nimport {\n useVirtualizer,\n defaultRangeExtractor,\n ScrollToOptions as ReactVirtualScrollToOptions,\n VirtualItem,\n} from '@tanstack/react-virtual';\nimport { ROW_HEIGHT_ESTIMATES } from '../util/rows';\nimport { Row } from '../components/Row/Row';\nimport { useTableRenderers } from '../types';\nimport { TableRef } from '../../types';\n\nexport function useTableRenderer<TType = unknown>(\n renderers: useTableRenderers<TType>,\n table: ReactTable<TType>,\n tableRef: React.RefObject<TableRef>,\n defaultRowActiveIndex?: number | undefined\n) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const isTableRowGrouped = !!table.getState().grouping?.length;\n\n // expanded rows\n const { createRowMeasurer, estimateSize } = useRowHeightVirtualisation<TType>(table);\n\n // row groups\n const rangeExtractor = useRowGroupVirtualisation<TType>(table);\n\n // account for thead and tfoot in the scroll area - both are always medium row height\n const scrollPaddingStart = ROW_HEIGHT_ESTIMATES.medium;\n // column groups offset the bottom padding :shrug:, multiplying by 1.5 ensures the bottom padding remains\n // consistent when there are groups and when there aren't. 1.5 is relatively arbitrary, but it gives alignment\n const scrollPaddingEnd = ROW_HEIGHT_ESTIMATES.medium * (table.getHeaderGroups().length > 1 ? 1.5 : 1);\n\n const virtualiser = useVirtualizer({\n count: rows.length,\n estimateSize,\n getScrollElement: () => tableRef.current,\n overscan: tableMeta.printing.isPrinting ? rows.length : undefined,\n rangeExtractor,\n // correctly sets top and bottom spacing for the scroll container - very sensitive, don't change\n scrollMargin: isTableRowGrouped ? 0 : scrollPaddingStart,\n // correctly sets the scroll padding offset, e.g. when keyboard navigating rows in the list\n scrollPaddingStart,\n scrollPaddingEnd: tableMeta.footer.isEnabled ? scrollPaddingEnd * 2 : scrollPaddingEnd,\n });\n\n const totalSize = virtualiser.getTotalSize();\n const virtualItems = virtualiser.getVirtualItems();\n\n const scrollToIndex = React.useCallback(\n (index: number, options: ReactVirtualScrollToOptions = { align: 'auto', behavior: 'smooth' }) => {\n const notSmooth: ReactVirtualScrollToOptions = { ...options, behavior: 'auto' };\n\n if (tableRef.current) {\n if (index === 0) {\n virtualiser.scrollToOffset(0, notSmooth);\n } else if (index === rows.length - 1) {\n // sometimes the last row doesn't fully show, so we just force scroll to the bottom\n tableRef.current.scrollTop = tableRef.current.scrollHeight;\n } else {\n virtualiser.scrollToIndex(index, options);\n }\n }\n },\n [virtualItems.length, tableRef.current, totalSize, rows.length]\n );\n\n // use row 1 not 0, because 0 might be sticky in grouped tables and it's start value will always be 0\n const paddingStartIndex = isTableRowGrouped && rows.length > 1 ? 1 : 0;\n\n // styling for offsetting rows - this \"is\" the virtualisation\n const [paddingTop, paddingBottom] =\n virtualItems.length > 0\n ? [\n Math.max(0, virtualItems[paddingStartIndex]?.start - virtualItems[paddingStartIndex]?.size ?? 0),\n Math.max(0, totalSize - virtualItems[virtualItems.length - 1]?.end ?? 0),\n ]\n : [0, 0];\n\n // ensure default active rows are scrolled to\n React.useEffect(() => {\n if (defaultRowActiveIndex) {\n scrollToIndex(defaultRowActiveIndex, { align: 'center', behavior: 'auto' });\n }\n }, []);\n\n // rendered output\n let style: CSSProperties = {};\n let content: (JSX.Element | null)[] | null = null;\n\n if (rows.length) {\n style = {\n height: `${totalSize}px`,\n paddingBottom,\n paddingTop,\n };\n content = virtualItems.map(virtualRow => {\n // there appears to be a react-virtual bug where it inserts a single `undefined` item at the end of the row, which crashes here\n if (!virtualRow) {\n return null;\n }\n\n const row = rows[virtualRow.index];\n const measureRow = createRowMeasurer(virtualiser.resizeItem, virtualRow);\n return (\n <Row\n key={row.id}\n row={row}\n index={virtualRow.index}\n table={table}\n measureRow={measureRow}\n renderer={renderers.row}\n cellRenderer={renderers.cell}\n />\n );\n });\n }\n\n return {\n rows: content,\n style,\n scrollToIndex,\n };\n}\n\n// support varying row heights - variable row heights, row expansion\nfunction useRowHeightVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const tableMeta = table.options.meta as ReactTableMeta<TType>;\n const rows = table.getRowModel().rows;\n const expandedState = table.getState().expanded;\n\n const [expandedRowHeightsCache, setExpandedRowHeightsCache] = React.useState<Record<number, number>>({});\n\n // look at all registered expanded row heights and use them to form a more accurate average size\n // it might be worth considering if taking the max, or an upper bound, would be better\n const averageExpandedRowHeight = React.useMemo(() => {\n const values: number[] = Object.values(expandedRowHeightsCache);\n return values.length ? values.reduce((a, b) => a + b, 0) / values.length : 0;\n }, [expandedRowHeightsCache]);\n\n // row heights\n const estimateSize = React.useCallback(\n (index: number) => {\n const rowHeight = tableMeta.rowHeight.height\n ? ROW_HEIGHT_ESTIMATES[tableMeta.rowHeight.height]\n : ROW_HEIGHT_ESTIMATES.medium;\n\n if (expandedState === true || rows[index]?.getIsExpanded?.()) {\n return rowHeight + averageExpandedRowHeight;\n }\n\n return rowHeight;\n },\n [tableMeta.rowHeight.height, averageExpandedRowHeight, expandedState]\n );\n\n const createRowMeasurer = React.useCallback(\n (resizeItem: (item: VirtualItem, size: number) => void, virtualRow: VirtualItem) =>\n (rowHeight: number, expansionHeight?: number) => {\n // register the expansion height so that it can be used to determine an average\n if (expansionHeight) {\n setExpandedRowHeightsCache(cache => ({ ...cache, [virtualRow.index]: expansionHeight }));\n }\n\n // update the whole row's size to include the expanded height\n resizeItem(virtualRow, rowHeight + (expansionHeight ?? 0));\n },\n []\n );\n\n return { estimateSize, createRowMeasurer };\n}\n\n// support virtualised row groups (where the row group headers are sticky)\nfunction useRowGroupVirtualisation<TType = unknown>(table: ReactTable<TType>) {\n const rows = table.getRowModel().rows;\n const isTableGrouped = !!table.getState().grouping.length;\n\n const rowGroupIndexes = React.useMemo(() => {\n const indexes: number[] = [];\n\n if (isTableGrouped) {\n rows.forEach((row, index) => {\n if (row.getIsGrouped()) {\n indexes.push(index);\n }\n });\n }\n\n return indexes;\n }, [rows]);\n\n // this is taken from the react-virtual docs/examples\n const rangeExtractor = React.useCallback(\n range => {\n const activeRowGroupIndex =\n [...rowGroupIndexes].reverse().find(index => range.startIndex >= index) ?? rowGroupIndexes[0];\n\n const next = new Set([activeRowGroupIndex, ...defaultRangeExtractor(range)]);\n return [...next].sort((a, b) => a - b);\n },\n [rowGroupIndexes]\n );\n\n return isTableGrouped ? rangeExtractor : undefined;\n}\n"],"names":["useTableRenderer","renderers","table","tableRef","defaultRowActiveIndex","tableMeta","options","meta","rows","getRowModel","isTableRowGrouped","_table$getState$group","getState","grouping","length","createRowMeasurer","estimateSize","useRowHeightVirtualisation","rangeExtractor","useRowGroupVirtualisation","scrollPaddingStart","ROW_HEIGHT_ESTIMATES","medium","scrollPaddingEnd","getHeaderGroups","virtualiser","useVirtualizer","count","getScrollElement","current","overscan","printing","isPrinting","undefined","scrollMargin","footer","isEnabled","totalSize","getTotalSize","virtualItems","getVirtualItems","scrollToIndex","React","useCallback","index","align","behavior","notSmooth","scrollToOffset","scrollTop","scrollHeight","paddingStartIndex","paddingTop","paddingBottom","Math","max","_ref","_virtualItems$padding","start","_virtualItems$padding2","size","_ref2","_virtualItems","end","useEffect","style","content","height","map","virtualRow","row","measureRow","resizeItem","Row","key","id","renderer","cellRenderer","cell","expandedState","expanded","expandedRowHeightsCache","setExpandedRowHeightsCache","useState","averageExpandedRowHeight","useMemo","values","Object","reduce","a","b","rowHeight","_rows$index","_rows$index$getIsExpa","getIsExpanded","call","expansionHeight","cache","isTableGrouped","rowGroupIndexes","indexes","forEach","getIsGrouped","push","range","activeRowGroupIndex","_reverse$find","reverse","find","startIndex","next","Set","defaultRangeExtractor","sort"],"mappings":";;;;;SAagBA,gBAAgBA,CAC5BC,SAAmC,EACnCC,KAAwB,EACxBC,QAAmC,EACnCC,qBAA0C;;EAE1C,MAAMC,SAAS,GAAGH,KAAK,CAACI,OAAO,CAACC,IAA6B;EAC7D,MAAMC,IAAI,GAAGN,KAAK,CAACO,WAAW,EAAE,CAACD,IAAI;EACrC,MAAME,iBAAiB,GAAG,CAAC,GAAAC,qBAAA,GAACT,KAAK,CAACU,QAAQ,EAAE,CAACC,QAAQ,cAAAF,qBAAA,eAAzBA,qBAAA,CAA2BG,MAAM;;EAG7D,MAAM;IAAEC,iBAAiB;IAAEC;GAAc,GAAGC,0BAA0B,CAAQf,KAAK,CAAC;;EAGpF,MAAMgB,cAAc,GAAGC,yBAAyB,CAAQjB,KAAK,CAAC;;EAG9D,MAAMkB,kBAAkB,GAAGC,oBAAoB,CAACC,MAAM;;;EAGtD,MAAMC,gBAAgB,GAAGF,oBAAoB,CAACC,MAAM,IAAIpB,KAAK,CAACsB,eAAe,EAAE,CAACV,MAAM,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;EAErG,MAAMW,WAAW,GAAGC,cAAc,CAAC;IAC/BC,KAAK,EAAEnB,IAAI,CAACM,MAAM;IAClBE,YAAY;IACZY,gBAAgB,EAAEA,MAAMzB,QAAQ,CAAC0B,OAAO;IACxCC,QAAQ,EAAEzB,SAAS,CAAC0B,QAAQ,CAACC,UAAU,GAAGxB,IAAI,CAACM,MAAM,GAAGmB,SAAS;IACjEf,cAAc;;IAEdgB,YAAY,EAAExB,iBAA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cAAK,CAACC,WAAW,CACpC6D,KAAK;;IACD,MAAMC,mBAAmB,IAAAC,aAAA,GACrB,CAAC,GAAGP,eAAe,CAAC,CAACQ,OAAO,EAAE,CAACC,IAAI,CAAChE,KAAK,IAAI4D,KAAK,CAACK,UAAU,IAAIjE,KAAK,CAAC,cAAA8D,aAAA,cAAAA,aAAA,GAAIP,eAAe,CAAC,CAAC,CAAC;IAEjG,MAAMW,IAAI,GAAG,IAAIC,GAAG,CAAC,CAACN,mBAAmB,EAAE,GAAGO,qBAAqB,CAACR,KAAK,CAAC,CAAC,CAAC;IAC5E,OAAO,CAAC,GAAGM,IAAI,CAAC,CAACG,IAAI,CAAC,CAACxB,CAAC,EAAEC,CAAC,KAAKD,CAAC,GAAGC,CAAC,CAAC;GACzC,EACD,CAACS,eAAe,CAAC,CACpB;EAED,OAAOD,cAAc,GAAGhF,cAAc,GAAGe,SAAS;AACtD;;;;"}
@@ -6,11 +6,11 @@ function useTableRowActive(isEnabled = false, initialRowActiveIndex) {
6
6
  const [rowActiveIndex, setRowActiveIndex] = React__default.useState(initialRowActiveIndex);
7
7
  const [rowHoverIndex, setRowHoverIndex] = React__default.useState(undefined);
8
8
  const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();
9
- const move = (direction, length, scrollToIndex) => setRowActiveIndex(currentIndex => {
10
- const nextIndex = currentIndex !== undefined ? getNextIndex(direction, currentIndex, length) : 0;
11
- setTimeout(() => scrollToIndex(nextIndex), 1);
12
- return nextIndex;
13
- });
9
+ const move = (direction, length, scrollToIndex) => {
10
+ const nextIndex = rowActiveIndex !== undefined ? getNextIndex(direction, rowActiveIndex, length) : 0;
11
+ scrollToIndex(nextIndex);
12
+ setTimeout(() => setRowActiveIndex(nextIndex), 50);
13
+ };
14
14
  const onKeyDown = React__default.useCallback((event, length, scrollToIndex) => {
15
15
  if (!isEnabled || event.defaultPrevented) {
16
16
  return;
@@ -1 +1 @@
1
- {"version":3,"file":"useTableRowActive.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowActive.ts"],"sourcesContent":["import React from 'react';\nimport { TableScrollToIndexHandler } from '../../types';\nimport { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport function useTableRowActive(isEnabled = false, initialRowActiveIndex?: number) {\n const [rowActiveIndex, setRowActiveIndex] = React.useState<number | undefined>(initialRowActiveIndex);\n const [rowHoverIndex, setRowHoverIndex] = React.useState<number | undefined>(undefined);\n const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();\n\n const move = (direction: -1 | 1, length: number, scrollToIndex: TableScrollToIndexHandler) =>\n setRowActiveIndex(currentIndex => {\n const nextIndex = currentIndex !== undefined ? getNextIndex(direction, currentIndex, length) : 0;\n setTimeout(() => scrollToIndex(nextIndex), 1);\n return nextIndex;\n });\n\n const onKeyDown = React.useCallback(\n (event: KeyboardEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.defaultPrevented) {\n return;\n }\n\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n setHoverStatePaused(true);\n }\n\n if (event.key === 'ArrowUp') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = 0;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(-1, length, scrollToIndex);\n }\n\n return;\n } else if (event.key === 'ArrowDown') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = length - 1;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(+1, length, scrollToIndex);\n }\n return;\n }\n },\n [isEnabled, rowActiveIndex]\n );\n\n const onFocus = React.useCallback(\n (event: React.FocusEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.isDefaultPrevented()) {\n return;\n }\n\n if (event.target.closest('tbody') || isElementInsideOrTriggeredFromContainer(event.target, event.currentTarget)) {\n return;\n }\n\n if (rowActiveIndex === undefined && length > 0) {\n setRowActiveIndex(index => {\n if (index === undefined) {\n scrollToIndex(0);\n return 0;\n }\n return index;\n });\n }\n },\n [rowActiveIndex, length, isEnabled]\n );\n\n return {\n isEnabled,\n rowActiveIndex,\n setRowActiveIndex: isEnabled ? setRowActiveIndex : () => undefined,\n rowHoverIndex,\n setRowHoverIndex,\n isHoverStatePaused,\n setHoverStatePaused: isEnabled ? setHoverStatePaused : () => undefined,\n handleFocus: isEnabled ? onFocus : () => undefined,\n handleKeyDown: isEnabled ? onKeyDown : () => undefined,\n };\n}\n\nfunction getNextIndex(direction: -1 | 1, currentIndex: number, length: number) {\n if (direction === -1) {\n return currentIndex - 1 > 0 ? currentIndex - 1 : 0;\n }\n\n return currentIndex + 1 < length ? currentIndex + 1 : currentIndex;\n}\n"],"names":["useTableRowActive","isEnabled","initialRowActiveIndex","rowActiveIndex","setRowActiveIndex","React","useState","rowHoverIndex","setRowHoverIndex","undefined","isHoverStatePaused","setHoverStatePaused","useIsHoverStatePaused","move","direction","length","scrollToIndex","currentIndex","nextIndex","getNextIndex","setTimeout","onKeyDown","useCallback","event","defaultPrevented","key","preventDefault","ctrlKey","metaKey","newIndex","onFocus","isDefaultPrevented","target","closest","isElementInsideOrTriggeredFromContainer","currentTarget","index","handleFocus","handleKeyDown"],"mappings":";;;;SAKgBA,iBAAiBA,CAACC,SAAS,GAAG,KAAK,EAAEC,qBAA8B;EAC/E,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAqBJ,qBAAqB,CAAC;EACrG,MAAM,CAACK,aAAa,EAAEC,gBAAgB,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqBG,SAAS,CAAC;EACvF,MAAM,CAACC,kBAAkB,EAAEC,mBAAmB,CAAC,GAAGC,qBAAqB,EAAE;EAEzE,MAAMC,IAAI,GAAGA,CAACC,SAAiB,EAAEC,MAAc,EAAEC,aAAwC,KACrFZ,iBAAiB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"}
1
+ {"version":3,"file":"useTableRowActive.js","sources":["../../../../../../../../../src/primitives/Table/useTableManager/features/useTableRowActive.ts"],"sourcesContent":["import React from 'react';\nimport { TableScrollToIndexHandler } from '../../types';\nimport { useIsHoverStatePaused } from '../../../../hooks/useIsHoverStatePaused';\nimport { isElementInsideOrTriggeredFromContainer } from '../../../../utils/dom';\n\nexport function useTableRowActive(isEnabled = false, initialRowActiveIndex?: number) {\n const [rowActiveIndex, setRowActiveIndex] = React.useState<number | undefined>(initialRowActiveIndex);\n const [rowHoverIndex, setRowHoverIndex] = React.useState<number | undefined>(undefined);\n const [isHoverStatePaused, setHoverStatePaused] = useIsHoverStatePaused();\n\n const move = (direction: -1 | 1, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n const nextIndex = rowActiveIndex !== undefined ? getNextIndex(direction, rowActiveIndex, length) : 0;\n scrollToIndex(nextIndex);\n setTimeout(() => setRowActiveIndex(nextIndex), 50);\n };\n\n const onKeyDown = React.useCallback(\n (event: KeyboardEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.defaultPrevented) {\n return;\n }\n\n if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {\n setHoverStatePaused(true);\n }\n\n if (event.key === 'ArrowUp') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = 0;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(-1, length, scrollToIndex);\n }\n\n return;\n } else if (event.key === 'ArrowDown') {\n event.preventDefault();\n\n if (event.ctrlKey || event.metaKey) {\n const newIndex = length - 1;\n scrollToIndex(newIndex);\n setRowActiveIndex(newIndex);\n } else {\n move(+1, length, scrollToIndex);\n }\n return;\n }\n },\n [isEnabled, rowActiveIndex]\n );\n\n const onFocus = React.useCallback(\n (event: React.FocusEvent, length: number, scrollToIndex: TableScrollToIndexHandler) => {\n if (!isEnabled || event.isDefaultPrevented()) {\n return;\n }\n\n if (event.target.closest('tbody') || isElementInsideOrTriggeredFromContainer(event.target, event.currentTarget)) {\n return;\n }\n\n if (rowActiveIndex === undefined && length > 0) {\n setRowActiveIndex(index => {\n if (index === undefined) {\n scrollToIndex(0);\n return 0;\n }\n return index;\n });\n }\n },\n [rowActiveIndex, length, isEnabled]\n );\n\n return {\n isEnabled,\n rowActiveIndex,\n setRowActiveIndex: isEnabled ? setRowActiveIndex : () => undefined,\n rowHoverIndex,\n setRowHoverIndex,\n isHoverStatePaused,\n setHoverStatePaused: isEnabled ? setHoverStatePaused : () => undefined,\n handleFocus: isEnabled ? onFocus : () => undefined,\n handleKeyDown: isEnabled ? onKeyDown : () => undefined,\n };\n}\n\nfunction getNextIndex(direction: -1 | 1, currentIndex: number, length: number) {\n if (direction === -1) {\n return currentIndex - 1 > 0 ? currentIndex - 1 : 0;\n }\n\n return currentIndex + 1 < length ? currentIndex + 1 : currentIndex;\n}\n"],"names":["useTableRowActive","isEnabled","initialRowActiveIndex","rowActiveIndex","setRowActiveIndex","React","useState","rowHoverIndex","setRowHoverIndex","undefined","isHoverStatePaused","setHoverStatePaused","useIsHoverStatePaused","move","direction","length","scrollToIndex","nextIndex","getNextIndex","setTimeout","onKeyDown","useCallback","event","defaultPrevented","key","preventDefault","ctrlKey","metaKey","newIndex","onFocus","isDefaultPrevented","target","closest","isElementInsideOrTriggeredFromContainer","currentTarget","index","handleFocus","handleKeyDown","currentIndex"],"mappings":";;;;SAKgBA,iBAAiBA,CAACC,SAAS,GAAG,KAAK,EAAEC,qBAA8B;EAC/E,MAAM,CAACC,cAAc,EAAEC,iBAAiB,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAqBJ,qBAAqB,CAAC;EACrG,MAAM,CAACK,aAAa,EAAEC,gBAAgB,CAAC,GAAGH,cAAK,CAACC,QAAQ,CAAqBG,SAAS,CAAC;EACvF,MAAM,CAACC,kBAAkB,EAAEC,mBAAmB,CAAC,GAAGC,qBAAqB,EAAE;EAEzE,MAAMC,IAAI,GAAGA,CAACC,SAAiB,EAA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,GAAGA,YAAY;AACtE;;;;"}
@@ -72,6 +72,9 @@ function isElementInteractive(element) {
72
72
  }
73
73
  return ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL', 'OPTION'].includes(element.tagName) && !element.hidden && !element.disabled && !element.readOnly;
74
74
  }
75
+ function isElementInsideTable3OrReport(element) {
76
+ return !!(element !== null && element !== void 0 && element.closest('[data-taco^=table]'));
77
+ }
75
78
 
76
- export { getIndexOfFirstChildOverflowingParent, getNextFocussableElement, hasFocusableElement, isElementInsideOrTriggeredFromContainer, isElementInsideOverlay, isElementInteractive, isSiblingElementInsideSameParentOverlay };
79
+ export { getIndexOfFirstChildOverflowingParent, getNextFocussableElement, hasFocusableElement, isElementInsideOrTriggeredFromContainer, isElementInsideOverlay, isElementInsideTable3OrReport, isElementInteractive, isSiblingElementInsideSameParentOverlay };
77
80
  //# sourceMappingURL=dom.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom.js","sources":["../../../../../../src/utils/dom.ts"],"sourcesContent":["// taken from react-aria\nconst FOCUSABLE_ELEMENTS = [\n 'input:not([disabled]):not([type=hidden])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'button:not([disabled])',\n 'a[href]',\n 'area[href]',\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]',\n '[tabindex]:not([tabindex=\"-1\"]):not([disabled])',\n 'details:not([disabled])',\n 'summary:not(:disabled)',\n];\n\nexport const hasFocusableElement = (element: HTMLElement | null) => {\n if (!element) {\n return null;\n }\n\n return !!element.querySelector(FOCUSABLE_ELEMENTS.join(','));\n};\n\nexport const isOverflowing = (element: HTMLElement | null) =>\n element !== null ? element.scrollWidth > element.offsetWidth : false;\n\nexport const getIndexOfFirstChildOverflowingParent = (element: HTMLElement, overscan = 0) => {\n let index = 0;\n let boundaryChildIndex: number | null = null;\n const clientRect = element.getBoundingClientRect();\n\n for (const child of Array.from(element.children)) {\n const right = child.getBoundingClientRect().right - clientRect.left;\n const width = clientRect.width - overscan;\n\n if (right > width) {\n boundaryChildIndex = index;\n break;\n }\n index++;\n }\n\n return boundaryChildIndex;\n};\n\nexport const getNextFocussableElement = (currentElement: HTMLElement | null) => {\n if (!currentElement) {\n return null;\n }\n\n const focussableElements = [...document.querySelectorAll<HTMLElement>(FOCUSABLE_ELEMENTS.join(','))];\n const currentElementIndex = focussableElements.indexOf(currentElement);\n\n // If the currentElement is not in the focussable elements list or it is the last element\n if (currentElementIndex !== -1 && currentElementIndex === focussableElements.length - 1) {\n return null;\n }\n\n return focussableElements[currentElementIndex + 1];\n};\n\nconst getOverlaySelector = (element: Element | null) => {\n switch (element?.getAttribute('role')) {\n case 'dialog':\n return `[aria-controls='${element.id}']`;\n\n case 'menu':\n return `#${element.getAttribute('aria-labelledby')}`;\n\n default:\n return undefined;\n }\n};\n\nexport function isElementInsideOrTriggeredFromContainer(element: Element | null, container: Element | null) {\n const selector = getOverlaySelector(element) ?? getOverlaySelector(element?.closest('[role=dialog],[role=menu]') ?? null);\n\n if (selector) {\n if (container?.querySelector(selector)) {\n return true;\n }\n\n const elementInDocument = document.querySelector(selector);\n\n // if the element does exist, see if it is itself connected to somethng that was triggered from the container\n if (elementInDocument) {\n return isElementInsideOrTriggeredFromContainer(elementInDocument, container);\n }\n\n return false;\n }\n\n return !!container?.contains(element);\n}\n\nexport function isElementInsideOverlay(element: Element | null) {\n return !!element?.closest('[role=dialog],[role=menu]');\n}\n\nexport function isSiblingElementInsideSameParentOverlay(element: Element | null, sibling: Element | null) {\n return !!element?.closest('[role=dialog],[role=menu]')?.contains(sibling);\n}\n\nexport function isElementInteractive(element: Element | null) {\n if (!element) {\n return false;\n }\n\n return (\n ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL', 'OPTION'].includes(element.tagName) &&\n !(element as HTMLElement).hidden &&\n !(element as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLButtonElement).disabled &&\n !(element as HTMLInputElement | HTMLTextAreaElement).readOnly\n );\n}\n"],"names":["FOCUSABLE_ELEMENTS","hasFocusableElement","element","querySelector","join","getIndexOfFirstChildOverflowingParent","overscan","index","boundaryChildIndex","clientRect","getBoundingClientRect","child","Array","from","children","right","left","width","getNextFocussableElement","currentElement","focussableElements","document","querySelectorAll","currentElementIndex","indexOf","length","getOverlaySelector","getAttribute","id","undefined","isElementInsideOrTriggeredFromContainer","container","selector","_getOverlaySelector","_element$closest","closest","elementInDocument","contains","isElementInsideOverlay","isSiblingElementInsideSameParentOverlay","sibling","_element$closest2","isElementInteractive","includes","tagName","hidden","disabled","readOnly"],"mappings":"AAAA;AACA,MAAMA,kBAAkB,GAAG,CACvB,0CAA0C,EAC1C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,iDAAiD,EACjD,yBAAyB,EACzB,wBAAwB,CAC3B;MAEYC,mBAAmB,GAAIC,OAA2B;EAC3D,IAAI,CAACA,OAAO,EAAE;IACV,OAAO,IAAI;;EAGf,OAAO,CAAC,CAACA,OAAO,CAACC,aAAa,CAACH,kBAAkB,CAACI,IAAI,CAAC,GAAG,CAAC,CAAC;AAChE;MAKaC,qCAAqC,GAAGA,CAACH,OAAoB,EAAEI,QAAQ,GAAG,CAAC;EACpF,IAAIC,KAAK,GAAG,CAAC;EACb,IAAIC,kBAAkB,GAAkB,IAAI;EAC5C,MAAMC,UAAU,GAAGP,OAAO,CAACQ,qBAAqB,EAAE;EAElD,KAAK,MAAMC,KAAK,IAAIC,KAAK,CAACC,IAAI,CAACX,OAAO,CAACY,QAAQ,CAAC,EAAE;IAC9C,MAAMC,KAAK,GAAGJ,KAAK,CAACD,qBAAqB,EAAE,CAACK,KAAK,GAAGN,UAAU,CAACO,IAAI;IACnE,MAAMC,KAAK,GAAGR,UAAU,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,aAATA,SAAS,eAATA,SAAS,CAAE5B,aAAa,CAAC6B,QAAQ,CAAC,EAAE;MACpC,OAAO,IAAI;;IAGf,MAAMI,iBAAiB,GAAGf,QAAQ,CAAClB,aAAa,CAAC6B,QAAQ,CAAC;;IAG1D,IAAII,iBAAiB,EAAE;MACnB,OAAON,uCAAuC,CAACM,iBAAiB,EAAEL,SAAS,CAAC;;IAGhF,OAAO,KAAK;;EAGhB,OAAO,CAAC,EAACA,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEM,QAAQ,CAACnC,OAAO,CAAC;AACzC;SAEgBoC,sBAAsBA,CAACpC,OAAuB;EAC1D,OAAO,CAAC,EAACA,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEiC,OAAO,CAAC,2BAA2B,CAAC;AAC1D;SAEgBI,uCAAuCA,CAACrC,OAAuB,EAAEsC,OAAuB;;EACpG,OAAO,CAAC,EAACtC,OAAO,aAAPA,OAAO,gBAAAuC,iBAAA,GAAPvC,OAAO,CAAEiC,OAAO,CAAC,2BAA2B,CAAC,cAAAM,iBAAA,eAA7CA,iBAAA,CAA+CJ,QAAQ,CAACG,OAAO,CAAC;AAC7E;SAEgBE,oBAAoBA,CAACxC,OAAuB;EACxD,IAAI,CAACA,OAAO,EAAE;IACV,OAAO,KAAK;;EAGhB,OACI,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAACyC,QAAQ,CAACzC,OAAO,CAAC0C,OAAO,CAAC,IAC3F,CAAE1C,OAAuB,CAAC2C,MAAM,IAChC,CAAE3C,OAA0F,CAAC4C,QAAQ,IACrG,CAAE5C,OAAkD,CAAC6C,QAAQ;AAErE;;;;"}
1
+ {"version":3,"file":"dom.js","sources":["../../../../../../src/utils/dom.ts"],"sourcesContent":["// taken from react-aria\nconst FOCUSABLE_ELEMENTS = [\n 'input:not([disabled]):not([type=hidden])',\n 'select:not([disabled])',\n 'textarea:not([disabled])',\n 'button:not([disabled])',\n 'a[href]',\n 'area[href]',\n 'summary',\n 'iframe',\n 'object',\n 'embed',\n 'audio[controls]',\n 'video[controls]',\n '[contenteditable]',\n '[tabindex]:not([tabindex=\"-1\"]):not([disabled])',\n 'details:not([disabled])',\n 'summary:not(:disabled)',\n];\n\nexport const hasFocusableElement = (element: HTMLElement | null) => {\n if (!element) {\n return null;\n }\n\n return !!element.querySelector(FOCUSABLE_ELEMENTS.join(','));\n};\n\nexport const isOverflowing = (element: HTMLElement | null) =>\n element !== null ? element.scrollWidth > element.offsetWidth : false;\n\nexport const getIndexOfFirstChildOverflowingParent = (element: HTMLElement, overscan = 0) => {\n let index = 0;\n let boundaryChildIndex: number | null = null;\n const clientRect = element.getBoundingClientRect();\n\n for (const child of Array.from(element.children)) {\n const right = child.getBoundingClientRect().right - clientRect.left;\n const width = clientRect.width - overscan;\n\n if (right > width) {\n boundaryChildIndex = index;\n break;\n }\n index++;\n }\n\n return boundaryChildIndex;\n};\n\nexport const getNextFocussableElement = (currentElement: HTMLElement | null) => {\n if (!currentElement) {\n return null;\n }\n\n const focussableElements = [...document.querySelectorAll<HTMLElement>(FOCUSABLE_ELEMENTS.join(','))];\n const currentElementIndex = focussableElements.indexOf(currentElement);\n\n // If the currentElement is not in the focussable elements list or it is the last element\n if (currentElementIndex !== -1 && currentElementIndex === focussableElements.length - 1) {\n return null;\n }\n\n return focussableElements[currentElementIndex + 1];\n};\n\nconst getOverlaySelector = (element: Element | null) => {\n switch (element?.getAttribute('role')) {\n case 'dialog':\n return `[aria-controls='${element.id}']`;\n\n case 'menu':\n return `#${element.getAttribute('aria-labelledby')}`;\n\n default:\n return undefined;\n }\n};\n\nexport function isElementInsideOrTriggeredFromContainer(element: Element | null, container: Element | null) {\n const selector = getOverlaySelector(element) ?? getOverlaySelector(element?.closest('[role=dialog],[role=menu]') ?? null);\n\n if (selector) {\n if (container?.querySelector(selector)) {\n return true;\n }\n\n const elementInDocument = document.querySelector(selector);\n\n // if the element does exist, see if it is itself connected to somethng that was triggered from the container\n if (elementInDocument) {\n return isElementInsideOrTriggeredFromContainer(elementInDocument, container);\n }\n\n return false;\n }\n\n return !!container?.contains(element);\n}\n\nexport function isElementInsideOverlay(element: Element | null) {\n return !!element?.closest('[role=dialog],[role=menu]');\n}\n\nexport function isSiblingElementInsideSameParentOverlay(element: Element | null, sibling: Element | null) {\n return !!element?.closest('[role=dialog],[role=menu]')?.contains(sibling);\n}\n\nexport function isElementInteractive(element: Element | null) {\n if (!element) {\n return false;\n }\n\n return (\n ['A', 'BUTTON', 'INPUT', 'TEXTAREA', 'SELECT', 'LABEL', 'OPTION'].includes(element.tagName) &&\n !(element as HTMLElement).hidden &&\n !(element as HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement | HTMLButtonElement).disabled &&\n !(element as HTMLInputElement | HTMLTextAreaElement).readOnly\n );\n}\n\nexport function isElementInsideTable3OrReport(element: Element | null) {\n return !!element?.closest('[data-taco^=table]');\n}\n"],"names":["FOCUSABLE_ELEMENTS","hasFocusableElement","element","querySelector","join","getIndexOfFirstChildOverflowingParent","overscan","index","boundaryChildIndex","clientRect","getBoundingClientRect","child","Array","from","children","right","left","width","getNextFocussableElement","currentElement","focussableElements","document","querySelectorAll","currentElementIndex","indexOf","length","getOverlaySelector","getAttribute","id","undefined","isElementInsideOrTriggeredFromContainer","container","selector","_getOverlaySelector","_element$closest","closest","elementInDocument","contains","isElementInsideOverlay","isSiblingElementInsideSameParentOverlay","sibling","_element$closest2","isElementInteractive","includes","tagName","hidden","disabled","readOnly","isElementInsideTable3OrReport"],"mappings":"AAAA;AACA,MAAMA,kBAAkB,GAAG,CACvB,0CAA0C,EAC1C,wBAAwB,EACxB,0BAA0B,EAC1B,wBAAwB,EACxB,SAAS,EACT,YAAY,EACZ,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,iDAAiD,EACjD,yBAAyB,EACzB,wBA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AAC,cAAAM,iBAAA,eAA7CA,iBAAA,CAA+CJ,QAAQ,CAACG,OAAO,CAAC;AAC7E;SAEgBE,oBAAoBA,CAACxC,OAAuB;EACxD,IAAI,CAACA,OAAO,EAAE;IACV,OAAO,KAAK;;EAGhB,OACI,CAAC,GAAG,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAACyC,QAAQ,CAACzC,OAAO,CAAC0C,OAAO,CAAC,IAC3F,CAAE1C,OAAuB,CAAC2C,MAAM,IAChC,CAAE3C,OAA0F,CAAC4C,QAAQ,IACrG,CAAE5C,OAAkD,CAAC6C,QAAQ;AAErE;SAEgBC,6BAA6BA,CAAC9C,OAAuB;EACjE,OAAO,CAAC,EAACA,OAAO,aAAPA,OAAO,eAAPA,OAAO,CAAEiC,OAAO,CAAC,oBAAoB,CAAC;AACnD;;;;"}
package/dist/index.css CHANGED
@@ -625,16 +625,16 @@ table[data-taco^='table'] tr:last-child th:before {
625
625
  /* row groups */
626
626
 
627
627
  table[data-taco^='table'] tr[data-row-group] {
628
- @apply bg-grey-100 sticky top-[calc((var(--table-header-group-depth)_-_1)_*_40px_+_42px)] z-30 mt-10 print:mt-0;
628
+ @apply bg-grey-100 sticky top-[calc((var(--table-header-group-depth)_-_1)_*_40px_+_42px)] z-30 pt-10 print:pt-0;
629
629
  }
630
630
 
631
631
  table[data-taco^='table'] tr[data-row-group]:first-child {
632
- @apply mt-0;
632
+ @apply pt-0;
633
633
  }
634
634
 
635
635
  table[data-taco^='table'] tr[data-row-group]:not(:first-child):before {
636
636
  content: '';
637
- @apply bg-grey-100 border-grey-300 absolute -top-full left-0 right-0 mt-px h-10 border-t print:top-0 print:h-[2px] print:border-t-2;
637
+ @apply bg-grey-100 border-grey-300 absolute left-0 right-0 top-0 h-10 border-t print:top-0 print:h-[2px] print:border-t-2;
638
638
  }
639
639
 
640
640
  table[data-taco^='table'] tr[data-row-group] td {
@@ -1231,7 +1231,7 @@ table[data-taco='table3'][data-table-editing-mode] tbody tr[data-row-editing-mov
1231
1231
  }
1232
1232
 
1233
1233
  table[data-taco='table3'][data-table-editing-mode] tbody tr[data-row-editing-move='true'] td {
1234
- @apply border-b-0;
1234
+ @apply z-30 border-b-0;
1235
1235
  }
1236
1236
 
1237
1237
  table[data-taco='table3'][data-table-editing-mode] tbody tr[data-row-editing-move='true'] > td:first-child {
@@ -1,9 +1,11 @@
1
1
  import React from 'react';
2
2
  import { Table as ReactTable } from '@tanstack/react-table';
3
+ import { TableRef } from '../../../types';
3
4
  declare type BodyProps<TType = unknown> = React.HTMLAttributes<HTMLTableSectionElement> & {
4
5
  enableHorizontalArrowKeyNavigation?: boolean;
5
6
  scrollToIndex: (index: number) => void;
6
7
  table: ReactTable<TType>;
8
+ tableElement: TableRef | null;
7
9
  };
8
10
  export declare function Body<TType = unknown>(props: BodyProps<TType>): JSX.Element;
9
11
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Column as ReactTableColumn } from '@tanstack/react-table';
2
- import { TableFilter } from '../../../../../types';
2
+ import { TableFilter, TableFilterComparator } from '../../../../../types';
3
3
  export declare function sortByHeader<TType = unknown>(a: ReactTableColumn<TType>, b: ReactTableColumn<TType>): number;
4
4
  export declare function isEmptyFilter(filter: TableFilter): boolean;
5
+ export declare function guessComparatorsBasedOnControl<TType = unknown>(column?: ReactTableColumn<TType>): TableFilterComparator[];