@semcore/data-table 16.0.0-prerelease.12 → 16.0.0-prerelease.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/Body.js +4 -3
- package/lib/cjs/Body.js.map +1 -1
- package/lib/cjs/DataTable.js.map +1 -1
- package/lib/cjs/Head.js.map +1 -1
- package/lib/cjs/components/Body/Body.js +216 -0
- package/lib/cjs/components/Body/Body.js.map +1 -0
- package/lib/cjs/components/Body/Body.types.js +2 -0
- package/lib/cjs/components/Body/Body.types.js.map +1 -0
- package/lib/cjs/components/Body/Cell.js +133 -0
- package/lib/cjs/components/Body/Cell.js.map +1 -0
- package/lib/cjs/components/Body/Cell.types.js +2 -0
- package/lib/cjs/components/Body/Cell.types.js.map +1 -0
- package/lib/cjs/components/Body/MergedCells.js +27 -0
- package/lib/cjs/components/Body/MergedCells.js.map +1 -0
- package/lib/cjs/components/Body/Row.js +212 -0
- package/lib/cjs/components/Body/Row.js.map +1 -0
- package/lib/cjs/components/Body/Row.types.js +2 -0
- package/lib/cjs/components/Body/Row.types.js.map +1 -0
- package/lib/cjs/components/Body/style.shadow.css +190 -0
- package/lib/cjs/components/DataTable/DataTable.js +565 -0
- package/lib/cjs/components/DataTable/DataTable.js.map +1 -0
- package/lib/cjs/components/DataTable/DataTable.types.js +2 -0
- package/lib/cjs/components/DataTable/DataTable.types.js.map +1 -0
- package/lib/cjs/components/DataTable/dataTable.shadow.css +14 -0
- package/lib/cjs/components/Head/Column.js +277 -0
- package/lib/cjs/components/Head/Column.js.map +1 -0
- package/lib/cjs/components/Head/Column.types.js +2 -0
- package/lib/cjs/components/Head/Column.types.js.map +1 -0
- package/lib/cjs/components/Head/Group.js +98 -0
- package/lib/cjs/components/Head/Group.js.map +1 -0
- package/lib/cjs/components/Head/Group.type.js +2 -0
- package/lib/cjs/components/Head/Group.type.js.map +1 -0
- package/lib/cjs/components/Head/Head.js +152 -0
- package/lib/cjs/components/Head/Head.js.map +1 -0
- package/lib/cjs/components/Head/Head.types.js +2 -0
- package/lib/cjs/components/Head/Head.types.js.map +1 -0
- package/lib/cjs/components/Head/style.shadow.css +165 -0
- package/lib/cjs/index.js +22 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/style/scroll-shadows.shadow.css +4 -0
- package/lib/cjs/translations/en.json +3 -1
- package/lib/cjs/utils.js +16 -7
- package/lib/cjs/utils.js.map +1 -1
- package/lib/es6/Body.js +4 -3
- package/lib/es6/Body.js.map +1 -1
- package/lib/es6/DataTable.js.map +1 -1
- package/lib/es6/Head.js.map +1 -1
- package/lib/es6/components/Body/Body.js +209 -0
- package/lib/es6/components/Body/Body.js.map +1 -0
- package/lib/es6/components/Body/Body.types.js +2 -0
- package/lib/es6/components/Body/Body.types.js.map +1 -0
- package/lib/es6/components/Body/Cell.js +126 -0
- package/lib/es6/components/Body/Cell.js.map +1 -0
- package/lib/es6/components/Body/Cell.types.js +2 -0
- package/lib/es6/components/Body/Cell.types.js.map +1 -0
- package/lib/es6/components/Body/MergedCells.js +18 -0
- package/lib/es6/components/Body/MergedCells.js.map +1 -0
- package/lib/es6/components/Body/Row.js +205 -0
- package/lib/es6/components/Body/Row.js.map +1 -0
- package/lib/es6/components/Body/Row.types.js +2 -0
- package/lib/es6/components/Body/Row.types.js.map +1 -0
- package/lib/es6/components/Body/style.shadow.css +190 -0
- package/lib/es6/components/DataTable/DataTable.js +558 -0
- package/lib/es6/components/DataTable/DataTable.js.map +1 -0
- package/lib/es6/components/DataTable/DataTable.types.js +2 -0
- package/lib/es6/components/DataTable/DataTable.types.js.map +1 -0
- package/lib/es6/components/DataTable/dataTable.shadow.css +14 -0
- package/lib/es6/components/Head/Column.js +270 -0
- package/lib/es6/components/Head/Column.js.map +1 -0
- package/lib/es6/components/Head/Column.types.js +2 -0
- package/lib/es6/components/Head/Column.types.js.map +1 -0
- package/lib/es6/components/Head/Group.js +91 -0
- package/lib/es6/components/Head/Group.js.map +1 -0
- package/lib/es6/components/Head/Group.type.js +2 -0
- package/lib/es6/components/Head/Group.type.js.map +1 -0
- package/lib/es6/components/Head/Head.js +145 -0
- package/lib/es6/components/Head/Head.js.map +1 -0
- package/lib/es6/components/Head/Head.types.js +2 -0
- package/lib/es6/components/Head/Head.types.js.map +1 -0
- package/lib/es6/components/Head/style.shadow.css +165 -0
- package/lib/es6/index.js +2 -0
- package/lib/es6/index.js.map +1 -1
- package/lib/es6/style/scroll-shadows.shadow.css +4 -0
- package/lib/es6/translations/en.json +3 -1
- package/lib/es6/utils.js +14 -6
- package/lib/es6/utils.js.map +1 -1
- package/lib/esm/Body.mjs +23 -22
- package/lib/esm/DataTable.mjs +11 -11
- package/lib/esm/Head.mjs +15 -15
- package/lib/esm/components/Body/Body.mjs +195 -0
- package/lib/esm/components/Body/Cell.mjs +129 -0
- package/lib/esm/components/Body/MergedCells.mjs +21 -0
- package/lib/esm/components/Body/Row.mjs +193 -0
- package/lib/esm/components/DataTable/DataTable.mjs +492 -0
- package/lib/esm/components/Head/Column.mjs +262 -0
- package/lib/esm/components/Head/Group.mjs +89 -0
- package/lib/esm/components/Head/Head.mjs +134 -0
- package/lib/esm/index.mjs +3 -0
- package/lib/esm/translations/en.json.mjs +3 -1
- package/lib/esm/utils.mjs +6 -6
- package/lib/types/Body.d.ts +1 -1
- package/lib/types/DataTable.d.ts +3 -3
- package/lib/types/Head.d.ts +1 -1
- package/lib/types/components/Body/Body.d.ts +8 -0
- package/lib/types/components/Body/Body.types.d.ts +31 -0
- package/lib/types/components/Body/Cell.d.ts +3 -0
- package/lib/types/components/Body/Cell.types.d.ts +14 -0
- package/lib/types/components/Body/MergedCells.d.ts +10 -0
- package/lib/types/components/Body/Row.d.ts +3 -0
- package/lib/types/components/Body/Row.types.d.ts +24 -0
- package/lib/types/components/DataTable/DataTable.d.ts +9 -0
- package/lib/types/components/DataTable/DataTable.types.d.ts +50 -0
- package/lib/types/components/Head/Column.d.ts +26 -0
- package/lib/types/components/Head/Column.types.d.ts +80 -0
- package/lib/types/components/Head/Group.d.ts +12 -0
- package/lib/types/components/Head/Group.type.d.ts +10 -0
- package/lib/types/components/Head/Head.d.ts +8 -0
- package/lib/types/components/Head/Head.types.d.ts +26 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/translations/__intergalactic-dynamic-locales.d.ts +2 -0
- package/lib/types/utils.d.ts +8 -4
- package/package.json +7 -6
- package/vite.config.ts +0 -3
|
@@ -0,0 +1,492 @@
|
|
|
1
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
7
|
+
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
8
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
9
|
+
import { sstyled, createComponent, lastInteraction, assignProps, Component } from "@semcore/core";
|
|
10
|
+
import * as React from "react";
|
|
11
|
+
import { ScrollArea, Box } from "@semcore/base-components";
|
|
12
|
+
import { Head } from "../Head/Head.mjs";
|
|
13
|
+
import { Body } from "../Body/Body.mjs";
|
|
14
|
+
import { hasFocusableIn, isFocusInside } from "@semcore/core/lib/utils/use/useFocusLock";
|
|
15
|
+
import syncScroll from "@semcore/core/lib/utils/syncScroll";
|
|
16
|
+
import { getScrollOffsetValue } from "../../utils.mjs";
|
|
17
|
+
import findComponent from "@semcore/core/lib/utils/findComponent";
|
|
18
|
+
import { localizedMessages } from "../../translations/__intergalactic-dynamic-locales.mjs";
|
|
19
|
+
import i18nEnhance from "@semcore/core/lib/utils/enhances/i18nEnhance";
|
|
20
|
+
import uniqueIDEnhancement from "@semcore/core/lib/utils/uniqueID";
|
|
21
|
+
import { ROW_GROUP } from "../../DataTable.mjs";
|
|
22
|
+
import { MergedRowsCell, MergedColumnsCell } from "../Body/MergedCells.mjs";
|
|
23
|
+
import { forkRef } from "@semcore/core/lib/utils/ref";
|
|
24
|
+
var style = (
|
|
25
|
+
/*__reshadow_css_start__*/
|
|
26
|
+
(sstyled.insert(
|
|
27
|
+
/*__inner_css_start__*/
|
|
28
|
+
".___SDataTable_1yoby_gg_{display:grid;position:relative;align-items:start;min-width:-moz-fit-content;min-width:fit-content}.___SDataTable_1yoby_gg_.__gridTemplateColumns_1yoby_gg_{grid-template-columns:var(--gridTemplateColumns_1yoby)}.___SDataTable_1yoby_gg_.__gridTemplateAreas_1yoby_gg_{grid-template-areas:var(--gridTemplateAreas_1yoby)}",
|
|
29
|
+
"1yoby_gg_"
|
|
30
|
+
), {
|
|
31
|
+
"__SDataTable": "___SDataTable_1yoby_gg_",
|
|
32
|
+
"_gridTemplateColumns": "__gridTemplateColumns_1yoby_gg_",
|
|
33
|
+
"--gridTemplateColumns": "--gridTemplateColumns_1yoby",
|
|
34
|
+
"_gridTemplateAreas": "__gridTemplateAreas_1yoby_gg_",
|
|
35
|
+
"--gridTemplateAreas": "--gridTemplateAreas_1yoby"
|
|
36
|
+
})
|
|
37
|
+
);
|
|
38
|
+
var scrollStyles = (
|
|
39
|
+
/*__reshadow_css_start__*/
|
|
40
|
+
(sstyled.insert(
|
|
41
|
+
/*__inner_css_start__*/
|
|
42
|
+
".___SScrollArea_1765z_gg_{width:-moz-fit-content;width:fit-content}.___SShadowHorizontal_1765z_gg_:after,.___SShadowHorizontal_1765z_gg_:before,.___SShadowVertical_1765z_gg_:after,.___SShadowVertical_1765z_gg_:before{z-index:1}",
|
|
43
|
+
"1765z_gg_"
|
|
44
|
+
), {
|
|
45
|
+
"__SScrollArea": "___SScrollArea_1765z_gg_",
|
|
46
|
+
"__SShadowHorizontal": "___SShadowHorizontal_1765z_gg_",
|
|
47
|
+
"__SShadowVertical": "___SShadowVertical_1765z_gg_"
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
var ACCORDION = Symbol("accordion");
|
|
51
|
+
var DataTableRoot = /* @__PURE__ */ function(_Component) {
|
|
52
|
+
_inherits(DataTableRoot2, _Component);
|
|
53
|
+
var _super = _createSuper(DataTableRoot2);
|
|
54
|
+
function DataTableRoot2(props) {
|
|
55
|
+
var _this;
|
|
56
|
+
_classCallCheck(this, DataTableRoot2);
|
|
57
|
+
_this = _super.call(this, props);
|
|
58
|
+
_defineProperty(_assertThisInitialized(_this), "columnsSplitter", "/");
|
|
59
|
+
_defineProperty(_assertThisInitialized(_this), "columns", []);
|
|
60
|
+
_defineProperty(_assertThisInitialized(_this), "focusedCell", [-1, -1]);
|
|
61
|
+
_defineProperty(_assertThisInitialized(_this), "tableContainerRef", /* @__PURE__ */ React.createRef());
|
|
62
|
+
_defineProperty(_assertThisInitialized(_this), "tableRef", /* @__PURE__ */ React.createRef());
|
|
63
|
+
_defineProperty(_assertThisInitialized(_this), "headerRef", /* @__PURE__ */ React.createRef());
|
|
64
|
+
_defineProperty(_assertThisInitialized(_this), "scrollBodyRef", void 0);
|
|
65
|
+
_defineProperty(_assertThisInitialized(_this), "scrollHeadRef", void 0);
|
|
66
|
+
_defineProperty(_assertThisInitialized(_this), "gridAreaGroupMap", /* @__PURE__ */ new Map());
|
|
67
|
+
_defineProperty(_assertThisInitialized(_this), "getRow", function(index) {
|
|
68
|
+
var _this$tableRef$curren;
|
|
69
|
+
return (_this$tableRef$curren = _this.tableRef.current) === null || _this$tableRef$curren === void 0 ? void 0 : _this$tableRef$curren.querySelector('[aria-rowindex="'.concat(index + 1, '"]'));
|
|
70
|
+
});
|
|
71
|
+
_defineProperty(_assertThisInitialized(_this), "hasFocusableInHeader", function() {
|
|
72
|
+
var hasFocusable = _this.columns.some(function(column) {
|
|
73
|
+
var columnElement = column.ref.current;
|
|
74
|
+
return columnElement && hasFocusableIn(columnElement);
|
|
75
|
+
});
|
|
76
|
+
return hasFocusable;
|
|
77
|
+
});
|
|
78
|
+
_defineProperty(_assertThisInitialized(_this), "changeFocusCell", function(rowIndex, colIndex, direction) {
|
|
79
|
+
var _this$tableRef$curren2, _this$tableRef$curren3;
|
|
80
|
+
var hasFocusable = _this.hasFocusableInHeader();
|
|
81
|
+
var maxCol = _this.columns.length - 1;
|
|
82
|
+
var maxRow = _this.totalRows;
|
|
83
|
+
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, '"]'));
|
|
84
|
+
var headerCells = (_this$tableRef$curren3 = _this.tableRef.current) === null || _this$tableRef$curren3 === void 0 ? void 0 : _this$tableRef$curren3.querySelectorAll("[role=columnheader]");
|
|
85
|
+
var currentCell = currentRow === null || currentRow === void 0 ? void 0 : currentRow.querySelector("[role=gridcell][aria-colindex='".concat(_this.focusedCell[1] + 1, "']"));
|
|
86
|
+
var currentHeaderCell = headerCells === null || headerCells === void 0 ? void 0 : headerCells.item(_this.focusedCell[1]);
|
|
87
|
+
var changed = true;
|
|
88
|
+
var newRow = _this.focusedCell[0] + rowIndex;
|
|
89
|
+
var newCol = _this.focusedCell[1] + colIndex;
|
|
90
|
+
if ((hasFocusable && newRow < 0 || !hasFocusable && newRow < 1 || newRow > maxRow) && newRow !== _this.focusedCell[0]) {
|
|
91
|
+
changed = false;
|
|
92
|
+
}
|
|
93
|
+
if ((newCol < 0 || newCol > maxCol) && newCol !== _this.focusedCell[1]) {
|
|
94
|
+
changed = false;
|
|
95
|
+
}
|
|
96
|
+
if (!changed) return;
|
|
97
|
+
var row = _this.getRow(newRow);
|
|
98
|
+
var cell = row === null || row === void 0 ? void 0 : row.querySelector('[role=gridcell][aria-colindex="'.concat(newCol + 1, '"], [role=columnheader][aria-colindex="').concat(newCol + 1, '"]'));
|
|
99
|
+
if (cell instanceof HTMLElement && currentCell !== cell) {
|
|
100
|
+
_this.focusedCell = [newRow, newCol];
|
|
101
|
+
currentCell === null || currentCell === void 0 ? void 0 : currentCell.setAttribute("inert", "");
|
|
102
|
+
if (currentCell !== currentHeaderCell) {
|
|
103
|
+
currentCell === null || currentCell === void 0 ? void 0 : currentCell.removeAttribute("aria-describedby");
|
|
104
|
+
}
|
|
105
|
+
var headerCell = headerCells === null || headerCells === void 0 ? void 0 : headerCells.item(newCol);
|
|
106
|
+
var describedBy = headerCell === null || headerCell === void 0 ? void 0 : headerCell.getAttribute("aria-describedby");
|
|
107
|
+
cell.removeAttribute("inert");
|
|
108
|
+
if (headerCell !== cell && describedBy) {
|
|
109
|
+
cell.setAttribute("aria-describedby", describedBy);
|
|
110
|
+
}
|
|
111
|
+
cell === null || cell === void 0 ? void 0 : cell.focus();
|
|
112
|
+
if (newRow !== 0) {
|
|
113
|
+
currentHeaderCell === null || currentHeaderCell === void 0 ? void 0 : currentHeaderCell.setAttribute("inert", "");
|
|
114
|
+
var _headerCell = headerCells === null || headerCells === void 0 ? void 0 : headerCells.item(newCol);
|
|
115
|
+
_headerCell === null || _headerCell === void 0 ? void 0 : _headerCell.removeAttribute("inert");
|
|
116
|
+
}
|
|
117
|
+
} else if (cell === null && currentCell instanceof HTMLElement) {
|
|
118
|
+
var rowI = rowIndex;
|
|
119
|
+
var colI = colIndex;
|
|
120
|
+
if (direction === "left" || direction === "right") {
|
|
121
|
+
if (currentCell.dataset.groupedBy === "columns") {
|
|
122
|
+
colI = direction === "left" ? colI - 1 : colI + 1;
|
|
123
|
+
} else {
|
|
124
|
+
rowI = rowI - 1;
|
|
125
|
+
}
|
|
126
|
+
} else if (direction === "up" || direction === "down") {
|
|
127
|
+
if (currentCell.dataset.groupedBy === "rows") {
|
|
128
|
+
rowI = direction === "up" ? rowI - 1 : rowI + 1;
|
|
129
|
+
} else {
|
|
130
|
+
colI = colI - 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
_this.changeFocusCell(rowI, colI, direction);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
_defineProperty(_assertThisInitialized(_this), "handleKeyDown", function(e) {
|
|
137
|
+
switch (e.key) {
|
|
138
|
+
case "Tab": {
|
|
139
|
+
_this.setInert(true);
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
case "ArrowLeft": {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
_this.changeFocusCell(0, -1, "left");
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
case "ArrowRight": {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
_this.changeFocusCell(0, 1, "right");
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
case "ArrowUp": {
|
|
153
|
+
e.preventDefault();
|
|
154
|
+
_this.changeFocusCell(-1, 0, "up");
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case "ArrowDown": {
|
|
158
|
+
e.preventDefault();
|
|
159
|
+
_this.changeFocusCell(1, 0, "down");
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
_defineProperty(_assertThisInitialized(_this), "initFocusableCell", function() {
|
|
165
|
+
var hasFocusable = _this.hasFocusableInHeader();
|
|
166
|
+
if (hasFocusable) {
|
|
167
|
+
_this.focusedCell = [0, 0];
|
|
168
|
+
} else {
|
|
169
|
+
_this.focusedCell = [1, 0];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
_defineProperty(_assertThisInitialized(_this), "handleFocus", function(e) {
|
|
173
|
+
if ((!e.relatedTarget || !isFocusInside(e.currentTarget, e.relatedTarget)) && lastInteraction.isKeyboard()) {
|
|
174
|
+
var _row;
|
|
175
|
+
if (_this.focusedCell[0] === -1 && _this.focusedCell[1] === -1) {
|
|
176
|
+
_this.initFocusableCell();
|
|
177
|
+
}
|
|
178
|
+
_this.setInert(true);
|
|
179
|
+
var row = _this.getRow(_this.focusedCell[0]);
|
|
180
|
+
if (!row) {
|
|
181
|
+
_this.initFocusableCell();
|
|
182
|
+
row = _this.getRow(_this.focusedCell[0]);
|
|
183
|
+
}
|
|
184
|
+
var cell = (_row = row) === null || _row === void 0 ? void 0 : _row.querySelectorAll("[role=gridcell], [role=columnheader]").item(_this.focusedCell[1]);
|
|
185
|
+
cell === null || cell === void 0 ? void 0 : cell.removeAttribute("inert");
|
|
186
|
+
cell instanceof HTMLElement && cell.focus();
|
|
187
|
+
e.currentTarget.setAttribute("tabIndex", "-1");
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
_defineProperty(_assertThisInitialized(_this), "handleBlur", function(e) {
|
|
191
|
+
var relatedTarget = e.relatedTarget;
|
|
192
|
+
var tableElement = _this.tableRef.current;
|
|
193
|
+
if (tableElement && (!relatedTarget || !isFocusInside(tableElement, relatedTarget) || !lastInteraction.isKeyboard())) {
|
|
194
|
+
_this.setInert(false);
|
|
195
|
+
tableElement.setAttribute("tabIndex", "0");
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
_defineProperty(_assertThisInitialized(_this), "handleMouseMove", function() {
|
|
199
|
+
_this.setInert(false);
|
|
200
|
+
});
|
|
201
|
+
var createRef = syncScroll();
|
|
202
|
+
_this.scrollBodyRef = createRef("body");
|
|
203
|
+
_this.scrollHeadRef = createRef("head");
|
|
204
|
+
_this.columns = _this.calculateColumns();
|
|
205
|
+
return _this;
|
|
206
|
+
}
|
|
207
|
+
_createClass(DataTableRoot2, [{
|
|
208
|
+
key: "componentDidMount",
|
|
209
|
+
value: function componentDidMount() {
|
|
210
|
+
this.forceUpdate();
|
|
211
|
+
}
|
|
212
|
+
}, {
|
|
213
|
+
key: "totalRows",
|
|
214
|
+
get: function get() {
|
|
215
|
+
var totalRows = this.asProps.totalRows;
|
|
216
|
+
return totalRows !== null && totalRows !== void 0 ? totalRows : this.calculateRows().length;
|
|
217
|
+
}
|
|
218
|
+
}, {
|
|
219
|
+
key: "gridSettings",
|
|
220
|
+
get: function get() {
|
|
221
|
+
var gridTemplateColumns = this.columns.map(function(c) {
|
|
222
|
+
return c.gridColumnWidth;
|
|
223
|
+
});
|
|
224
|
+
var gridTemplateAreas = this.columns.map(function(c) {
|
|
225
|
+
return c.name;
|
|
226
|
+
});
|
|
227
|
+
return {
|
|
228
|
+
gridTemplateColumns,
|
|
229
|
+
gridTemplateAreas
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}, {
|
|
233
|
+
key: "getHeadProps",
|
|
234
|
+
value: function getHeadProps() {
|
|
235
|
+
var _this$asProps = this.asProps, use = _this$asProps.use, compact = _this$asProps.compact, sort = _this$asProps.sort, onSortChange = _this$asProps.onSortChange, getI18nText = _this$asProps.getI18nText, uid = _this$asProps.uid;
|
|
236
|
+
var _this$gridSettings = this.gridSettings, gridTemplateColumns = _this$gridSettings.gridTemplateColumns, gridTemplateAreas = _this$gridSettings.gridTemplateAreas;
|
|
237
|
+
return {
|
|
238
|
+
columns: this.columns,
|
|
239
|
+
use,
|
|
240
|
+
tableRef: this.tableRef,
|
|
241
|
+
compact: Boolean(compact),
|
|
242
|
+
sort,
|
|
243
|
+
onSortChange,
|
|
244
|
+
getI18nText,
|
|
245
|
+
uid,
|
|
246
|
+
ref: this.headerRef,
|
|
247
|
+
gridAreaGroupMap: this.gridAreaGroupMap,
|
|
248
|
+
gridTemplateColumns,
|
|
249
|
+
gridTemplateAreas
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}, {
|
|
253
|
+
key: "getBodyProps",
|
|
254
|
+
value: function getBodyProps() {
|
|
255
|
+
var _header$children;
|
|
256
|
+
var _this$asProps2 = this.asProps, use = _this$asProps2.use, compact = _this$asProps2.compact, loading = _this$asProps2.loading, getI18nText = _this$asProps2.getI18nText;
|
|
257
|
+
var rows = this.calculateRows();
|
|
258
|
+
var _this$gridSettings2 = this.gridSettings, gridTemplateColumns = _this$gridSettings2.gridTemplateColumns, gridTemplateAreas = _this$gridSettings2.gridTemplateAreas;
|
|
259
|
+
var header = this.headerRef.current;
|
|
260
|
+
var headerHeight = Array.from((_header$children = header === null || header === void 0 ? void 0 : header.children) !== null && _header$children !== void 0 ? _header$children : []).reduce(function(maxHeight, col) {
|
|
261
|
+
var rect = col.getBoundingClientRect();
|
|
262
|
+
if (rect.height > maxHeight) {
|
|
263
|
+
maxHeight = rect.height;
|
|
264
|
+
}
|
|
265
|
+
return maxHeight;
|
|
266
|
+
}, 0);
|
|
267
|
+
return {
|
|
268
|
+
columns: this.columns,
|
|
269
|
+
rows,
|
|
270
|
+
use,
|
|
271
|
+
scrollRef: this.scrollBodyRef,
|
|
272
|
+
headerRows: this.columns.some(function(column) {
|
|
273
|
+
return Boolean(column.parent);
|
|
274
|
+
}) ? 2 : 1,
|
|
275
|
+
compact: Boolean(compact),
|
|
276
|
+
gridTemplateColumns,
|
|
277
|
+
gridTemplateAreas,
|
|
278
|
+
loading,
|
|
279
|
+
headerHeight,
|
|
280
|
+
getI18nText
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
}, {
|
|
284
|
+
key: "setInert",
|
|
285
|
+
value: function setInert(value) {
|
|
286
|
+
var _this$tableRef$curren4;
|
|
287
|
+
var cells = (_this$tableRef$curren4 = this.tableRef.current) === null || _this$tableRef$curren4 === void 0 ? void 0 : _this$tableRef$curren4.querySelectorAll("[role=gridcell], [role=columnheader]");
|
|
288
|
+
cells === null || cells === void 0 ? void 0 : cells.forEach(function(cell) {
|
|
289
|
+
if (value === true) {
|
|
290
|
+
cell.setAttribute("inert", "");
|
|
291
|
+
} else {
|
|
292
|
+
cell.removeAttribute("inert");
|
|
293
|
+
}
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
}, {
|
|
297
|
+
key: "render",
|
|
298
|
+
value: function render() {
|
|
299
|
+
var _ref = this.asProps, _ref2;
|
|
300
|
+
var SDataTable = Box;
|
|
301
|
+
var _this$asProps3 = this.asProps, Children = _this$asProps3.Children, styles = _this$asProps3.styles, w = _this$asProps3.w, wMax = _this$asProps3.wMax, wMin = _this$asProps3.wMin, h = _this$asProps3.h, hMax = _this$asProps3.hMax, hMin = _this$asProps3.hMin;
|
|
302
|
+
_this$asProps3.loading;
|
|
303
|
+
var _getScrollOffsetValue = getScrollOffsetValue(this.columns), _getScrollOffsetValue2 = _slicedToArray(_getScrollOffsetValue, 2), offsetLeftSum = _getScrollOffsetValue2[0], offsetRightSum = _getScrollOffsetValue2[1];
|
|
304
|
+
var _this$gridSettings3 = this.gridSettings, gridTemplateColumns = _this$gridSettings3.gridTemplateColumns, gridTemplateAreas = _this$gridSettings3.gridTemplateAreas;
|
|
305
|
+
var Head2 = findComponent(Children, ["DataTable.Head"]);
|
|
306
|
+
var Body2 = findComponent(Children, ["DataTable.Body"]);
|
|
307
|
+
var width = w !== null && w !== void 0 ? w : this.columns.some(function(c) {
|
|
308
|
+
return c.gridColumnWidth === "auto" || c.gridColumnWidth === "1fr";
|
|
309
|
+
}) ? "100%" : void 0;
|
|
310
|
+
return _ref2 = sstyled(styles), /* @__PURE__ */ React.createElement(ScrollArea, _ref2.cn("ScrollArea", {
|
|
311
|
+
"leftOffset": offsetLeftSum,
|
|
312
|
+
"rightOffset": offsetRightSum,
|
|
313
|
+
"w": width,
|
|
314
|
+
"wMax": wMax,
|
|
315
|
+
"wMin": wMin,
|
|
316
|
+
"h": h,
|
|
317
|
+
"hMax": hMax,
|
|
318
|
+
"hMin": hMin,
|
|
319
|
+
"shadow": true,
|
|
320
|
+
"container": this.tableContainerRef,
|
|
321
|
+
"styles": scrollStyles
|
|
322
|
+
}), /* @__PURE__ */ React.createElement(ScrollArea.Container, {
|
|
323
|
+
tabIndex: -1
|
|
324
|
+
}, /* @__PURE__ */ React.createElement(SDataTable, _ref2.cn("SDataTable", _objectSpread({}, assignProps({
|
|
325
|
+
"ref": forkRef(this.tableRef, this.tableContainerRef),
|
|
326
|
+
"role": "grid",
|
|
327
|
+
"onKeyDown": this.handleKeyDown,
|
|
328
|
+
"onMouseMove": this.handleMouseMove,
|
|
329
|
+
"tabIndex": 0,
|
|
330
|
+
"onFocus": this.handleFocus,
|
|
331
|
+
"onBlur": this.handleBlur,
|
|
332
|
+
"aria-rowcount": this.totalRows,
|
|
333
|
+
"aria-colcount": this.columns.length,
|
|
334
|
+
"gridTemplateColumns": gridTemplateColumns.join(" "),
|
|
335
|
+
"gridTemplateAreas": gridTemplateAreas.join(" "),
|
|
336
|
+
"w": "100%",
|
|
337
|
+
"use:data": void 0,
|
|
338
|
+
"use:w": void 0,
|
|
339
|
+
"use:wMax": void 0,
|
|
340
|
+
"use:wMin": void 0,
|
|
341
|
+
"use:h": void 0,
|
|
342
|
+
"use:hMax": void 0,
|
|
343
|
+
"use:hMin": void 0
|
|
344
|
+
}, _ref))), Body2, Head2)), /* @__PURE__ */ React.createElement(ScrollArea.Bar, {
|
|
345
|
+
orientation: "horizontal"
|
|
346
|
+
}), /* @__PURE__ */ React.createElement(ScrollArea.Bar, {
|
|
347
|
+
orientation: "vertical"
|
|
348
|
+
}));
|
|
349
|
+
}
|
|
350
|
+
}, {
|
|
351
|
+
key: "calculateColumns",
|
|
352
|
+
value: function calculateColumns() {
|
|
353
|
+
var _this2 = this;
|
|
354
|
+
var _this$props = this.props, children = _this$props.children, data = _this$props.data;
|
|
355
|
+
var HeadComponent = findComponent(children, ["Head"]);
|
|
356
|
+
var hasGroup = findComponent(HeadComponent.props.children, ["Head.Group"]) !== void 0;
|
|
357
|
+
var groupIndex = 0;
|
|
358
|
+
var gridColumnIndex = 1;
|
|
359
|
+
var calculateGridTemplateColumn = this.calculateGridTemplateColumn.bind(this);
|
|
360
|
+
var columns = [];
|
|
361
|
+
var makeColumn = function makeColumn2(columnElement, parent, isFirst, isLast) {
|
|
362
|
+
var _columnElement$props$, _ref3, _columnElement$props$2;
|
|
363
|
+
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" : void 0;
|
|
364
|
+
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" : void 0;
|
|
365
|
+
var column = {
|
|
366
|
+
name: columnElement.props.name,
|
|
367
|
+
// @ts-ignore
|
|
368
|
+
ref: function ref(node) {
|
|
369
|
+
if (node) {
|
|
370
|
+
var calculatedWidth = node.getBoundingClientRect().width;
|
|
371
|
+
var calculatedHeight = node.getBoundingClientRect().height;
|
|
372
|
+
column.calculatedWidth = calculatedWidth;
|
|
373
|
+
column.calculatedHeight = calculatedHeight;
|
|
374
|
+
}
|
|
375
|
+
this.ref.current = node;
|
|
376
|
+
},
|
|
377
|
+
gridColumnWidth: calculateGridTemplateColumn(columnElement),
|
|
378
|
+
fixed: (_columnElement$props$ = columnElement.props.fixed) !== null && _columnElement$props$ !== void 0 ? _columnElement$props$ : parent === null || parent === void 0 ? void 0 : parent.props.fixed,
|
|
379
|
+
calculatedWidth: 0,
|
|
380
|
+
calculatedHeight: 0,
|
|
381
|
+
borders: (_ref3 = (_columnElement$props$2 = columnElement.props.borders) !== null && _columnElement$props$2 !== void 0 ? _columnElement$props$2 : leftBordersFromParent) !== null && _ref3 !== void 0 ? _ref3 : rightBordersFromParent,
|
|
382
|
+
parent,
|
|
383
|
+
flexWrap: columnElement.props.flexWrap,
|
|
384
|
+
alignItems: columnElement.props.alignItems,
|
|
385
|
+
alignContent: columnElement.props.alignContent,
|
|
386
|
+
justifyContent: columnElement.props.justifyContent
|
|
387
|
+
};
|
|
388
|
+
return column;
|
|
389
|
+
};
|
|
390
|
+
React.Children.forEach(HeadComponent.props.children, function(child, i) {
|
|
391
|
+
if (!/* @__PURE__ */ React.isValidElement(child)) return;
|
|
392
|
+
if (child.type === Head.Column) {
|
|
393
|
+
var col = makeColumn(child);
|
|
394
|
+
col.gridArea = "1 / ".concat(gridColumnIndex, " / ").concat(hasGroup ? "3" : "2", " / ").concat(gridColumnIndex + 1);
|
|
395
|
+
gridColumnIndex++;
|
|
396
|
+
columns.push(col);
|
|
397
|
+
} else if (child.type === Head.Group) {
|
|
398
|
+
var Group = child;
|
|
399
|
+
var childCount = React.Children.count(child.props.children);
|
|
400
|
+
var initGridColumn = gridColumnIndex;
|
|
401
|
+
React.Children.forEach(child.props.children, function(child2, j) {
|
|
402
|
+
if ((child2 === null || child2 === void 0 ? void 0 : child2.type) === Head.Column) {
|
|
403
|
+
var isFirst = j === 0;
|
|
404
|
+
var isLast = j === childCount - 1;
|
|
405
|
+
var _col = makeColumn(child2, Group, isFirst, isLast);
|
|
406
|
+
if (i === 0 && j === 0 && data.some(function(d) {
|
|
407
|
+
return d[ACCORDION];
|
|
408
|
+
})) {
|
|
409
|
+
gridColumnIndex++;
|
|
410
|
+
_col.gridArea = "2 / ".concat(gridColumnIndex - 1, " / 3 / ").concat(gridColumnIndex + 1);
|
|
411
|
+
} else {
|
|
412
|
+
_col.gridArea = "2 / ".concat(gridColumnIndex, " / 3 / ").concat(gridColumnIndex + 1);
|
|
413
|
+
}
|
|
414
|
+
_col.gridArea = "2 / ".concat(gridColumnIndex, " / 3 / ").concat(gridColumnIndex + 1);
|
|
415
|
+
gridColumnIndex++;
|
|
416
|
+
columns.push(_col);
|
|
417
|
+
}
|
|
418
|
+
});
|
|
419
|
+
_this2.gridAreaGroupMap.set(groupIndex, "1 / ".concat(initGridColumn, " / 2 / ").concat(gridColumnIndex));
|
|
420
|
+
groupIndex++;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
return columns.filter(Boolean);
|
|
424
|
+
}
|
|
425
|
+
}, {
|
|
426
|
+
key: "calculateRows",
|
|
427
|
+
value: function calculateRows() {
|
|
428
|
+
var _this3 = this;
|
|
429
|
+
var data = this.asProps.data;
|
|
430
|
+
var rows = [];
|
|
431
|
+
var addToRows = function addToRows2(row) {
|
|
432
|
+
var dtRow = Object.entries(row).reduce(function(acc, _ref4) {
|
|
433
|
+
var _ref5 = _slicedToArray(_ref4, 2), key = _ref5[0], value = _ref5[1];
|
|
434
|
+
var columnsToRow = key.split(_this3.columnsSplitter);
|
|
435
|
+
if (columnsToRow.length === 1) {
|
|
436
|
+
acc[key] = value;
|
|
437
|
+
} else {
|
|
438
|
+
acc[columnsToRow[0]] = new MergedColumnsCell(value, columnsToRow.length);
|
|
439
|
+
}
|
|
440
|
+
if (row[ACCORDION]) {
|
|
441
|
+
acc[ACCORDION] = row[ACCORDION];
|
|
442
|
+
}
|
|
443
|
+
return acc;
|
|
444
|
+
}, {});
|
|
445
|
+
rows.push(dtRow);
|
|
446
|
+
};
|
|
447
|
+
data.forEach(function(row, rowIndex2) {
|
|
448
|
+
var groupedRows = row[ROW_GROUP];
|
|
449
|
+
if (groupedRows) {
|
|
450
|
+
groupedRows.forEach(function(childRow, index) {
|
|
451
|
+
if (index === 0) {
|
|
452
|
+
var rowData = _objectSpread(_objectSpread({}, childRow), Object.entries(row).reduce(function(acc, _ref6) {
|
|
453
|
+
var _ref7 = _slicedToArray(_ref6, 2), key = _ref7[0], value = _ref7[1];
|
|
454
|
+
acc[key] = new MergedRowsCell(value, groupedRows.length);
|
|
455
|
+
return acc;
|
|
456
|
+
}, {}));
|
|
457
|
+
addToRows(rowData);
|
|
458
|
+
} else {
|
|
459
|
+
addToRows(childRow);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
} else {
|
|
463
|
+
addToRows(row);
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
return rows;
|
|
467
|
+
}
|
|
468
|
+
}, {
|
|
469
|
+
key: "calculateGridTemplateColumn",
|
|
470
|
+
value: function calculateGridTemplateColumn(c) {
|
|
471
|
+
var _c$props$gtcWidth;
|
|
472
|
+
return (_c$props$gtcWidth = c.props.gtcWidth) !== null && _c$props$gtcWidth !== void 0 ? _c$props$gtcWidth : this.props.defaultGridTemplateColumnWidth;
|
|
473
|
+
}
|
|
474
|
+
}]);
|
|
475
|
+
return DataTableRoot2;
|
|
476
|
+
}(Component);
|
|
477
|
+
_defineProperty(DataTableRoot, "displayName", "DataTable");
|
|
478
|
+
_defineProperty(DataTableRoot, "style", style);
|
|
479
|
+
_defineProperty(DataTableRoot, "enhance", [uniqueIDEnhancement(), i18nEnhance(localizedMessages)]);
|
|
480
|
+
_defineProperty(DataTableRoot, "defaultProps", {
|
|
481
|
+
use: "primary",
|
|
482
|
+
defaultGridTemplateColumnWidth: "auto",
|
|
483
|
+
h: "auto"
|
|
484
|
+
});
|
|
485
|
+
var DataTable = createComponent(DataTableRoot, {
|
|
486
|
+
Head,
|
|
487
|
+
Body
|
|
488
|
+
});
|
|
489
|
+
export {
|
|
490
|
+
ACCORDION,
|
|
491
|
+
DataTable
|
|
492
|
+
};
|