@semcore/data-table 16.0.0-prerelease.9 → 16.0.0

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.
Files changed (138) hide show
  1. package/CHANGELOG.md +25 -1
  2. package/lib/cjs/components/Body/Body.js +436 -0
  3. package/lib/cjs/components/Body/Body.js.map +1 -0
  4. package/lib/cjs/components/Body/Body.types.js +2 -0
  5. package/lib/cjs/components/Body/Body.types.js.map +1 -0
  6. package/lib/cjs/components/Body/Cell.js +194 -0
  7. package/lib/cjs/components/Body/Cell.js.map +1 -0
  8. package/lib/cjs/components/Body/Cell.types.js +2 -0
  9. package/lib/cjs/components/Body/Cell.types.js.map +1 -0
  10. package/lib/cjs/components/Body/MergedCells.js +29 -0
  11. package/lib/cjs/components/Body/MergedCells.js.map +1 -0
  12. package/lib/cjs/components/Body/Row.js +244 -0
  13. package/lib/cjs/components/Body/Row.js.map +1 -0
  14. package/lib/cjs/components/Body/Row.types.js +4 -0
  15. package/lib/cjs/components/Body/Row.types.js.map +1 -0
  16. package/lib/cjs/components/Body/style.shadow.css +257 -0
  17. package/lib/cjs/components/DataTable/DataTable.js +981 -0
  18. package/lib/cjs/components/DataTable/DataTable.js.map +1 -0
  19. package/lib/cjs/{types.js → components/DataTable/DataTable.types.js} +1 -1
  20. package/lib/cjs/components/DataTable/DataTable.types.js.map +1 -0
  21. package/lib/cjs/components/DataTable/dataTable.shadow.css +17 -0
  22. package/lib/cjs/components/Head/Column.js +316 -0
  23. package/lib/cjs/components/Head/Column.js.map +1 -0
  24. package/lib/cjs/components/Head/Column.types.js +2 -0
  25. package/lib/cjs/components/Head/Column.types.js.map +1 -0
  26. package/lib/cjs/components/Head/Group.js +115 -0
  27. package/lib/cjs/components/Head/Group.js.map +1 -0
  28. package/lib/cjs/components/Head/Group.type.js +2 -0
  29. package/lib/cjs/components/Head/Group.type.js.map +1 -0
  30. package/lib/cjs/components/Head/Head.js +205 -0
  31. package/lib/cjs/components/Head/Head.js.map +1 -0
  32. package/lib/cjs/components/Head/Head.types.js +2 -0
  33. package/lib/cjs/components/Head/Head.types.js.map +1 -0
  34. package/lib/cjs/components/Head/style.shadow.css +176 -0
  35. package/lib/cjs/index.js +25 -15
  36. package/lib/cjs/index.js.map +1 -1
  37. package/lib/cjs/style/scroll-shadows.shadow.css +39 -5
  38. package/lib/cjs/translations/en.json +6 -1
  39. package/lib/cjs/utils.js +16 -7
  40. package/lib/cjs/utils.js.map +1 -1
  41. package/lib/es6/components/Body/Body.js +429 -0
  42. package/lib/es6/components/Body/Body.js.map +1 -0
  43. package/lib/es6/components/Body/Body.types.js +2 -0
  44. package/lib/es6/components/Body/Body.types.js.map +1 -0
  45. package/lib/es6/components/Body/Cell.js +187 -0
  46. package/lib/es6/components/Body/Cell.js.map +1 -0
  47. package/lib/es6/components/Body/Cell.types.js +2 -0
  48. package/lib/es6/components/Body/Cell.types.js.map +1 -0
  49. package/lib/es6/components/Body/MergedCells.js +20 -0
  50. package/lib/es6/components/Body/MergedCells.js.map +1 -0
  51. package/lib/es6/components/Body/Row.js +237 -0
  52. package/lib/es6/components/Body/Row.js.map +1 -0
  53. package/lib/es6/components/Body/Row.types.js +2 -0
  54. package/lib/es6/components/Body/Row.types.js.map +1 -0
  55. package/lib/es6/components/Body/style.shadow.css +257 -0
  56. package/lib/es6/components/DataTable/DataTable.js +970 -0
  57. package/lib/es6/components/DataTable/DataTable.js.map +1 -0
  58. package/lib/es6/components/DataTable/DataTable.types.js +2 -0
  59. package/lib/es6/components/DataTable/DataTable.types.js.map +1 -0
  60. package/lib/es6/components/DataTable/dataTable.shadow.css +17 -0
  61. package/lib/es6/components/Head/Column.js +309 -0
  62. package/lib/es6/components/Head/Column.js.map +1 -0
  63. package/lib/es6/components/Head/Column.types.js +2 -0
  64. package/lib/es6/components/Head/Column.types.js.map +1 -0
  65. package/lib/es6/components/Head/Group.js +108 -0
  66. package/lib/es6/components/Head/Group.js.map +1 -0
  67. package/lib/es6/components/Head/Group.type.js +2 -0
  68. package/lib/es6/components/Head/Group.type.js.map +1 -0
  69. package/lib/es6/components/Head/Head.js +199 -0
  70. package/lib/es6/components/Head/Head.js.map +1 -0
  71. package/lib/es6/components/Head/Head.types.js +2 -0
  72. package/lib/es6/components/Head/Head.types.js.map +1 -0
  73. package/lib/es6/components/Head/style.shadow.css +176 -0
  74. package/lib/es6/index.js +5 -2
  75. package/lib/es6/index.js.map +1 -1
  76. package/lib/es6/style/scroll-shadows.shadow.css +39 -5
  77. package/lib/es6/translations/en.json +6 -1
  78. package/lib/es6/utils.js +14 -6
  79. package/lib/es6/utils.js.map +1 -1
  80. package/lib/esm/components/Body/Body.mjs +392 -0
  81. package/lib/esm/components/Body/Cell.mjs +185 -0
  82. package/lib/esm/components/Body/MergedCells.mjs +23 -0
  83. package/lib/esm/components/Body/Row.mjs +218 -0
  84. package/lib/esm/components/Body/style.shadow.css +257 -0
  85. package/lib/esm/components/DataTable/DataTable.mjs +904 -0
  86. package/lib/esm/components/DataTable/dataTable.shadow.css +17 -0
  87. package/lib/esm/components/Head/Column.mjs +299 -0
  88. package/lib/esm/components/Head/Group.mjs +102 -0
  89. package/lib/esm/components/Head/Head.mjs +180 -0
  90. package/lib/esm/components/Head/style.shadow.css +176 -0
  91. package/lib/esm/index.mjs +8 -5
  92. package/lib/esm/style/scroll-shadows.shadow.css +41 -0
  93. package/lib/esm/translations/en.json.mjs +6 -1
  94. package/lib/esm/utils.mjs +6 -15
  95. package/lib/types/components/Body/Body.d.ts +8 -0
  96. package/lib/types/components/Body/Body.types.d.ts +56 -0
  97. package/lib/types/components/Body/Cell.d.ts +3 -0
  98. package/lib/types/components/Body/Cell.types.d.ts +20 -0
  99. package/lib/types/components/Body/MergedCells.d.ts +14 -0
  100. package/lib/types/components/Body/Row.d.ts +3 -0
  101. package/lib/types/components/Body/Row.types.d.ts +42 -0
  102. package/lib/types/components/DataTable/DataTable.d.ts +12 -0
  103. package/lib/types/components/DataTable/DataTable.types.d.ts +118 -0
  104. package/lib/types/components/Head/Column.d.ts +30 -0
  105. package/lib/types/components/Head/Column.types.d.ts +82 -0
  106. package/lib/types/components/Head/Group.d.ts +15 -0
  107. package/lib/types/components/Head/Group.type.d.ts +16 -0
  108. package/lib/types/components/Head/Head.d.ts +98 -0
  109. package/lib/types/components/Head/Head.types.d.ts +35 -0
  110. package/lib/types/index.d.ts +10 -2
  111. package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +5 -0
  112. package/lib/types/utils.d.ts +8 -4
  113. package/package.json +11 -6
  114. package/vite.config.ts +0 -3
  115. package/lib/cjs/Body.js +0 -475
  116. package/lib/cjs/Body.js.map +0 -1
  117. package/lib/cjs/DataTable.js +0 -622
  118. package/lib/cjs/DataTable.js.map +0 -1
  119. package/lib/cjs/Head.js +0 -399
  120. package/lib/cjs/Head.js.map +0 -1
  121. package/lib/cjs/style/data-table.shadow.css +0 -394
  122. package/lib/cjs/types.js.map +0 -1
  123. package/lib/es6/Body.js +0 -468
  124. package/lib/es6/Body.js.map +0 -1
  125. package/lib/es6/DataTable.js +0 -614
  126. package/lib/es6/DataTable.js.map +0 -1
  127. package/lib/es6/Head.js +0 -391
  128. package/lib/es6/Head.js.map +0 -1
  129. package/lib/es6/style/data-table.shadow.css +0 -394
  130. package/lib/es6/types.js +0 -2
  131. package/lib/es6/types.js.map +0 -1
  132. package/lib/esm/Body.mjs +0 -427
  133. package/lib/esm/DataTable.mjs +0 -582
  134. package/lib/esm/Head.mjs +0 -369
  135. package/lib/types/Body.d.ts +0 -61
  136. package/lib/types/DataTable.d.ts +0 -205
  137. package/lib/types/Head.d.ts +0 -45
  138. package/lib/types/types.d.ts +0 -73
