@react-fabric/data 1.0.0-beta.4 → 1.0.0-beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/checklist/CheckList.js +25 -16
- package/dist/cjs/histogram/Histogram.js +12 -4
- package/dist/cjs/table/BodyCell.js +35 -3
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/HeaderCell.js +4 -3
- package/dist/cjs/table/Table.js +71 -69
- package/dist/cjs/table/useVirtualTable.js +15 -1
- package/dist/cjs/virtual/Gallery.js +11 -4
- package/dist/cjs/virtual/List.js +11 -4
- package/dist/esm/checklist/CheckList.js +27 -18
- package/dist/esm/histogram/Histogram.js +12 -4
- package/dist/esm/table/BodyCell.js +35 -3
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/HeaderCell.js +4 -3
- package/dist/esm/table/Table.js +72 -70
- package/dist/esm/table/useVirtualTable.js +15 -1
- package/dist/esm/virtual/Gallery.js +11 -4
- package/dist/esm/virtual/List.js +11 -4
- package/dist/types/checklist/CheckList.d.ts +2 -2
- package/dist/types/histogram/Histogram.d.ts +3 -3
- package/dist/types/index.d.ts +1 -1
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/EmptyCell.d.ts +2 -2
- package/dist/types/table/HeaderCell.d.ts +2 -2
- package/dist/types/table/Table.d.ts +1 -1
- package/dist/types/table/types.d.ts +11 -4
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +4 -0
- package/dist/types/virtual/Gallery.d.ts +3 -2
- package/dist/types/virtual/List.d.ts +3 -2
- package/package.json +6 -5
- package/src/checklist/CheckList.tsx +81 -77
- package/src/histogram/Histogram.tsx +5 -1
- package/src/index.ts +1 -1
- package/src/table/AddColumn.tsx +2 -2
- package/src/table/BodyCell.tsx +30 -3
- package/src/table/BodyRow.tsx +142 -0
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +4 -3
- package/src/table/Table.tsx +90 -73
- package/src/table/types.ts +13 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +16 -2
- package/src/virtual/Gallery.tsx +4 -1
- package/src/virtual/List.tsx +4 -1
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
4
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
-
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
6
5
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
7
7
|
var core = require('@react-fabric/core');
|
|
8
8
|
var utilities = require('@react-fabric/utilities');
|
|
9
9
|
var react = require('react');
|
|
@@ -11,10 +11,11 @@ var reactI18next = require('react-i18next');
|
|
|
11
11
|
var useSelectableList = require('../hooks/useSelectableList.js');
|
|
12
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
13
13
|
|
|
14
|
-
var _excluded = ["
|
|
14
|
+
var _excluded = ["id", "allowNegative", "selected", "icon", "label", "isDisabled", "onClick", "badge"],
|
|
15
|
+
_excluded2 = ["items", "maxCount", "allowNegative", "emptyMessage", "sortItems", "selected", "nonselected", "onChange", "onClick"];
|
|
15
16
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
17
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
17
|
-
var CheckItem =
|
|
18
|
+
var CheckItem = function CheckItem(_ref) {
|
|
18
19
|
var id = _ref.id,
|
|
19
20
|
allowNegative = _ref.allowNegative,
|
|
20
21
|
selected = _ref.selected,
|
|
@@ -22,8 +23,9 @@ var CheckItem = /*#__PURE__*/react.memo(function (_ref) {
|
|
|
22
23
|
label = _ref.label,
|
|
23
24
|
isDisabled = _ref.isDisabled,
|
|
24
25
|
_onClick = _ref.onClick,
|
|
25
|
-
badge = _ref.badge
|
|
26
|
-
|
|
26
|
+
badge = _ref.badge,
|
|
27
|
+
aria = _objectWithoutProperties(_ref, _excluded);
|
|
28
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
|
|
27
29
|
role: "none",
|
|
28
30
|
className: "ax-checkList__item",
|
|
29
31
|
"data-disabled": isDisabled,
|
|
@@ -32,7 +34,8 @@ var CheckItem = /*#__PURE__*/react.memo(function (_ref) {
|
|
|
32
34
|
},
|
|
33
35
|
onContextMenu: function onContextMenu(e) {
|
|
34
36
|
return [allowNegative && _onClick(id, true), e.preventDefault()];
|
|
35
|
-
}
|
|
37
|
+
}
|
|
38
|
+
}, aria), {}, {
|
|
36
39
|
children: [!allowNegative && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
37
40
|
"data-type": "checkbox",
|
|
38
41
|
className: "ax-checkList__checkbox",
|
|
@@ -67,9 +70,8 @@ var CheckItem = /*#__PURE__*/react.memo(function (_ref) {
|
|
|
67
70
|
}), /*#__PURE__*/jsxRuntime.jsx("label", {
|
|
68
71
|
children: label
|
|
69
72
|
}), /*#__PURE__*/jsxRuntime.jsx(core.Badge, _objectSpread({}, badge))]
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
CheckItem.displayName = "CheckItem";
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
73
75
|
var CheckList = function CheckList(_ref2) {
|
|
74
76
|
var _ref2$items = _ref2.items,
|
|
75
77
|
items = _ref2$items === void 0 ? [] : _ref2$items,
|
|
@@ -79,12 +81,20 @@ var CheckList = function CheckList(_ref2) {
|
|
|
79
81
|
emptyMessage = _ref2.emptyMessage,
|
|
80
82
|
_ref2$sortItems = _ref2.sortItems,
|
|
81
83
|
sortItems = _ref2$sortItems === void 0 ? true : _ref2$sortItems,
|
|
82
|
-
|
|
84
|
+
selected = _ref2.selected,
|
|
85
|
+
nonselected = _ref2.nonselected,
|
|
86
|
+
onChange = _ref2.onChange,
|
|
87
|
+
onClick = _ref2.onClick,
|
|
88
|
+
aria = _objectWithoutProperties(_ref2, _excluded2);
|
|
83
89
|
var _useTranslation = reactI18next.useTranslation("data"),
|
|
84
90
|
t = _useTranslation.t;
|
|
85
|
-
var _useSelectableList = useSelectableList.useSelectableList(
|
|
86
|
-
items: items
|
|
87
|
-
|
|
91
|
+
var _useSelectableList = useSelectableList.useSelectableList({
|
|
92
|
+
items: items,
|
|
93
|
+
selected: selected,
|
|
94
|
+
nonselected: nonselected,
|
|
95
|
+
onChange: onChange,
|
|
96
|
+
onClick: onClick
|
|
97
|
+
}),
|
|
88
98
|
selection = _useSelectableList.selection,
|
|
89
99
|
toggleSelection = _useSelectableList.toggleSelection;
|
|
90
100
|
var _useState = react.useState(false),
|
|
@@ -105,8 +115,7 @@ var CheckList = function CheckList(_ref2) {
|
|
|
105
115
|
return 0;
|
|
106
116
|
}).slice(0, !showMore && maxCount > 0 ? maxCount : undefined);
|
|
107
117
|
}, [items, selection, maxCount, showMore, sortItems]);
|
|
108
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
109
|
-
className: "ax-checkList",
|
|
118
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({}, aria), {}, {
|
|
110
119
|
children: [listItems.map(function (item, index) {
|
|
111
120
|
return /*#__PURE__*/react.createElement(CheckItem, _objectSpread(_objectSpread({}, item), {}, {
|
|
112
121
|
key: index,
|
|
@@ -128,7 +137,7 @@ var CheckList = function CheckList(_ref2) {
|
|
|
128
137
|
className: "text-sm",
|
|
129
138
|
message: emptyMessage !== null && emptyMessage !== void 0 ? emptyMessage : t("checkList.empty")
|
|
130
139
|
})]
|
|
131
|
-
});
|
|
140
|
+
}));
|
|
132
141
|
};
|
|
133
142
|
|
|
134
143
|
exports.CheckList = CheckList;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
3
4
|
var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
|
|
5
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
6
|
var core = require('@react-fabric/core');
|
|
5
7
|
var utilities = require('@react-fabric/utilities');
|
|
6
8
|
var classNames = require('classnames');
|
|
@@ -9,6 +11,9 @@ var reactI18next = require('react-i18next');
|
|
|
9
11
|
var Histogram_module = require('./Histogram.module.css');
|
|
10
12
|
var jsxRuntime = require('react/jsx-runtime');
|
|
11
13
|
|
|
14
|
+
var _excluded = ["items", "total", "color", "sortBy", "emptyTitle", "emptyMessage", "onClick"];
|
|
15
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
16
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
12
17
|
var emptyIcon = "M20.84 22.73L11.11 13H3V11H9.11L6.11 8H3V6H4.11L1.11 3L2.39 1.73L22.11 21.46L20.84 22.73M15 11H14.2L15 11.8V11M21 8V6H9.2L11.2 8H21M3 18H9V16H3V18Z";
|
|
13
18
|
var Histogram = function Histogram(_ref) {
|
|
14
19
|
var _ref$items = _ref.items,
|
|
@@ -20,7 +25,8 @@ var Histogram = function Histogram(_ref) {
|
|
|
20
25
|
sortBy = _ref$sortBy === void 0 ? "count" : _ref$sortBy,
|
|
21
26
|
emptyTitle = _ref.emptyTitle,
|
|
22
27
|
emptyMessage = _ref.emptyMessage,
|
|
23
|
-
_onClick = _ref.onClick
|
|
28
|
+
_onClick = _ref.onClick,
|
|
29
|
+
aria = _objectWithoutProperties(_ref, _excluded);
|
|
24
30
|
var _useTranslation = reactI18next.useTranslation("data"),
|
|
25
31
|
t = _useTranslation.t;
|
|
26
32
|
var maxTotal = react.useMemo(function () {
|
|
@@ -32,8 +38,9 @@ var Histogram = function Histogram(_ref) {
|
|
|
32
38
|
var sorted = react.useMemo(function () {
|
|
33
39
|
return items.sort(utilities.compareValues(sortBy === "label" ? "asc" : "desc", sortBy));
|
|
34
40
|
}, [items, sortBy]);
|
|
35
|
-
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
36
|
-
className: Histogram_module.histogram
|
|
41
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", _objectSpread(_objectSpread({
|
|
42
|
+
className: Histogram_module.histogram
|
|
43
|
+
}, aria), {}, {
|
|
37
44
|
style: {
|
|
38
45
|
"--color": "var(--".concat(color, ")")
|
|
39
46
|
},
|
|
@@ -49,6 +56,7 @@ var Histogram = function Histogram(_ref) {
|
|
|
49
56
|
role: "none",
|
|
50
57
|
"data-disabled": item.count === 0 || item.disabled,
|
|
51
58
|
className: classNames("relative cursor-pointer flex flex-nowrap items-center select-none overflow-hidden min-h-6 my-px", Histogram_module.histoLabel, (item.count === 0 || item.disabled) && "pointer-events-none"),
|
|
59
|
+
"data-testid": item.id,
|
|
52
60
|
onClick: function onClick(e) {
|
|
53
61
|
return [_onClick === null || _onClick === void 0 ? void 0 : _onClick(item.id), e.stopPropagation()];
|
|
54
62
|
},
|
|
@@ -83,7 +91,7 @@ var Histogram = function Histogram(_ref) {
|
|
|
83
91
|
})]
|
|
84
92
|
}, item.id);
|
|
85
93
|
})]
|
|
86
|
-
});
|
|
94
|
+
}));
|
|
87
95
|
};
|
|
88
96
|
|
|
89
97
|
exports.Histogram = Histogram;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var date = require('@react-fabric/date');
|
|
4
|
+
var utilities = require('@react-fabric/utilities');
|
|
3
5
|
var classNames = require('classnames');
|
|
4
6
|
var react = require('react');
|
|
5
7
|
var Context = require('./Context.js');
|
|
@@ -30,15 +32,45 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
30
32
|
*/
|
|
31
33
|
|
|
32
34
|
var BodyCell = function BodyCell(_ref) {
|
|
33
|
-
var _column$minWidth, _column$maxWidth
|
|
35
|
+
var _column$minWidth, _column$maxWidth;
|
|
34
36
|
var column = _ref.column,
|
|
35
|
-
item = _ref.item
|
|
37
|
+
item = _ref.item,
|
|
38
|
+
index = _ref.index;
|
|
36
39
|
var _useTableContext = Context.useTableContext(),
|
|
37
40
|
widths = _useTableContext.widths;
|
|
38
41
|
var width = react.useMemo(function () {
|
|
39
42
|
var _widths$get;
|
|
40
43
|
return (_widths$get = widths.get(column.id.toString())) !== null && _widths$get !== void 0 ? _widths$get : column.width;
|
|
41
44
|
}, [widths, column]);
|
|
45
|
+
var content = react.useMemo(function () {
|
|
46
|
+
var value = utilities.getByPath(item, column.id.toString());
|
|
47
|
+
if (column.renderer != null) {
|
|
48
|
+
return column.renderer(item[column.id], item, index);
|
|
49
|
+
}
|
|
50
|
+
if (column.dataType === "boolean") {
|
|
51
|
+
var _column$valueMap;
|
|
52
|
+
var map = (_column$valueMap = column.valueMap) !== null && _column$valueMap !== void 0 ? _column$valueMap : {
|
|
53
|
+
"true": "Yes",
|
|
54
|
+
"false": "no"
|
|
55
|
+
};
|
|
56
|
+
return map["".concat(utilities.isTrue(value) ? "true" : "false")];
|
|
57
|
+
}
|
|
58
|
+
if (column.valueMap != null) {
|
|
59
|
+
if (column.dataType === "string" && value in column.valueMap) {
|
|
60
|
+
return column.valueMap[value];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (column.dataType === "date") {
|
|
64
|
+
return /*#__PURE__*/jsxRuntime.jsx(date.DateDisplay, {
|
|
65
|
+
date: value,
|
|
66
|
+
format: column.format
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
if (column.dataType === "number") {
|
|
70
|
+
return utilities.Format.number(value, column.format);
|
|
71
|
+
}
|
|
72
|
+
return value !== null && value !== void 0 ? value : "";
|
|
73
|
+
}, [item, column]);
|
|
42
74
|
return /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
43
75
|
className: "overflow-hidden bg-inherit start-0",
|
|
44
76
|
style: {
|
|
@@ -48,7 +80,7 @@ var BodyCell = function BodyCell(_ref) {
|
|
|
48
80
|
},
|
|
49
81
|
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
50
82
|
className: classNames("px-2 py-1 border-e truncate", column.align === "center" && "text-center", column.align === "end" && "text-end"),
|
|
51
|
-
children:
|
|
83
|
+
children: content
|
|
52
84
|
})
|
|
53
85
|
});
|
|
54
86
|
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var classNames = require('classnames');
|
|
4
|
+
var BodyCell = require('./BodyCell.js');
|
|
5
|
+
var CheckboxCell = require('./CheckboxCell.js');
|
|
6
|
+
var core = require('@react-fabric/core');
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* React Fabric
|
|
11
|
+
* @version: 1.0.0
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* The MIT License (MIT)
|
|
15
|
+
* Copyright (c) 2024 Adarsh Pastakia
|
|
16
|
+
*
|
|
17
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
|
|
18
|
+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
19
|
+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
20
|
+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
21
|
+
* subject to the following conditions:
|
|
22
|
+
*
|
|
23
|
+
* The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
24
|
+
* portions of the Software.
|
|
25
|
+
*
|
|
26
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
27
|
+
* TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
28
|
+
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
29
|
+
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
var BodyRow = function BodyRow(_ref) {
|
|
33
|
+
var _state$start, _state$cols, _state$end;
|
|
34
|
+
var rowKey = _ref.rowKey,
|
|
35
|
+
index = _ref.index,
|
|
36
|
+
data = _ref.data,
|
|
37
|
+
keyProperty = _ref.keyProperty,
|
|
38
|
+
measureElement = _ref.measureElement,
|
|
39
|
+
state = _ref.state,
|
|
40
|
+
hideableColumns = _ref.hideableColumns,
|
|
41
|
+
wrapperStart = _ref.wrapperStart,
|
|
42
|
+
wrapperEnd = _ref.wrapperEnd,
|
|
43
|
+
onRowClick = _ref.onRowClick,
|
|
44
|
+
checkableRows = _ref.checkableRows,
|
|
45
|
+
checked = _ref.checked,
|
|
46
|
+
toggleChecked = _ref.toggleChecked,
|
|
47
|
+
canExpand = _ref.canExpand,
|
|
48
|
+
expanded = _ref.expanded,
|
|
49
|
+
toggleExpand = _ref.toggleExpand,
|
|
50
|
+
expandRow = _ref.expandRow;
|
|
51
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
52
|
+
ref: measureElement,
|
|
53
|
+
"data-index": index,
|
|
54
|
+
className: index % 2 ? "bg-even" : "bg-odd",
|
|
55
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
56
|
+
role: "none",
|
|
57
|
+
"data-row": index,
|
|
58
|
+
className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
|
|
59
|
+
onClick: function onClick() {
|
|
60
|
+
return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
|
|
61
|
+
},
|
|
62
|
+
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
63
|
+
className: wrapperStart,
|
|
64
|
+
children: [!!canExpand && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
65
|
+
className: classNames("group font-medium w-6 flex flex-nowrap text-start items-center", !canExpand(data) && "pointer-events-none opacity-35"),
|
|
66
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
|
67
|
+
className: "p-1 text-tint-700 hover:text-primary-600",
|
|
68
|
+
icon: expanded ? core.CoreIcons.collapse : core.CoreIcons.expand,
|
|
69
|
+
onClick: function onClick(e) {
|
|
70
|
+
return [keyProperty && toggleExpand(data[keyProperty]), e.stopPropagation()];
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}), checkableRows && keyProperty && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
|
|
74
|
+
onClick: function onClick() {
|
|
75
|
+
return toggleChecked(data[keyProperty]);
|
|
76
|
+
},
|
|
77
|
+
state: checked
|
|
78
|
+
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, ids) {
|
|
79
|
+
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
80
|
+
column: col,
|
|
81
|
+
item: data,
|
|
82
|
+
index: ids
|
|
83
|
+
}, "".concat(String(rowKey), ":").concat(ids));
|
|
84
|
+
})]
|
|
85
|
+
}), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idc) {
|
|
86
|
+
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
87
|
+
column: col,
|
|
88
|
+
item: data,
|
|
89
|
+
index: idc
|
|
90
|
+
}, "".concat(String(rowKey), ":").concat(idc));
|
|
91
|
+
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
92
|
+
className: wrapperEnd,
|
|
93
|
+
children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, ide) {
|
|
94
|
+
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
95
|
+
column: col,
|
|
96
|
+
item: data,
|
|
97
|
+
index: ide
|
|
98
|
+
}, "".concat(String(rowKey), ":").concat(ide));
|
|
99
|
+
}), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
100
|
+
className: "w-6"
|
|
101
|
+
})]
|
|
102
|
+
})]
|
|
103
|
+
}), expanded && expandRow(data)]
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
exports.BodyRow = BodyRow;
|
|
@@ -38,7 +38,8 @@ var HeaderCell = function HeaderCell(_ref) {
|
|
|
38
38
|
rtlFlip = _ref.rtlFlip;
|
|
39
39
|
_ref.actions;
|
|
40
40
|
_ref.locked;
|
|
41
|
-
var
|
|
41
|
+
var tooltip = _ref.tooltip,
|
|
42
|
+
sortable = _ref.sortable,
|
|
42
43
|
resizable = _ref.resizable,
|
|
43
44
|
_width = _ref.width,
|
|
44
45
|
maxWidth = _ref.maxWidth,
|
|
@@ -82,8 +83,8 @@ var HeaderCell = function HeaderCell(_ref) {
|
|
|
82
83
|
maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : types.COL_MAX_WIDTH
|
|
83
84
|
},
|
|
84
85
|
children: [/*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
|
|
85
|
-
content: label,
|
|
86
|
-
disabled: !label,
|
|
86
|
+
content: tooltip !== null && tooltip !== void 0 ? tooltip : label,
|
|
87
|
+
disabled: !(tooltip !== null && tooltip !== void 0 ? tooltip : label),
|
|
87
88
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
88
89
|
className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
|
|
89
90
|
children: [icon && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
|
package/dist/cjs/table/Table.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
4
|
var core = require('@react-fabric/core');
|
|
5
|
-
var
|
|
5
|
+
var utilities = require('@react-fabric/utilities');
|
|
6
6
|
var react = require('react');
|
|
7
7
|
var reactI18next = require('react-i18next');
|
|
8
8
|
var AddColumn = require('./AddColumn.js');
|
|
9
|
-
var
|
|
9
|
+
var BodyRow = require('./BodyRow.js');
|
|
10
10
|
var CheckboxCell = require('./CheckboxCell.js');
|
|
11
11
|
var Context = require('./Context.js');
|
|
12
12
|
var EmptyCell = require('./EmptyCell.js');
|
|
@@ -18,16 +18,21 @@ var jsxRuntime = require('react/jsx-runtime');
|
|
|
18
18
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
19
19
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
20
20
|
var Table = function Table(_ref) {
|
|
21
|
-
var _state$start, _state$cols, _state$end, _items$, _state$
|
|
21
|
+
var _state$start, _state$cols, _state$end, _items$, _state$start2, _state$cols2, _state$end2;
|
|
22
22
|
var ref = _ref.ref,
|
|
23
23
|
data = _ref.data,
|
|
24
24
|
columns = _ref.columns,
|
|
25
25
|
keyProperty = _ref.keyProperty,
|
|
26
26
|
checkableRows = _ref.checkableRows,
|
|
27
|
+
initialScroll = _ref.initialScroll,
|
|
27
28
|
hideableColumns = _ref.hideableColumns,
|
|
28
29
|
sort = _ref.sort,
|
|
29
30
|
loading = _ref.loading,
|
|
31
|
+
emptyDisplay = _ref.emptyDisplay,
|
|
32
|
+
canExpand = _ref.canExpand,
|
|
33
|
+
children = _ref.children,
|
|
30
34
|
onSort = _ref.onSort,
|
|
35
|
+
onScroll = _ref.onScroll,
|
|
31
36
|
onRowClick = _ref.onRowClick,
|
|
32
37
|
onCheckedChanged = _ref.onCheckedChanged;
|
|
33
38
|
var _useTranslation = reactI18next.useTranslation("data"),
|
|
@@ -41,7 +46,10 @@ var Table = function Table(_ref) {
|
|
|
41
46
|
var _useVirtualTable = useVirtualTable.useVirtualTable(data, keyProperty, fireCheckChanged),
|
|
42
47
|
scrollerRef = _useVirtualTable.scrollerRef,
|
|
43
48
|
items = _useVirtualTable.items,
|
|
49
|
+
top = _useVirtualTable.top,
|
|
44
50
|
checkState = _useVirtualTable.checkState,
|
|
51
|
+
virtualizer = _useVirtualTable.virtualizer,
|
|
52
|
+
toggleExpand = _useVirtualTable.toggleExpand,
|
|
45
53
|
toggleChecked = _useVirtualTable.toggleChecked,
|
|
46
54
|
toggleAllChecked = _useVirtualTable.toggleAllChecked,
|
|
47
55
|
getData = _useVirtualTable.getData,
|
|
@@ -54,35 +62,46 @@ var Table = function Table(_ref) {
|
|
|
54
62
|
var wrapperEnd = react.useMemo(function () {
|
|
55
63
|
return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
|
|
56
64
|
}, []);
|
|
65
|
+
react.useLayoutEffect(function () {
|
|
66
|
+
setTimeout(function () {
|
|
67
|
+
initialScroll && virtualizer.scrollToIndex(initialScroll, {
|
|
68
|
+
align: "start"
|
|
69
|
+
});
|
|
70
|
+
}, 100);
|
|
71
|
+
}, []);
|
|
57
72
|
react.useImperativeHandle(ref, function () {
|
|
58
73
|
return {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return el && (el.dataset.hilight = undefined);
|
|
63
|
-
});
|
|
64
|
-
var el = (_refBody$current2 = refBody.current) === null || _refBody$current2 === void 0 ? void 0 : _refBody$current2.querySelector("[data-row=\"".concat(row, "\"]"));
|
|
65
|
-
el === null || el === void 0 || el.scrollIntoView({
|
|
66
|
-
behavior: "smooth",
|
|
67
|
-
block: "center"
|
|
74
|
+
scrollTo: function scrollTo(row) {
|
|
75
|
+
virtualizer.scrollToIndex(row, {
|
|
76
|
+
align: "start"
|
|
68
77
|
});
|
|
69
|
-
el && (el.dataset.hilight = "true");
|
|
70
78
|
},
|
|
71
|
-
|
|
72
|
-
var
|
|
73
|
-
(
|
|
74
|
-
|
|
79
|
+
hilight: function hilight(row) {
|
|
80
|
+
var _scrollerRef$current;
|
|
81
|
+
(_scrollerRef$current = scrollerRef.current) === null || _scrollerRef$current === void 0 || (_scrollerRef$current = _scrollerRef$current.querySelector(".hilight")) === null || _scrollerRef$current === void 0 || _scrollerRef$current.classList.remove("hilight", "ring-1");
|
|
82
|
+
virtualizer.scrollToIndex(Math.floor(row), {
|
|
83
|
+
align: "start"
|
|
75
84
|
});
|
|
85
|
+
setTimeout(function () {
|
|
86
|
+
var _scrollerRef$current2;
|
|
87
|
+
(_scrollerRef$current2 = scrollerRef.current) === null || _scrollerRef$current2 === void 0 || (_scrollerRef$current2 = _scrollerRef$current2.querySelector("[data-index=\"".concat(row, "\"]"))) === null || _scrollerRef$current2 === void 0 || _scrollerRef$current2.classList.add("hilight", "ring-1");
|
|
88
|
+
}, 100);
|
|
76
89
|
},
|
|
77
|
-
|
|
78
|
-
var
|
|
79
|
-
|
|
80
|
-
el === null || el === void 0 || el.scrollIntoView({
|
|
81
|
-
behavior: "smooth"
|
|
82
|
-
});
|
|
90
|
+
unhilight: function unhilight() {
|
|
91
|
+
var _scrollerRef$current3;
|
|
92
|
+
(_scrollerRef$current3 = scrollerRef.current) === null || _scrollerRef$current3 === void 0 || (_scrollerRef$current3 = _scrollerRef$current3.querySelector(".hilight")) === null || _scrollerRef$current3 === void 0 || _scrollerRef$current3.classList.remove("hilight", "ring-1");
|
|
83
93
|
}
|
|
84
94
|
};
|
|
85
95
|
}, []);
|
|
96
|
+
react.useEffect(function () {
|
|
97
|
+
var handle = utilities.debounce(function (top) {
|
|
98
|
+
onScroll === null || onScroll === void 0 || onScroll(top !== null && top !== void 0 ? top : 0);
|
|
99
|
+
});
|
|
100
|
+
handle(top);
|
|
101
|
+
return function () {
|
|
102
|
+
handle.cancel();
|
|
103
|
+
};
|
|
104
|
+
}, [top]);
|
|
86
105
|
return /*#__PURE__*/jsxRuntime.jsx(Context.TableProvider, {
|
|
87
106
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
88
107
|
className: "grid area-content overflow-auto relative",
|
|
@@ -94,7 +113,9 @@ var Table = function Table(_ref) {
|
|
|
94
113
|
className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
|
|
95
114
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
96
115
|
className: wrapperStart,
|
|
97
|
-
children: [
|
|
116
|
+
children: [canExpand && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
117
|
+
className: "w-6"
|
|
118
|
+
}), checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
|
|
98
119
|
state: checkState.allChecked,
|
|
99
120
|
onClick: toggleAllChecked
|
|
100
121
|
}), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
|
|
@@ -133,74 +154,55 @@ var Table = function Table(_ref) {
|
|
|
133
154
|
height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
|
|
134
155
|
}
|
|
135
156
|
}), items.map(function (_ref2) {
|
|
136
|
-
var _state$start2, _state$cols2, _state$end2;
|
|
137
157
|
var index = _ref2.index,
|
|
138
158
|
key = _ref2.key;
|
|
139
159
|
var data = getData(index);
|
|
140
|
-
return /*#__PURE__*/jsxRuntime.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
column: col,
|
|
159
|
-
item: data
|
|
160
|
-
}, "".concat(key, ":").concat(ids));
|
|
161
|
-
})]
|
|
162
|
-
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col, idc) {
|
|
163
|
-
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
164
|
-
column: col,
|
|
165
|
-
item: data
|
|
166
|
-
}, "".concat(key, ":").concat(idc));
|
|
167
|
-
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
168
|
-
className: wrapperEnd,
|
|
169
|
-
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col, ide) {
|
|
170
|
-
return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
|
|
171
|
-
column: col,
|
|
172
|
-
item: data
|
|
173
|
-
}, "".concat(key, ":").concat(ide));
|
|
174
|
-
}), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
175
|
-
className: "w-6"
|
|
176
|
-
})]
|
|
177
|
-
})]
|
|
160
|
+
return /*#__PURE__*/jsxRuntime.jsx(BodyRow.BodyRow, {
|
|
161
|
+
rowKey: key,
|
|
162
|
+
index: index,
|
|
163
|
+
checkableRows: checkableRows,
|
|
164
|
+
checked: keyProperty && checkState.checked.includes(data[keyProperty]) ? 1 : 0,
|
|
165
|
+
expanded: !!keyProperty && checkState.expanded.includes(data[keyProperty]),
|
|
166
|
+
data: data,
|
|
167
|
+
hideableColumns: hideableColumns,
|
|
168
|
+
keyProperty: keyProperty,
|
|
169
|
+
measureElement: measureElement,
|
|
170
|
+
onRowClick: onRowClick,
|
|
171
|
+
state: state,
|
|
172
|
+
canExpand: canExpand,
|
|
173
|
+
toggleExpand: toggleExpand,
|
|
174
|
+
expandRow: children,
|
|
175
|
+
toggleChecked: toggleChecked,
|
|
176
|
+
wrapperEnd: wrapperEnd,
|
|
177
|
+
wrapperStart: wrapperStart
|
|
178
178
|
}, key);
|
|
179
179
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
180
180
|
className: "flex-1 flex flex-nowrap",
|
|
181
181
|
children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
182
182
|
className: wrapperStart,
|
|
183
|
-
children: [
|
|
183
|
+
children: [canExpand && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
184
|
+
className: "w-6"
|
|
185
|
+
}), checkableRows && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
184
186
|
className: "w-6"
|
|
185
|
-
}), (_state$
|
|
187
|
+
}), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col) {
|
|
186
188
|
return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
|
|
187
189
|
})]
|
|
188
|
-
}), (_state$
|
|
190
|
+
}), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col) {
|
|
189
191
|
return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
|
|
190
192
|
}), /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
191
193
|
className: wrapperEnd,
|
|
192
|
-
children: [(_state$
|
|
194
|
+
children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col) {
|
|
193
195
|
return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
|
|
194
196
|
}), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
195
197
|
className: "w-6"
|
|
196
198
|
})]
|
|
197
199
|
})]
|
|
198
200
|
})]
|
|
199
|
-
}), !loading && data.length === 0 && /*#__PURE__*/jsxRuntime.jsx(core.EmptyContent, {
|
|
201
|
+
}), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsxRuntime.jsx(core.EmptyContent, {
|
|
200
202
|
size: "sm",
|
|
201
203
|
className: "bg-dimmed",
|
|
202
204
|
message: t("datagrid.empty")
|
|
203
|
-
})]
|
|
205
|
+
}))]
|
|
204
206
|
})
|
|
205
207
|
});
|
|
206
208
|
};
|
|
@@ -8,6 +8,7 @@ var react = require('react');
|
|
|
8
8
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
9
9
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
10
10
|
var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged) {
|
|
11
|
+
var _virtualizer$range;
|
|
11
12
|
// TODO: refactor data into item list, apply grouping if groupColumn provided
|
|
12
13
|
// TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
|
|
13
14
|
|
|
@@ -22,8 +23,12 @@ var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged
|
|
|
22
23
|
}
|
|
23
24
|
});
|
|
24
25
|
var _useReducer = react.useReducer(function (state, action) {
|
|
26
|
+
if (action.type === "expand") {
|
|
27
|
+
if (state.expanded.includes(action.key)) state.expanded.splice(state.expanded.indexOf(action.key), 1);else state.expanded.push(action.key);
|
|
28
|
+
}
|
|
25
29
|
if (action.type === "check") {
|
|
26
30
|
if (state.checked.includes(action.key)) state.checked.splice(state.checked.indexOf(action.key), 1);else state.checked.push(action.key);
|
|
31
|
+
onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
|
|
27
32
|
}
|
|
28
33
|
if (action.type === "checkall") {
|
|
29
34
|
if (state.allChecked !== 0) {
|
|
@@ -33,13 +38,14 @@ var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged
|
|
|
33
38
|
return item[keyProperty];
|
|
34
39
|
});
|
|
35
40
|
}
|
|
41
|
+
onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
|
|
36
42
|
}
|
|
37
|
-
onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
|
|
38
43
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
39
44
|
allChecked: state.checked.length === data.length ? 1 : state.checked.length ? 2 : 0
|
|
40
45
|
});
|
|
41
46
|
}, {
|
|
42
47
|
checked: [],
|
|
48
|
+
expanded: [],
|
|
43
49
|
allChecked: 0
|
|
44
50
|
}),
|
|
45
51
|
_useReducer2 = _slicedToArray(_useReducer, 2),
|
|
@@ -54,8 +60,16 @@ var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged
|
|
|
54
60
|
items: virtualItems,
|
|
55
61
|
checkState: state,
|
|
56
62
|
getData: getData,
|
|
63
|
+
virtualizer: virtualizer,
|
|
64
|
+
top: (_virtualizer$range = virtualizer.range) === null || _virtualizer$range === void 0 ? void 0 : _virtualizer$range.startIndex,
|
|
57
65
|
totalSize: virtualizer.getTotalSize,
|
|
58
66
|
measureElement: virtualizer.measureElement,
|
|
67
|
+
toggleExpand: function toggleExpand(key) {
|
|
68
|
+
return dispatch({
|
|
69
|
+
type: "expand",
|
|
70
|
+
key: key
|
|
71
|
+
});
|
|
72
|
+
},
|
|
59
73
|
toggleChecked: function toggleChecked(key) {
|
|
60
74
|
return dispatch({
|
|
61
75
|
type: "check",
|