@@ -0,0 +1,970 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import _objectSpread from "@babel/runtime/helpers/objectSpread2";
3
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
4
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
5
+ import _createClass from "@babel/runtime/helpers/createClass";
6
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
7
+ import _inherits from "@babel/runtime/helpers/inherits";
8
+ import _createSuper from "@babel/runtime/helpers/createSuper";
9
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
10
+ import { sstyled as _sstyled2 } from "@semcore/core";
11
+ import { sstyled as _sstyled } from "@semcore/core";
12
+ import { assignProps as _assignProps } from "@semcore/core";
13
+ import * as React from 'react';
14
+ import { Component, createComponent, lastInteraction, Root, sstyled } from '@semcore/core';
15
+ import { Box, ScreenReaderOnly, ScrollArea } from '@semcore/base-components';
16
+ import { Head } from '../Head/Head';
17
+ import { Body } from '../Body/Body';
18
+ /*!__reshadow-styles__:"./dataTable.shadow.css"*/
19
+ var style = ( /*__reshadow_css_start__*/_sstyled.insert( /*__inner_css_start__*/".___SDataTable_1iypx_gg_{display:grid;align-items:start;min-width:-moz-fit-content;min-width:fit-content}.___SDataTable_1iypx_gg_.__gridTemplateColumns_1iypx_gg_{grid-template-columns:var(--gridTemplateColumns_1iypx)}.___SDataTable_1iypx_gg_.__gridTemplateAreas_1iypx_gg_{grid-template-areas:var(--gridTemplateAreas_1iypx)}.___SDataTable_1iypx_gg_.__gridTemplateRows_1iypx_gg_{grid-template-rows:var(--gridTemplateRows_1iypx)}", /*__inner_css_end__*/"1iypx_gg_"),
20
+ /*__reshadow_css_end__*/
21
+ {
22
+ "__SDataTable": "___SDataTable_1iypx_gg_",
23
+ "_gridTemplateColumns": "__gridTemplateColumns_1iypx_gg_",
24
+ "--gridTemplateColumns": "--gridTemplateColumns_1iypx",
25
+ "_gridTemplateAreas": "__gridTemplateAreas_1iypx_gg_",
26
+ "--gridTemplateAreas": "--gridTemplateAreas_1iypx",
27
+ "_gridTemplateRows": "__gridTemplateRows_1iypx_gg_",
28
+ "--gridTemplateRows": "--gridTemplateRows_1iypx"
29
+ });
30
+ import { isFocusInside, hasFocusableIn } from '@semcore/core/lib/utils/use/useFocusLock';
31
+ import { getScrollOffsetValue } from '../../utils';
32
+ import findComponent from '@semcore/core/lib/utils/findComponent';
33
+ import { localizedMessages } from '../../translations/__intergalactic-dynamic-locales';
34
+ import i18nEnhance from '@semcore/core/lib/utils/enhances/i18nEnhance';
35
+ import uniqueIDEnhancement from '@semcore/core/lib/utils/uniqueID';
36
+ import { forkRef } from '@semcore/core/lib/utils/ref';
37
+ /*!__reshadow-styles__:"../../style/scroll-shadows.shadow.css"*/
38
+ var scrollStyles = ( /*__reshadow_css_start__*/_sstyled2.insert( /*__inner_css_start__*/".___SScrollArea_11h4o_gg_{width:-moz-fit-content;width:fit-content}.___SScrollArea_11h4o_gg_ .___SContainer_11h4o_gg_{overflow:visible;overflow:initial}.___SScrollArea_11h4o_gg_ .___SContainer_11h4o_gg_._scrollDirection_both_11h4o_gg_{overflow:auto}.___SScrollArea_11h4o_gg_ .___SContainer_11h4o_gg_._scrollDirection_horizontal_11h4o_gg_{overflow-x:auto;overflow-y:initial}.___SScrollArea_11h4o_gg_ .___SContainer_11h4o_gg_._scrollDirection_vertical_11h4o_gg_{overflow-x:initial;overflow-y:auto}.___SScrollArea_11h4o_gg_ .___SContainer_11h4o_gg_.__loading_11h4o_gg_{overflow:hidden}.___SScrollArea_11h4o_gg_ .___SContainer_11h4o_gg_.__headerHeight_11h4o_gg_{scroll-padding-top:var(--headerHeight_11h4o)}.___SScrollArea_11h4o_gg_ .___SShadowVertical_11h4o_gg_:before{display:none}.___SScrollArea_11h4o_gg_ .___SShadowHorizontal_11h4o_gg_:after,.___SScrollArea_11h4o_gg_ .___SShadowHorizontal_11h4o_gg_:before,.___SScrollArea_11h4o_gg_ .___SShadowVertical_11h4o_gg_:after{z-index:2}", /*__inner_css_end__*/"11h4o_gg_"),
39
+ /*__reshadow_css_end__*/
40
+ {
41
+ "__SScrollArea": "___SScrollArea_11h4o_gg_",
42
+ "__SContainer": "___SContainer_11h4o_gg_",
43
+ "_scrollDirection_both": "_scrollDirection_both_11h4o_gg_",
44
+ "_scrollDirection_horizontal": "_scrollDirection_horizontal_11h4o_gg_",
45
+ "_scrollDirection_vertical": "_scrollDirection_vertical_11h4o_gg_",
46
+ "_loading": "__loading_11h4o_gg_",
47
+ "_headerHeight": "__headerHeight_11h4o_gg_",
48
+ "--headerHeight": "--headerHeight_11h4o",
49
+ "__SShadowVertical": "___SShadowVertical_11h4o_gg_",
50
+ "__SShadowHorizontal": "___SShadowHorizontal_11h4o_gg_"
51
+ });
52
+ import { hasParent } from '@semcore/core/lib/utils/hasParent';
53
+ import trottle from '@semcore/core/lib/utils/rafTrottle';
54
+ import { MergedColumnsCell, MergedRowsCell } from '../Body/MergedCells';
55
+ import { NoData } from '@semcore/widget-empty';
56
+ export var ACCORDION = Symbol('accordion');
57
+ export var ROW_GROUP = Symbol('ROW_GROUP');
58
+ export var UNIQ_ROW_KEY = Symbol('UNIQ_ROW_KEY');
59
+ export var SELECT_ALL = Symbol('SELECT_ALL');
60
+ export var ROW_INDEX = Symbol('ROW_INDEX');
61
+ var SCROLL_BAR_HEIGHT = 12;
62
+ var DataTableRoot = /*#__PURE__*/function (_Component) {
63
+ _inherits(DataTableRoot, _Component);
64
+ var _super = _createSuper(DataTableRoot);
65
+ function DataTableRoot(props) {
66
+ var _this;
67
+ _classCallCheck(this, DataTableRoot);
68
+ _this = _super.call(this, props);
69
+ _defineProperty(_assertThisInitialized(_this), "columns", []);
70
+ _defineProperty(_assertThisInitialized(_this), "treeColumns", []);
71
+ _defineProperty(_assertThisInitialized(_this), "hasGroups", false);
72
+ _defineProperty(_assertThisInitialized(_this), "focusedCell", [-1, -1]);
73
+ _defineProperty(_assertThisInitialized(_this), "scrollAreaRef", /*#__PURE__*/React.createRef());
74
+ _defineProperty(_assertThisInitialized(_this), "tableContainerRef", /*#__PURE__*/React.createRef());
75
+ _defineProperty(_assertThisInitialized(_this), "tableRef", /*#__PURE__*/React.createRef());
76
+ _defineProperty(_assertThisInitialized(_this), "headerRef", /*#__PURE__*/React.createRef());
77
+ _defineProperty(_assertThisInitialized(_this), "spinnerRef", /*#__PURE__*/React.createRef());
78
+ _defineProperty(_assertThisInitialized(_this), "gridAreaGroupMap", new Map());
79
+ _defineProperty(_assertThisInitialized(_this), "columnsSplitter", '/');
80
+ _defineProperty(_assertThisInitialized(_this), "rows", []);
81
+ _defineProperty(_assertThisInitialized(_this), "selectAllMessageTimer", 0);
82
+ _defineProperty(_assertThisInitialized(_this), "state", {
83
+ scrollTop: 0,
84
+ scrollDirection: 'down',
85
+ selectAllMessage: ''
86
+ });
87
+ _defineProperty(_assertThisInitialized(_this), "handleSelectRow", function (isSelected, selectedRowIndex, row, event) {
88
+ var _this$asProps = _this.asProps,
89
+ selectedRows = _this$asProps.selectedRows,
90
+ onSelectedRowsChange = _this$asProps.onSelectedRowsChange,
91
+ data = _this$asProps.data;
92
+ if (selectedRows && onSelectedRowsChange) {
93
+ var newSelectedRows = new Set(selectedRows);
94
+ if (isSelected && !newSelectedRows.has(selectedRowIndex)) {
95
+ newSelectedRows.add(selectedRowIndex);
96
+ } else if (!isSelected && newSelectedRows.has(selectedRowIndex)) {
97
+ newSelectedRows["delete"](selectedRowIndex);
98
+ }
99
+ onSelectedRowsChange(_toConsumableArray(newSelectedRows), event, {
100
+ selectedRowIndex: selectedRowIndex,
101
+ isSelected: isSelected,
102
+ row: row
103
+ });
104
+ }
105
+ });
106
+ _defineProperty(_assertThisInitialized(_this), "setSelectAllMessage", function (selectedAll) {
107
+ if (_this.selectAllMessageTimer) {
108
+ clearTimeout(_this.selectAllMessageTimer);
109
+ }
110
+ var getI18nText = _this.asProps.getI18nText;
111
+ var message = getI18nText(selectedAll ? 'DataTable.allItemsSelected:aria-live' : 'DataTable.allItemsDeselected:aria-live');
112
+ _this.setState({
113
+ selectAllMessage: message
114
+ });
115
+ _this.selectAllMessageTimer = window.setTimeout(function () {
116
+ _this.setState({
117
+ selectAllMessage: ''
118
+ });
119
+ }, 5000);
120
+ });
121
+ _defineProperty(_assertThisInitialized(_this), "getRow", function (index) {
122
+ var _this$tableRef$curren;
123
+ return (_this$tableRef$curren = _this.tableRef.current) === null || _this$tableRef$curren === void 0 ? void 0 : _this$tableRef$curren.querySelector("[aria-rowindex=\"".concat(index + 1, "\"]"));
124
+ });
125
+ _defineProperty(_assertThisInitialized(_this), "hasFocusableInHeader", function () {
126
+ var hasFocusable = _this.columns.some(function (column) {
127
+ var columnElement = column.ref.current;
128
+ return columnElement && hasFocusableIn(columnElement);
129
+ });
130
+ return hasFocusable;
131
+ });
132
+ _defineProperty(_assertThisInitialized(_this), "onExpandRow", function (expandedRow) {
133
+ var expandedRows = _this.asProps.expandedRows;
134
+ if (expandedRows.has(expandedRow[UNIQ_ROW_KEY])) {
135
+ expandedRows["delete"](expandedRow[UNIQ_ROW_KEY]);
136
+ } else {
137
+ expandedRows.add(expandedRow[UNIQ_ROW_KEY]);
138
+ }
139
+ _this.handlers.expandedRows(new Set(_toConsumableArray(expandedRows)));
140
+ });
141
+ _defineProperty(_assertThisInitialized(_this), "changeFocusCell", function (rowIndex, colIndex, direction) {
142
+ var _this$tableRef$curren2, _this$tableRef$curren3;
143
+ var hasFocusable = _this.hasFocusableInHeader();
144
+ var maxCol = _this.columns.length - 1;
145
+ var maxRow = _this.totalRows || 1;
146
+ var currentRow = (_this$tableRef$curren2 = _this.tableRef.current) === null || _this$tableRef$curren2 === void 0 ? void 0 : _this$tableRef$curren2.querySelector("[aria-rowindex=\"".concat(_this.focusedCell[0] + 1, "\"]"));
147
+ var headerCells = (_this$tableRef$curren3 = _this.tableRef.current) === null || _this$tableRef$curren3 === void 0 ? void 0 : _this$tableRef$curren3.querySelectorAll('[role=columnheader]');
148
+ var currentCell = currentRow === null || currentRow === void 0 ? void 0 : currentRow.querySelector("[role=gridcell][aria-colindex='".concat(_this.focusedCell[1] + 1, "']"));
149
+ var currentHeaderCell = headerCells === null || headerCells === void 0 ? void 0 : headerCells.item(_this.focusedCell[1]);
150
+ var changed = true;
151
+ var newRow = _this.focusedCell[0] + rowIndex;
152
+ var newCol = _this.focusedCell[1] + colIndex;
153
+ if ((hasFocusable && newRow < 0 || !hasFocusable && newRow < 1 || newRow > maxRow) && newRow !== _this.focusedCell[0]) {
154
+ changed = false;
155
+ }
156
+ if ((newCol < 0 || newCol > maxCol) && newCol !== _this.focusedCell[1]) {
157
+ changed = false;
158
+ }
159
+ if (!changed) return;
160
+ var row = _this.getRow(newRow);
161
+ var cell = row === null || row === void 0 ? void 0 : row.querySelector(":scope > [role=gridcell][aria-colindex=\"".concat(newCol + 1, "\"], :scope > [role=columnheader][aria-colindex=\"").concat(newCol + 1, "\"], :scope > div > [role=columnheader][aria-colindex=\"").concat(newCol + 1, "\"]"));
162
+ if (cell instanceof HTMLElement && currentCell !== cell) {
163
+ _this.focusedCell = [newRow, newCol];
164
+ currentCell === null || currentCell === void 0 ? void 0 : currentCell.setAttribute('inert', '');
165
+ if (currentCell !== currentHeaderCell) {
166
+ currentCell === null || currentCell === void 0 ? void 0 : currentCell.removeAttribute('aria-describedby');
167
+ }
168
+ var headerCell = headerCells === null || headerCells === void 0 ? void 0 : headerCells.item(newCol);
169
+ var describedBy = headerCell === null || headerCell === void 0 ? void 0 : headerCell.getAttribute('aria-describedby');
170
+ cell.removeAttribute('inert');
171
+ if (headerCell !== cell && describedBy) {
172
+ cell.setAttribute('aria-describedby', describedBy);
173
+ }
174
+ cell === null || cell === void 0 ? void 0 : cell.focus();
175
+ if (newRow !== 0) {
176
+ currentHeaderCell === null || currentHeaderCell === void 0 ? void 0 : currentHeaderCell.setAttribute('inert', '');
177
+ var _headerCell = headerCells === null || headerCells === void 0 ? void 0 : headerCells.item(newCol);
178
+ _headerCell === null || _headerCell === void 0 ? void 0 : _headerCell.removeAttribute('inert');
179
+ }
180
+ } else if (cell === null && currentCell instanceof HTMLElement) {
181
+ var rowI = rowIndex;
182
+ var colI = colIndex;
183
+ if (direction === 'left' || direction === 'right') {
184
+ var _currentCell$parentEl, _row$children;
185
+ // left/right
186
+ if (currentCell.dataset.groupedBy === 'colgroup' || Number((_currentCell$parentEl = currentCell.parentElement) === null || _currentCell$parentEl === void 0 ? void 0 : _currentCell$parentEl.getAttribute('aria-rowindex')) === 2 || Array.from((_row$children = row === null || row === void 0 ? void 0 : row.children) !== null && _row$children !== void 0 ? _row$children : []).indexOf(currentCell) > 0) {
187
+ colI = direction === 'left' ? colI - 1 : colI + 1;
188
+ } else {
189
+ rowI = rowI - 1;
190
+ }
191
+ } else if (direction === 'up' || direction === 'down') {
192
+ // top/bottom
193
+ if (currentCell.dataset.groupedBy === 'rowgroup' || Number(currentCell.getAttribute('aria-colindex')) === 1) {
194
+ rowI = direction === 'up' ? rowI - 1 : rowI + 1;
195
+ } else {
196
+ colI = colI - 1;
197
+ }
198
+ }
199
+ _this.changeFocusCell(rowI, colI, direction);
200
+ } else if (cell === null && currentHeaderCell instanceof HTMLElement && direction === 'down') {
201
+ var _colI = colIndex - 1;
202
+ _this.changeFocusCell(rowIndex, _colI, direction);
203
+ } else if (row === null && _this.focusedCell[0] === 0 && direction === 'down' && _this.asProps.virtualScroll) {
204
+ _this.changeFocusCell(rowIndex + 1, colIndex, direction);
205
+ }
206
+ });
207
+ _defineProperty(_assertThisInitialized(_this), "handleKeyDown", function (e) {
208
+ switch (e.key) {
209
+ case 'Tab':
210
+ {
211
+ _this.setInert(true);
212
+ break;
213
+ }
214
+ case 'ArrowLeft':
215
+ {
216
+ e.preventDefault();
217
+ _this.changeFocusCell(0, -1, 'left');
218
+ break;
219
+ }
220
+ case 'ArrowRight':
221
+ {
222
+ e.preventDefault();
223
+ _this.changeFocusCell(0, 1, 'right');
224
+ break;
225
+ }
226
+ case 'ArrowUp':
227
+ {
228
+ e.preventDefault();
229
+ _this.changeFocusCell(-1, 0, 'up');
230
+ break;
231
+ }
232
+ case 'ArrowDown':
233
+ {
234
+ e.preventDefault();
235
+ _this.changeFocusCell(1, 0, 'down');
236
+ break;
237
+ }
238
+ }
239
+ });
240
+ _defineProperty(_assertThisInitialized(_this), "initFocusableCell", function () {
241
+ var hasFocusable = _this.hasFocusableInHeader();
242
+ if (hasFocusable) {
243
+ _this.focusedCell = [0, 0];
244
+ } else {
245
+ _this.focusedCell = [1, 0];
246
+ }
247
+ });
248
+ _defineProperty(_assertThisInitialized(_this), "handleScroll", trottle(function (e) {
249
+ var scrollTop = e.target.scrollTop;
250
+ var scrollDirection = scrollTop > _this.state.scrollTop ? 'down' : 'up';
251
+ _this.setState({
252
+ scrollTop: scrollTop,
253
+ scrollDirection: scrollDirection
254
+ });
255
+ }));
256
+ _defineProperty(_assertThisInitialized(_this), "handleFocus", function (e) {
257
+ if (_this.asProps.loading) {
258
+ var _this$spinnerRef$curr;
259
+ (_this$spinnerRef$curr = _this.spinnerRef.current) === null || _this$spinnerRef$curr === void 0 ? void 0 : _this$spinnerRef$curr.focus();
260
+ e.currentTarget.setAttribute('tabIndex', '-1');
261
+ } else if ((!e.relatedTarget || !isFocusInside(e.currentTarget, e.relatedTarget)) && lastInteraction.isKeyboard()) {
262
+ var _row;
263
+ if (_this.focusedCell[0] === -1 && _this.focusedCell[1] === -1) {
264
+ _this.initFocusableCell();
265
+ }
266
+ _this.setInert(true);
267
+ var row = _this.getRow(_this.focusedCell[0]);
268
+ if (!row) {
269
+ _this.initFocusableCell();
270
+ row = _this.getRow(_this.focusedCell[0]);
271
+ }
272
+ if (!row && _this.asProps.virtualScroll) {
273
+ var _this$tableRef$curren4;
274
+ var firstAvailableCell = (_this$tableRef$curren4 = _this.tableRef.current) === null || _this$tableRef$curren4 === void 0 ? void 0 : _this$tableRef$curren4.querySelector("[role=\"gridcell\"]");
275
+ var firstAvailableRow = firstAvailableCell === null || firstAvailableCell === void 0 ? void 0 : firstAvailableCell.parentElement;
276
+ if (firstAvailableCell && firstAvailableRow) {
277
+ var _Number, _Number2;
278
+ var colIndex = ((_Number = Number(firstAvailableCell.getAttribute('aria-colindex'))) !== null && _Number !== void 0 ? _Number : 1) - 1;
279
+ var rowIndex = ((_Number2 = Number(firstAvailableRow.getAttribute('aria-rowindex'))) !== null && _Number2 !== void 0 ? _Number2 : 1) - 1;
280
+ _this.focusedCell[0] = rowIndex;
281
+ _this.focusedCell[1] = colIndex;
282
+ row = firstAvailableRow;
283
+ }
284
+ }
285
+ var cell = (_row = row) === null || _row === void 0 ? void 0 : _row.querySelectorAll('[role=gridcell], [role=columnheader]').item(_this.focusedCell[1]);
286
+ cell === null || cell === void 0 ? void 0 : cell.removeAttribute('inert');
287
+ if (cell instanceof HTMLElement) {
288
+ if (hasParent(e.target, cell)) {
289
+ e.target.focus();
290
+ } else {
291
+ cell.focus();
292
+ }
293
+ }
294
+ e.currentTarget.setAttribute('tabIndex', '-1');
295
+ }
296
+ });
297
+ _defineProperty(_assertThisInitialized(_this), "handleBlur", function (e) {
298
+ var relatedTarget = e.relatedTarget;
299
+ var tableElement = _this.tableRef.current;
300
+ if (tableElement && (!relatedTarget || !isFocusInside(tableElement, relatedTarget) || !lastInteraction.isKeyboard())) {
301
+ _this.setInert(false);
302
+ tableElement.setAttribute('tabIndex', '0');
303
+ }
304
+ });
305
+ _defineProperty(_assertThisInitialized(_this), "handleMouseMove", function () {
306
+ _this.setInert(false);
307
+ });
308
+ _defineProperty(_assertThisInitialized(_this), "handleBackFromAccordion", function (cellIndex) {
309
+ _this.changeFocusCell(-1, cellIndex === -1 ? 0 : cellIndex, 'up');
310
+ });
311
+ if (props.children) {
312
+ _this.columns = _this.calculateColumns();
313
+ } else {
314
+ var cols = _this.calculateColumnsFromConfig();
315
+ _this.columns = cols[0];
316
+ _this.treeColumns = cols[1];
317
+ }
318
+ _this.rows = _this.calculateRows();
319
+ return _this;
320
+ }
321
+ _createClass(DataTableRoot, [{
322
+ key: "uncontrolledProps",
323
+ value: function uncontrolledProps() {
324
+ return {
325
+ expandedRows: new Set()
326
+ };
327
+ }
328
+ }, {
329
+ key: "componentDidMount",
330
+ value: function componentDidMount() {
331
+ this.forceUpdate();
332
+ }
333
+ }, {
334
+ key: "componentDidUpdate",
335
+ value: function componentDidUpdate(prevProps) {
336
+ var _this$asProps2 = this.asProps,
337
+ data = _this$asProps2.data,
338
+ selectedRows = _this$asProps2.selectedRows;
339
+ if (prevProps.data !== data) {
340
+ this.rows = this.calculateRows();
341
+ this.forceUpdate();
342
+ }
343
+ if (prevProps.selectedRows !== selectedRows && selectedRows !== undefined) {
344
+ if (prevProps.selectedRows.length < data.length && selectedRows.length === data.length) {
345
+ this.setSelectAllMessage(true);
346
+ } else if (prevProps.selectedRows.length > 0 && selectedRows.length === 0) {
347
+ this.setSelectAllMessage(false);
348
+ }
349
+ }
350
+ }
351
+ }, {
352
+ key: "totalRows",
353
+ get: function get() {
354
+ var _this$asProps3 = this.asProps,
355
+ totalRows = _this$asProps3.totalRows,
356
+ expandedRows = _this$asProps3.expandedRows;
357
+ var flatRows = this.rows.flat();
358
+ var expandedRowsCount = Array.from(expandedRows !== null && expandedRows !== void 0 ? expandedRows : []).reduce(function (acc, rowKey) {
359
+ var dtRow = flatRows.find(function (el) {
360
+ return el[UNIQ_ROW_KEY] === rowKey;
361
+ });
362
+ if (dtRow) {
363
+ var _expandedRows = dtRow[ACCORDION];
364
+ if (Array.isArray(_expandedRows)) {
365
+ acc = acc + _expandedRows.length;
366
+ } else {
367
+ acc = acc + 1;
368
+ }
369
+ }
370
+ return acc;
371
+ }, 0);
372
+ if (totalRows !== undefined) {
373
+ return totalRows + expandedRowsCount;
374
+ }
375
+ var rows = this.rows.reduce(function (acc, item) {
376
+ acc = acc + 1;
377
+ if (Array.isArray(item)) {
378
+ acc = acc + item.length;
379
+ }
380
+ return acc;
381
+ }, 0);
382
+ return rows + expandedRowsCount;
383
+ }
384
+ }, {
385
+ key: "gridSettings",
386
+ get: function get() {
387
+ var columns = this.columns;
388
+ var gridTemplateColumns = columns.map(function (c) {
389
+ return c.gridColumnWidth;
390
+ });
391
+ var gridTemplateAreas = columns.map(function (c) {
392
+ return c.name;
393
+ });
394
+ return {
395
+ gridTemplateColumns: gridTemplateColumns,
396
+ gridTemplateAreas: gridTemplateAreas
397
+ };
398
+ }
399
+ }, {
400
+ key: "getHeadProps",
401
+ value: function getHeadProps() {
402
+ var _this2 = this;
403
+ var _this$asProps4 = this.asProps,
404
+ use = _this$asProps4.use,
405
+ compact = _this$asProps4.compact,
406
+ sort = _this$asProps4.sort,
407
+ onSortChange = _this$asProps4.onSortChange,
408
+ getI18nText = _this$asProps4.getI18nText,
409
+ uid = _this$asProps4.uid,
410
+ headerProps = _this$asProps4.headerProps,
411
+ onSelectedRowsChange = _this$asProps4.onSelectedRowsChange,
412
+ selectedRows = _this$asProps4.selectedRows,
413
+ sideIndents = _this$asProps4.sideIndents;
414
+ var _this$gridSettings = this.gridSettings,
415
+ gridTemplateColumns = _this$gridSettings.gridTemplateColumns,
416
+ gridTemplateAreas = _this$gridSettings.gridTemplateAreas;
417
+ return _objectSpread({
418
+ columns: this.columns,
419
+ treeColumns: this.treeColumns,
420
+ use: use,
421
+ tableRef: this.tableRef,
422
+ compact: Boolean(compact),
423
+ sort: sort,
424
+ onSortChange: onSortChange,
425
+ getI18nText: getI18nText,
426
+ uid: uid,
427
+ ref: this.headerRef,
428
+ gridAreaGroupMap: this.gridAreaGroupMap,
429
+ gridTemplateColumns: gridTemplateColumns,
430
+ gridTemplateAreas: gridTemplateAreas,
431
+ sideIndents: sideIndents,
432
+ totalRows: this.totalRows,
433
+ selectedRows: selectedRows,
434
+ onChangeSelectAll: function onChangeSelectAll(value, e) {
435
+ var selectedRowsIndexes = value ? new Array(_this2.totalRows).fill(undefined).map(function (_, i) {
436
+ return i;
437
+ }) : [];
438
+ onSelectedRowsChange === null || onSelectedRowsChange === void 0 ? void 0 : onSelectedRowsChange(selectedRowsIndexes, e);
439
+ }
440
+ }, headerProps);
441
+ }
442
+ }, {
443
+ key: "getBodyProps",
444
+ value: function getBodyProps() {
445
+ var _this$asProps5 = this.asProps,
446
+ use = _this$asProps5.use,
447
+ compact = _this$asProps5.compact,
448
+ loading = _this$asProps5.loading,
449
+ getI18nText = _this$asProps5.getI18nText,
450
+ expandedRows = _this$asProps5.expandedRows,
451
+ virtualScroll = _this$asProps5.virtualScroll,
452
+ uid = _this$asProps5.uid,
453
+ rowProps = _this$asProps5.rowProps,
454
+ renderCell = _this$asProps5.renderCell,
455
+ headerProps = _this$asProps5.headerProps,
456
+ renderEmptyData = _this$asProps5.renderEmptyData,
457
+ sideIndents = _this$asProps5.sideIndents,
458
+ selectedRows = _this$asProps5.selectedRows;
459
+ var _this$gridSettings2 = this.gridSettings,
460
+ gridTemplateColumns = _this$gridSettings2.gridTemplateColumns,
461
+ gridTemplateAreas = _this$gridSettings2.gridTemplateAreas;
462
+ return {
463
+ columns: this.columns,
464
+ rows: this.rows,
465
+ flatRows: this.rows.flat(),
466
+ use: use,
467
+ compact: Boolean(compact),
468
+ gridTemplateColumns: gridTemplateColumns,
469
+ gridTemplateAreas: gridTemplateAreas,
470
+ loading: loading,
471
+ headerHeight: this.getHeaderHeight(),
472
+ stickyHeader: headerProps === null || headerProps === void 0 ? void 0 : headerProps.sticky,
473
+ getI18nText: getI18nText,
474
+ expandedRows: expandedRows,
475
+ onExpandRow: this.onExpandRow,
476
+ spinnerRef: this.spinnerRef,
477
+ scrollTop: this.state.scrollTop,
478
+ scrollDirection: this.state.scrollDirection,
479
+ tableContainerRef: this.tableContainerRef,
480
+ tableRef: this.tableRef,
481
+ scrollAreaRef: this.scrollAreaRef,
482
+ onBackFromAccordion: this.handleBackFromAccordion,
483
+ virtualScroll: virtualScroll,
484
+ hasGroups: this.hasGroups,
485
+ uid: uid,
486
+ rowProps: rowProps,
487
+ renderCell: renderCell,
488
+ renderEmptyData: renderEmptyData,
489
+ sideIndents: sideIndents,
490
+ selectedRows: selectedRows,
491
+ onSelectRow: this.handleSelectRow
492
+ };
493
+ }
494
+ }, {
495
+ key: "setInert",
496
+ value: function setInert(value) {
497
+ var _this$tableRef$curren5;
498
+ var cells = (_this$tableRef$curren5 = this.tableRef.current) === null || _this$tableRef$curren5 === void 0 ? void 0 : _this$tableRef$curren5.querySelectorAll('[role=gridcell], [role=columnheader]');
499
+ cells === null || cells === void 0 ? void 0 : cells.forEach(function (cell) {
500
+ if (value === true) {
501
+ cell.setAttribute('inert', '');
502
+ } else {
503
+ cell.removeAttribute('inert');
504
+ }
505
+ });
506
+ }
507
+ }, {
508
+ key: "render",
509
+ value: function render() {
510
+ var _ref = this.asProps,
511
+ _ref2;
512
+ var SDataTable = Box;
513
+ var _this$asProps6 = this.asProps,
514
+ Children = _this$asProps6.Children,
515
+ styles = _this$asProps6.styles,
516
+ w = _this$asProps6.w,
517
+ wMax = _this$asProps6.wMax,
518
+ wMin = _this$asProps6.wMin,
519
+ h = _this$asProps6.h,
520
+ hMax = _this$asProps6.hMax,
521
+ hMin = _this$asProps6.hMin,
522
+ virtualScroll = _this$asProps6.virtualScroll,
523
+ children = _this$asProps6.children,
524
+ headerProps = _this$asProps6.headerProps,
525
+ loading = _this$asProps6.loading,
526
+ selectedRows = _this$asProps6.selectedRows;
527
+ var _getScrollOffsetValue = getScrollOffsetValue(this.columns),
528
+ _getScrollOffsetValue2 = _slicedToArray(_getScrollOffsetValue, 2),
529
+ offsetLeftSum = _getScrollOffsetValue2[0],
530
+ offsetRightSum = _getScrollOffsetValue2[1];
531
+ var _this$gridSettings3 = this.gridSettings,
532
+ gridTemplateColumns = _this$gridSettings3.gridTemplateColumns,
533
+ gridTemplateAreas = _this$gridSettings3.gridTemplateAreas;
534
+ var Head = findComponent(Children, ['DataTable.Head']);
535
+ var headerPropsToCheck = headerProps !== null && headerProps !== void 0 ? headerProps : Head === null || Head === void 0 ? void 0 : Head.props;
536
+ var headerHeight = this.getHeaderHeight();
537
+ var topOffset = headerPropsToCheck !== null && headerPropsToCheck !== void 0 && headerPropsToCheck.sticky || headerPropsToCheck !== null && headerPropsToCheck !== void 0 && headerPropsToCheck.withScrollBar ? headerHeight : undefined;
538
+ var width = w !== null && w !== void 0 ? w : this.columns.some(function (c) {
539
+ return c.gridColumnWidth === 'auto' || c.gridColumnWidth === '1fr';
540
+ }) ? '100%' : undefined;
541
+ var gridTemplateRows = undefined;
542
+ if (virtualScroll && typeof virtualScroll !== 'boolean' && 'rowHeight' in virtualScroll) {
543
+ gridTemplateRows = "auto auto repeat(".concat(this.totalRows, ", minmax(").concat(virtualScroll.rowHeight, "px, auto)");
544
+ }
545
+ var scrollDirection = undefined;
546
+ var hasWidthSettings = Boolean(w) && w !== '100%' || Boolean(wMax);
547
+ var hasHeightSettings = Boolean(h) && h !== 'fit-content' || Boolean(hMax);
548
+ if (hasWidthSettings && !hasHeightSettings) {
549
+ scrollDirection = 'horizontal';
550
+ } else if (hasHeightSettings && !hasWidthSettings) {
551
+ scrollDirection = 'vertical';
552
+ } else if (hasWidthSettings && hasHeightSettings) {
553
+ scrollDirection = 'both';
554
+ }
555
+ return _ref2 = sstyled(styles), /*#__PURE__*/React.createElement(ScrollArea, _ref2.cn("ScrollArea", {
556
+ "leftOffset": offsetLeftSum,
557
+ "rightOffset": offsetRightSum,
558
+ "topOffset": topOffset,
559
+ "w": width,
560
+ "wMax": wMax,
561
+ "wMin": wMin,
562
+ "h": h,
563
+ "hMax": hMax,
564
+ "hMin": hMin,
565
+ "shadow": true,
566
+ "ref": this.scrollAreaRef,
567
+ "container": this.tableContainerRef,
568
+ "styles": scrollStyles,
569
+ "onScroll": this.handleScroll,
570
+ "disableAutofocusToContent": true
571
+ }), /*#__PURE__*/React.createElement(ScrollArea.Container, {
572
+ tabIndex: -1
573
+ // @ts-ignore
574
+ ,
575
+ scrollDirection: scrollDirection
576
+ // @ts-ignore
577
+ ,
578
+ loading: loading,
579
+ headerHeight: "".concat(headerHeight, "px")
580
+ }, /*#__PURE__*/React.createElement(SDataTable, _ref2.cn("SDataTable", _objectSpread({}, _assignProps({
581
+ "ref": forkRef(this.tableRef, this.tableContainerRef),
582
+ "role": 'grid',
583
+ "onKeyDown": this.handleKeyDown,
584
+ "onMouseMove": this.handleMouseMove,
585
+ "tabIndex": 0,
586
+ "onFocus": this.handleFocus,
587
+ "onBlur": this.handleBlur,
588
+ "aria-rowcount": this.totalRows,
589
+ "aria-colcount": this.columns.length,
590
+ "gridTemplateColumns": gridTemplateColumns.join(' '),
591
+ "gridTemplateAreas": gridTemplateAreas.join(' '),
592
+ "gridTemplateRows": gridTemplateRows,
593
+ "w": '100%',
594
+ "use:data": undefined,
595
+ "use:w": undefined,
596
+ "use:wMax": undefined,
597
+ "use:wMin": undefined,
598
+ "use:h": undefined,
599
+ "use:hMax": undefined,
600
+ "use:hMin": undefined
601
+ }, _ref))), children ? /*#__PURE__*/React.createElement(Children, _ref2.cn("Children", {})) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(DataTable.Head, null), /*#__PURE__*/React.createElement(DataTable.Body, null)))), (headerPropsToCheck === null || headerPropsToCheck === void 0 ? void 0 : headerPropsToCheck.withScrollBar) && topOffset && !loading && /*#__PURE__*/React.createElement(ScrollArea.Bar, {
602
+ orientation: "horizontal",
603
+ top: topOffset - SCROLL_BAR_HEIGHT,
604
+ zIndex: 10
605
+ }), !loading && /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ScrollArea.Bar, {
606
+ orientation: "horizontal",
607
+ zIndex: 10
608
+ }), /*#__PURE__*/React.createElement(ScrollArea.Bar, {
609
+ orientation: "vertical",
610
+ zIndex: 10
611
+ })), selectedRows !== undefined && /*#__PURE__*/React.createElement(ScreenReaderOnly, _ref2.cn("ScreenReaderOnly", {
612
+ "aria-live": 'polite',
613
+ "role": 'status'
614
+ }), this.state.selectAllMessage));
615
+ }
616
+ }, {
617
+ key: "calculateColumns",
618
+ value: function calculateColumns() {
619
+ var _this3 = this;
620
+ var _this$props = this.props,
621
+ children = _this$props.children,
622
+ data = _this$props.data,
623
+ selectedRows = _this$props.selectedRows;
624
+ var HeadComponent = findComponent(children, ['Head']);
625
+ this.hasGroups = findComponent(HeadComponent.props.children, ['Head.Group']) !== undefined;
626
+ var columnIndex = 0;
627
+ var groupIndex = 0;
628
+ var gridColumnIndex = selectedRows ? 2 : 1;
629
+ var calculateGridTemplateColumn = this.calculateGridTemplateColumn.bind(this);
630
+ var columns = [];
631
+ if (selectedRows) {
632
+ var column = {
633
+ name: SELECT_ALL.toString(),
634
+ // @ts-ignore
635
+ ref: function ref(node) {
636
+ if (node) {
637
+ var calculatedWidth = node.getBoundingClientRect().width;
638
+ var calculatedHeight = node.getBoundingClientRect().height;
639
+ column.calculatedWidth = calculatedWidth;
640
+ column.calculatedHeight = calculatedHeight;
641
+ }
642
+ this.ref.current = node;
643
+ },
644
+ gridColumnWidth: '40px',
645
+ calculatedWidth: 0,
646
+ calculatedHeight: 0,
647
+ alignItems: 'flex-start'
648
+ };
649
+ columns.push(column);
650
+ }
651
+ var makeColumn = function makeColumn(columnElement, parent, isFirst, isLast) {
652
+ var _columnElement$props$, _ref3, _columnElement$props$2;
653
+ var leftBordersFromParent = isFirst && ((parent === null || parent === void 0 ? void 0 : parent.props.borders) === 'both' || (parent === null || parent === void 0 ? void 0 : parent.props.borders) === 'left') ? 'left' : undefined;
654
+ var rightBordersFromParent = isLast && ((parent === null || parent === void 0 ? void 0 : parent.props.borders) === 'both' || (parent === null || parent === void 0 ? void 0 : parent.props.borders) === 'right') ? 'right' : undefined;
655
+ var column = {
656
+ name: columnElement.props.name,
657
+ // @ts-ignore
658
+ ref: function ref(node) {
659
+ if (node) {
660
+ var calculatedWidth = node.getBoundingClientRect().width;
661
+ var calculatedHeight = node.getBoundingClientRect().height;
662
+ column.calculatedWidth = calculatedWidth;
663
+ column.calculatedHeight = calculatedHeight;
664
+ }
665
+ this.ref.current = node;
666
+ },
667
+ gridColumnWidth: calculateGridTemplateColumn(columnElement),
668
+ fixed: (_columnElement$props$ = columnElement.props.fixed) !== null && _columnElement$props$ !== void 0 ? _columnElement$props$ : parent === null || parent === void 0 ? void 0 : parent.props.fixed,
669
+ calculatedWidth: 0,
670
+ calculatedHeight: 0,
671
+ borders: (_ref3 = (_columnElement$props$2 = columnElement.props.borders) !== null && _columnElement$props$2 !== void 0 ? _columnElement$props$2 : leftBordersFromParent) !== null && _ref3 !== void 0 ? _ref3 : rightBordersFromParent,
672
+ parent: parent,
673
+ flexWrap: columnElement.props.flexWrap,
674
+ alignItems: columnElement.props.alignItems,
675
+ alignContent: columnElement.props.alignContent,
676
+ justifyContent: columnElement.props.justifyContent
677
+ };
678
+ return column;
679
+ };
680
+ var childIsColumn = function childIsColumn(child) {
681
+ return child.type === Head.Column;
682
+ };
683
+ var childIsGroup = function childIsGroup(child) {
684
+ return child.type === Head.Group;
685
+ };
686
+ React.Children.forEach(HeadComponent.props.children, function (child, i) {
687
+ if (! /*#__PURE__*/React.isValidElement(child)) return;
688
+ if (childIsColumn(child)) {
689
+ var col = makeColumn(child);
690
+ col.gridArea = "1 / ".concat(gridColumnIndex, " / ").concat(_this3.hasGroups ? '3' : '2', " / ").concat(gridColumnIndex + 1);
691
+ columnIndex++;
692
+ gridColumnIndex++;
693
+ columns.push(col);
694
+ } else if (childIsGroup(child)) {
695
+ var Group = child;
696
+ var childCount = React.Children.count(child.props.children);
697
+ var initGridColumn = gridColumnIndex;
698
+ React.Children.forEach(child.props.children, function (child, j) {
699
+ if ((child === null || child === void 0 ? void 0 : child.type) === Head.Column) {
700
+ var isFirst = j === 0;
701
+ var isLast = j === childCount - 1;
702
+ var _col = makeColumn(child, Group, isFirst, isLast);
703
+ if (i === 0 && j === 0 && data.some(function (d) {
704
+ return d[ACCORDION];
705
+ })) {
706
+ gridColumnIndex++;
707
+ _col.gridArea = "2 / ".concat(gridColumnIndex - 1, " / 3 / ").concat(gridColumnIndex + 1);
708
+ } else {
709
+ _col.gridArea = "2 / ".concat(gridColumnIndex, " / 3 / ").concat(gridColumnIndex + 1);
710
+ }
711
+ _col.gridArea = "2 / ".concat(gridColumnIndex, " / 3 / ").concat(gridColumnIndex + 1);
712
+ columnIndex++;
713
+ gridColumnIndex++;
714
+ columns.push(_col);
715
+ }
716
+ });
717
+ _this3.gridAreaGroupMap.set(groupIndex, "1 / ".concat(initGridColumn, " / 2 / ").concat(gridColumnIndex));
718
+ groupIndex++;
719
+ }
720
+ });
721
+ return columns.filter(Boolean);
722
+ }
723
+ }, {
724
+ key: "calculateColumnsFromConfig",
725
+ value: function calculateColumnsFromConfig() {
726
+ var _this4 = this;
727
+ var _this$props2 = this.props,
728
+ columns = _this$props2.columns,
729
+ data = _this$props2.data,
730
+ selectedRows = _this$props2.selectedRows;
731
+ this.hasGroups = columns.some(function (column) {
732
+ return 'columns' in column;
733
+ });
734
+ var columnIndex = 0;
735
+ var groupIndex = 0;
736
+ var gridColumnIndex = selectedRows ? 2 : 1;
737
+ var calculateGridTemplateColumn = this.calculateGridTemplateColumn.bind(this);
738
+ var calculatedColumns = [];
739
+ var treeColumns = [];
740
+ if (selectedRows) {
741
+ var column = {
742
+ name: SELECT_ALL.toString(),
743
+ // @ts-ignore
744
+ ref: function ref(node) {
745
+ if (node) {
746
+ var calculatedWidth = node.getBoundingClientRect().width;
747
+ var calculatedHeight = node.getBoundingClientRect().height;
748
+ column.calculatedWidth = calculatedWidth;
749
+ column.calculatedHeight = calculatedHeight;
750
+ }
751
+ this.ref.current = node;
752
+ },
753
+ gridColumnWidth: '40px',
754
+ calculatedWidth: 0,
755
+ calculatedHeight: 0,
756
+ alignItems: 'flex-start'
757
+ };
758
+ calculatedColumns.push(column);
759
+ }
760
+ var makeColumn = function makeColumn(columnElement, parent, isFirst, isLast) {
761
+ var _columnElement$fixed, _ref4, _columnElement$border;
762
+ var leftBordersFromParent = isFirst && ((parent === null || parent === void 0 ? void 0 : parent.borders) === 'both' || (parent === null || parent === void 0 ? void 0 : parent.borders) === 'left') ? 'left' : undefined;
763
+ var rightBordersFromParent = isLast && ((parent === null || parent === void 0 ? void 0 : parent.borders) === 'both' || (parent === null || parent === void 0 ? void 0 : parent.borders) === 'right') ? 'right' : undefined;
764
+ var column = _objectSpread(_objectSpread({}, columnElement), {}, {
765
+ name: childIsColumn(columnElement) ? columnElement.name : '',
766
+ // @ts-ignore
767
+ ref: function ref(node) {
768
+ var _columnElement$ref;
769
+ if (node) {
770
+ var calculatedWidth = node.getBoundingClientRect().width;
771
+ var calculatedHeight = node.getBoundingClientRect().height;
772
+ column.calculatedWidth = calculatedWidth;
773
+ column.calculatedHeight = calculatedHeight;
774
+ }
775
+ if (childIsColumn(columnElement) && (_columnElement$ref = columnElement.ref) !== null && _columnElement$ref !== void 0 && _columnElement$ref.hasOwnProperty('current')) {
776
+ // @ts-ignore
777
+ columnElement.ref.current = node;
778
+ }
779
+ if (this !== null && this !== void 0 && this.ref) {
780
+ this.ref.current = node;
781
+ }
782
+ },
783
+ gridColumnWidth: childIsColumn(columnElement) ? calculateGridTemplateColumn(columnElement) : '',
784
+ fixed: (_columnElement$fixed = columnElement.fixed) !== null && _columnElement$fixed !== void 0 ? _columnElement$fixed : parent === null || parent === void 0 ? void 0 : parent.fixed,
785
+ calculatedWidth: 0,
786
+ calculatedHeight: 0,
787
+ borders: (_ref4 = (_columnElement$border = columnElement.borders) !== null && _columnElement$border !== void 0 ? _columnElement$border : leftBordersFromParent) !== null && _ref4 !== void 0 ? _ref4 : rightBordersFromParent,
788
+ parent: parent
789
+ });
790
+ return column;
791
+ };
792
+ var childIsColumn = function childIsColumn(child) {
793
+ return !('columns' in child);
794
+ };
795
+ var childIsGroup = function childIsGroup(child) {
796
+ return 'columns' in child;
797
+ };
798
+ columns.forEach(function (child, i) {
799
+ if (childIsColumn(child)) {
800
+ var col = makeColumn(child);
801
+ col.gridArea = "1 / ".concat(gridColumnIndex, " / ").concat(_this4.hasGroups ? '3' : '2', " / ").concat(gridColumnIndex + 1);
802
+ columnIndex++;
803
+ gridColumnIndex++;
804
+ calculatedColumns.push(col);
805
+ treeColumns.push(col);
806
+ } else if (childIsGroup(child)) {
807
+ var Group = makeColumn(child);
808
+ var childCount = child.columns.length;
809
+ var initGridColumn = gridColumnIndex;
810
+ Group.columns = [];
811
+ Group.children = child.children;
812
+ child.columns.forEach(function (child, j) {
813
+ var _Group$columns;
814
+ var isFirst = j === 0;
815
+ var isLast = j === childCount - 1;
816
+ var col = makeColumn(child, Group, isFirst, isLast);
817
+ if (i === 0 && j === 0 && data.some(function (d) {
818
+ return d[ACCORDION];
819
+ })) {
820
+ gridColumnIndex++;
821
+ col.gridArea = "2 / ".concat(gridColumnIndex - 1, " / 3 / ").concat(gridColumnIndex + 1);
822
+ } else {
823
+ col.gridArea = "2 / ".concat(gridColumnIndex, " / 3 / ").concat(gridColumnIndex + 1);
824
+ }
825
+ col.gridArea = "2 / ".concat(gridColumnIndex, " / 3 / ").concat(gridColumnIndex + 1);
826
+ columnIndex++;
827
+ gridColumnIndex++;
828
+ calculatedColumns.push(col);
829
+ (_Group$columns = Group.columns) === null || _Group$columns === void 0 ? void 0 : _Group$columns.push(col);
830
+ });
831
+ treeColumns.push(Group);
832
+ _this4.gridAreaGroupMap.set(groupIndex, "1 / ".concat(initGridColumn, " / 2 / ").concat(gridColumnIndex));
833
+ groupIndex++;
834
+ }
835
+ });
836
+ return [calculatedColumns, treeColumns];
837
+ }
838
+ }, {
839
+ key: "calculateRows",
840
+ value: function calculateRows() {
841
+ var _this5 = this;
842
+ var columns = this.columns;
843
+ // @ts-ignore
844
+ var _this$props3 = this.props,
845
+ data = _this$props3.data,
846
+ uid = _this$props3.uid;
847
+ var rows = [];
848
+ var columnNames = columns.map(function (column) {
849
+ return column.name;
850
+ });
851
+ var rowIndex = 0;
852
+ var id = 100000000; // need this for gen keys by toString(36)
853
+
854
+ var makeDtRow = function makeDtRow(row, excludeColumns) {
855
+ var _Object$entries$reduc;
856
+ var columns = new Set(columnNames);
857
+ var dtRow = Object.entries(row).reduce(function (acc, _ref5) {
858
+ var _ref6 = _slicedToArray(_ref5, 2),
859
+ key = _ref6[0],
860
+ value = _ref6[1];
861
+ var columnsToRow = key.split(_this5.columnsSplitter);
862
+ if (columnsToRow.length === 1) {
863
+ acc[key] = value !== null && value !== void 0 ? value : '';
864
+ columns["delete"](key);
865
+ } else {
866
+ acc[columnsToRow[0]] = new MergedColumnsCell(value, {
867
+ dataKey: key,
868
+ size: columnsToRow.length
869
+ });
870
+ columnsToRow.forEach(function (value) {
871
+ columns["delete"](value);
872
+ });
873
+ }
874
+ if (row[ACCORDION]) {
875
+ acc[ACCORDION] = row[ACCORDION];
876
+ }
877
+ return acc;
878
+ }, (_Object$entries$reduc = {}, _defineProperty(_Object$entries$reduc, UNIQ_ROW_KEY, row[UNIQ_ROW_KEY] || "".concat(uid, "_").concat((rowIndex + id).toString(36))), _defineProperty(_Object$entries$reduc, ROW_INDEX, rowIndex), _Object$entries$reduc));
879
+ excludeColumns === null || excludeColumns === void 0 ? void 0 : excludeColumns.forEach(function (value) {
880
+ columns["delete"](value);
881
+ });
882
+ if (columns.size > 0) {
883
+ columns.forEach(function (value) {
884
+ dtRow[value] = '';
885
+ });
886
+ }
887
+ return dtRow;
888
+ };
889
+ data.forEach(function (row) {
890
+ var groupedRows = row[ROW_GROUP];
891
+ if (groupedRows) {
892
+ var _Object$entries$reduc2;
893
+ var innerRows = [];
894
+ var groupedKeys = [];
895
+ var groupedRowData = Object.entries(row).reduce(function (acc, _ref7) {
896
+ var _ref8 = _slicedToArray(_ref7, 2),
897
+ key = _ref8[0],
898
+ value = _ref8[1];
899
+ acc[key] = new MergedRowsCell(value, groupedRows.length);
900
+ groupedKeys.push(key);
901
+ return acc;
902
+ }, (_Object$entries$reduc2 = {}, _defineProperty(_Object$entries$reduc2, UNIQ_ROW_KEY, ''), _defineProperty(_Object$entries$reduc2, ROW_INDEX, -1), _Object$entries$reduc2));
903
+ groupedRows.forEach(function (childRow, index) {
904
+ var dtRow;
905
+ if (index === 0) {
906
+ var rowData = _objectSpread(_objectSpread({}, childRow), groupedRowData);
907
+ dtRow = makeDtRow(rowData);
908
+ } else {
909
+ dtRow = makeDtRow(childRow, groupedKeys);
910
+ }
911
+ innerRows.push(dtRow);
912
+ rowIndex++;
913
+ });
914
+ rows.push(innerRows);
915
+ } else {
916
+ var dtRow = makeDtRow(row);
917
+ rows.push(dtRow);
918
+ rowIndex++;
919
+ }
920
+ });
921
+ return rows;
922
+ }
923
+ }, {
924
+ key: "calculateGridTemplateColumn",
925
+ value: function calculateGridTemplateColumn(c) {
926
+ var _ref9;
927
+ return (_ref9 = /*#__PURE__*/React.isValidElement(c) ? c.props.gtcWidth : c.gtcWidth) !== null && _ref9 !== void 0 ? _ref9 : this.props.defaultGridTemplateColumnWidth;
928
+ }
929
+ }, {
930
+ key: "getHeaderHeight",
931
+ value: function getHeaderHeight() {
932
+ var _this$headerRef$curre;
933
+ var header = (_this$headerRef$curre = this.headerRef.current) === null || _this$headerRef$curre === void 0 ? void 0 : _this$headerRef$curre.children;
934
+ var height = 0;
935
+ for (var i = 0; i < ((_header$length = header === null || header === void 0 ? void 0 : header.length) !== null && _header$length !== void 0 ? _header$length : 0); i++) {
936
+ var _header$length, _header$item;
937
+ var columnHeight = header === null || header === void 0 ? void 0 : (_header$item = header.item(i)) === null || _header$item === void 0 ? void 0 : _header$item.getBoundingClientRect().height;
938
+ if (columnHeight) {
939
+ height = columnHeight;
940
+ break;
941
+ }
942
+ }
943
+ return height;
944
+ }
945
+ }]);
946
+ return DataTableRoot;
947
+ }(Component);
948
+ _defineProperty(DataTableRoot, "displayName", 'DataTable');
949
+ _defineProperty(DataTableRoot, "style", style);
950
+ _defineProperty(DataTableRoot, "enhance", [uniqueIDEnhancement(), i18nEnhance(localizedMessages)]);
951
+ _defineProperty(DataTableRoot, "defaultProps", {
952
+ use: 'primary',
953
+ defaultGridTemplateColumnWidth: 'auto',
954
+ defaultExpandedRows: new Set(),
955
+ defaultSelectedRows: undefined,
956
+ h: 'fit-content',
957
+ renderEmptyData: function renderEmptyData() {
958
+ return /*#__PURE__*/React.createElement(NoData, {
959
+ py: 10,
960
+ type: 'nothing-found',
961
+ description: '',
962
+ w: '100%'
963
+ });
964
+ }
965
+ });
966
+ export var DataTable = createComponent(DataTableRoot, {
967
+ Head: Head,
968
+ Body: Body
969
+ });
970
+ //# sourceMappingURL=DataTable.js.map