@react-fabric/data 1.0.0-beta.4 → 1.0.0-beta.40

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 (81) hide show
  1. package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
  2. package/css/styles.css +24 -0
  3. package/dist/cjs/checklist/CheckList.js +25 -16
  4. package/dist/cjs/histogram/Histogram.js +20 -10
  5. package/dist/cjs/hooks/usePagination.js +7 -4
  6. package/dist/cjs/json/JsonViewer.js +40 -27
  7. package/dist/cjs/table/BodyCell.js +38 -5
  8. package/dist/cjs/table/BodyRow.js +107 -0
  9. package/dist/cjs/table/CheckboxCell.js +1 -1
  10. package/dist/cjs/table/HeaderCell.js +29 -36
  11. package/dist/cjs/table/Table.js +105 -67
  12. package/dist/cjs/table/useResizer.js +4 -4
  13. package/dist/cjs/table/useVirtualTable.js +118 -17
  14. package/dist/cjs/tree/TreeNode.js +44 -24
  15. package/dist/cjs/tree/TreePanel.js +28 -10
  16. package/dist/cjs/tree/useTree.js +96 -14
  17. package/dist/cjs/tree/utils.js +20 -5
  18. package/dist/cjs/virtual/Gallery.js +43 -29
  19. package/dist/cjs/virtual/List.js +43 -31
  20. package/dist/esm/checklist/CheckList.js +27 -18
  21. package/dist/esm/histogram/Histogram.js +21 -11
  22. package/dist/esm/hooks/usePagination.js +7 -4
  23. package/dist/esm/json/JsonViewer.js +41 -28
  24. package/dist/esm/table/BodyCell.js +38 -5
  25. package/dist/esm/table/BodyRow.js +107 -0
  26. package/dist/esm/table/CheckboxCell.js +1 -1
  27. package/dist/esm/table/HeaderCell.js +30 -37
  28. package/dist/esm/table/Table.js +107 -69
  29. package/dist/esm/table/useResizer.js +4 -4
  30. package/dist/esm/table/useVirtualTable.js +120 -19
  31. package/dist/esm/tree/TreeNode.js +46 -26
  32. package/dist/esm/tree/TreePanel.js +28 -10
  33. package/dist/esm/tree/useTree.js +98 -16
  34. package/dist/esm/tree/utils.js +20 -5
  35. package/dist/esm/virtual/Gallery.js +43 -29
  36. package/dist/esm/virtual/List.js +43 -31
  37. package/dist/types/checklist/CheckList.d.ts +2 -2
  38. package/dist/types/histogram/Histogram.d.ts +3 -3
  39. package/dist/types/index.d.ts +1 -1
  40. package/dist/types/table/AddColumn.d.ts +2 -2
  41. package/dist/types/table/BodyCell.d.ts +4 -3
  42. package/dist/types/table/BodyRow.d.ts +20 -0
  43. package/dist/types/table/EmptyCell.d.ts +2 -2
  44. package/dist/types/table/HeaderCell.d.ts +2 -2
  45. package/dist/types/table/Table.d.ts +1 -1
  46. package/dist/types/table/types.d.ts +17 -6
  47. package/dist/types/table/useTableColumns.d.ts +6 -6
  48. package/dist/types/table/useVirtualTable.d.ts +20 -5
  49. package/dist/types/tree/TreeNode.d.ts +1 -1
  50. package/dist/types/tree/TreePanel.d.ts +1 -1
  51. package/dist/types/tree/types.d.ts +25 -5
  52. package/dist/types/tree/useTree.d.ts +2 -9
  53. package/dist/types/tree/utils.d.ts +4 -1
  54. package/dist/types/virtual/Gallery.d.ts +12 -4
  55. package/dist/types/virtual/List.d.ts +7 -3
  56. package/package.json +10 -7
  57. package/src/checklist/CheckList.tsx +81 -77
  58. package/src/histogram/Histogram.tsx +17 -11
  59. package/src/hooks/usePagination.tsx +13 -7
  60. package/src/index.ts +1 -1
  61. package/src/json/JsonViewer.tsx +45 -35
  62. package/src/table/AddColumn.tsx +2 -2
  63. package/src/table/BodyCell.tsx +34 -5
  64. package/src/table/BodyRow.tsx +143 -0
  65. package/src/table/CheckboxCell.tsx +1 -1
  66. package/src/table/EmptyCell.tsx +2 -2
  67. package/src/table/HeaderCell.tsx +27 -13
  68. package/src/table/Table.tsx +141 -73
  69. package/src/table/types.ts +20 -5
  70. package/src/table/useResizer.ts +5 -3
  71. package/src/table/useTableColumns.ts +7 -7
  72. package/src/table/useVirtualTable.ts +143 -28
  73. package/src/tree/TreeNode.tsx +90 -56
  74. package/src/tree/TreePanel.tsx +23 -3
  75. package/src/tree/types.ts +32 -4
  76. package/src/tree/useTree.ts +102 -23
  77. package/src/tree/utils.ts +23 -8
  78. package/src/virtual/Gallery.tsx +46 -35
  79. package/src/virtual/List.tsx +40 -27
  80. package/dist/cjs/histogram/Histogram.module.css +0 -1
  81. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -1,44 +1,23 @@
1
1
  'use strict';
2
2
 
3
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
3
4
  var core = require('@react-fabric/core');
4
5
  var react = require('react');
5
6
  var Context = require('./Context.js');
6
7
  var types = require('./types.js');
7
8
  var jsxRuntime = require('react/jsx-runtime');
8
9
 
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
10
  var HeaderCell = function HeaderCell(_ref) {
33
11
  var id = _ref.id,
34
12
  label = _ref.label,
35
13
  icon = _ref.icon,
36
14
  iconBg = _ref.iconBg,
37
15
  iconColor = _ref.iconColor,
38
- rtlFlip = _ref.rtlFlip;
39
- _ref.actions;
16
+ rtlFlip = _ref.rtlFlip,
17
+ actions = _ref.actions;
40
18
  _ref.locked;
41
- var sortable = _ref.sortable,
19
+ var tooltip = _ref.tooltip,
20
+ sortable = _ref.sortable,
42
21
  resizable = _ref.resizable,
43
22
  _width = _ref.width,
44
23
  maxWidth = _ref.maxWidth,
@@ -52,38 +31,52 @@ var HeaderCell = function HeaderCell(_ref) {
52
31
  var _widths$get;
53
32
  return (_widths$get = widths.get(id.toString())) !== null && _widths$get !== void 0 ? _widths$get : _width;
54
33
  }, [widths, _width, id]);
55
- var handleSort = react.useCallback(function () {
34
+ var handleSort = react.useCallback(function (order) {
56
35
  sortable && (onSort === null || onSort === void 0 ? void 0 : onSort({
57
36
  id: id.toString(),
58
- order: (sort === null || sort === void 0 ? void 0 : sort.id) === id && sort.order === "asc" ? "desc" : "asc"
37
+ order: order !== null && order !== void 0 ? order : (sort === null || sort === void 0 ? void 0 : sort.id) === id && sort.order === "asc" ? "desc" : "asc"
59
38
  }));
60
- }, [onSort, name, sort, sortable]);
39
+ }, [onSort, sort, sortable]);
61
40
  var menus = react.useMemo(function () {
62
41
  var ret = [];
63
42
  if (sortable) {
64
43
  ret.push( /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
65
44
  label: "Sort ascending",
66
- icon: core.CoreIcons.sortAsc
45
+ icon: core.CoreIcons.sortAsc,
46
+ onClick: function onClick() {
47
+ return handleSort("asc");
48
+ }
67
49
  }, "sort-asc"), /*#__PURE__*/jsxRuntime.jsx(core.MenuItem, {
68
50
  label: "Sort descending",
69
- icon: core.CoreIcons.sortDesc
51
+ icon: core.CoreIcons.sortDesc,
52
+ onClick: function onClick() {
53
+ return handleSort("desc");
54
+ }
70
55
  }, "sort-desc"));
71
56
  }
57
+ if (sortable && actions) {
58
+ ret.push( /*#__PURE__*/jsxRuntime.jsx(core.Divider, {}));
59
+ }
60
+ if (actions) {
61
+ ret.push.apply(ret, _toConsumableArray(actions));
62
+ }
72
63
  return ret;
73
- }, [sortable]);
64
+ }, [sortable, actions]);
74
65
  return /*#__PURE__*/jsxRuntime.jsxs("div", {
75
66
  role: "none",
76
67
  "data-id": id,
77
- onClick: handleSort,
78
- className: "group font-medium border-e flex flex-nowrap text-start items-center table-header-cell",
68
+ onClick: function onClick() {
69
+ return handleSort();
70
+ },
71
+ className: "group/tool font-medium border-e flex flex-nowrap text-start items-center table-header-cell",
79
72
  style: {
80
73
  width: width !== null && width !== void 0 ? width : types.COL_DEFAULT_WIDTH,
81
74
  minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : types.COL_MIN_WIDTH,
82
75
  maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : types.COL_MAX_WIDTH
83
76
  },
84
77
  children: [/*#__PURE__*/jsxRuntime.jsx(core.Tooltip, {
85
- content: label,
86
- disabled: !label,
78
+ content: tooltip !== null && tooltip !== void 0 ? tooltip : label,
79
+ disabled: !(tooltip !== null && tooltip !== void 0 ? tooltip : label),
87
80
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
88
81
  className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
89
82
  children: [icon && /*#__PURE__*/jsxRuntime.jsx(core.Icon, {
@@ -2,11 +2,12 @@
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var core = require('@react-fabric/core');
5
+ var utilities = require('@react-fabric/utilities');
5
6
  var classNames = require('classnames');
6
7
  var react = require('react');
7
8
  var reactI18next = require('react-i18next');
8
9
  var AddColumn = require('./AddColumn.js');
9
- var BodyCell = require('./BodyCell.js');
10
+ var BodyRow = require('./BodyRow.js');
10
11
  var CheckboxCell = require('./CheckboxCell.js');
11
12
  var Context = require('./Context.js');
12
13
  var EmptyCell = require('./EmptyCell.js');
@@ -18,16 +19,25 @@ var jsxRuntime = require('react/jsx-runtime');
18
19
  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
20
  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
21
  var Table = function Table(_ref) {
21
- var _state$start, _state$cols, _state$end, _items$, _state$start3, _state$cols3, _state$end3;
22
+ var _state$start, _state$cols, _state$end, _items, _state$start2, _state$cols2, _state$end2;
22
23
  var ref = _ref.ref,
23
24
  data = _ref.data,
24
25
  columns = _ref.columns,
25
- keyProperty = _ref.keyProperty,
26
+ _ref$keyProperty = _ref.keyProperty,
27
+ keyProperty = _ref$keyProperty === void 0 ? "id" : _ref$keyProperty,
28
+ groupProperty = _ref.groupProperty,
26
29
  checkableRows = _ref.checkableRows,
30
+ initialScroll = _ref.initialScroll,
27
31
  hideableColumns = _ref.hideableColumns,
28
32
  sort = _ref.sort,
29
33
  loading = _ref.loading,
34
+ checked = _ref.checked,
35
+ emptyDisplay = _ref.emptyDisplay,
36
+ groupRenderer = _ref.groupRenderer,
37
+ canExpand = _ref.canExpand,
38
+ children = _ref.children,
30
39
  onSort = _ref.onSort,
40
+ onScroll = _ref.onScroll,
31
41
  onRowClick = _ref.onRowClick,
32
42
  onCheckedChanged = _ref.onCheckedChanged;
33
43
  var _useTranslation = reactI18next.useTranslation("data"),
@@ -38,14 +48,25 @@ var Table = function Table(_ref) {
38
48
  var _useTableColumns = useTableColumns.useTableColumns(columns),
39
49
  state = _useTableColumns.state,
40
50
  onHide = _useTableColumns.onHide;
41
- var _useVirtualTable = useVirtualTable.useVirtualTable(data, keyProperty, fireCheckChanged),
51
+ var _useVirtualTable = useVirtualTable.useVirtualTable(data, {
52
+ checked: checked,
53
+ keyProperty: keyProperty,
54
+ groupProperty: groupProperty,
55
+ onCheckChanged: fireCheckChanged
56
+ }),
42
57
  scrollerRef = _useVirtualTable.scrollerRef,
43
58
  items = _useVirtualTable.items,
59
+ top = _useVirtualTable.top,
44
60
  checkState = _useVirtualTable.checkState,
61
+ virtualizer = _useVirtualTable.virtualizer,
62
+ hasActiveSticky = _useVirtualTable.hasActiveSticky,
63
+ toggleExpand = _useVirtualTable.toggleExpand,
45
64
  toggleChecked = _useVirtualTable.toggleChecked,
46
65
  toggleAllChecked = _useVirtualTable.toggleAllChecked,
66
+ toggleGroupExpand = _useVirtualTable.toggleGroupExpand,
47
67
  getData = _useVirtualTable.getData,
48
68
  totalSize = _useVirtualTable.totalSize,
69
+ isActiveSticky = _useVirtualTable.isActiveSticky,
49
70
  measureElement = _useVirtualTable.measureElement;
50
71
  var refBody = react.useRef(null);
51
72
  var wrapperStart = react.useMemo(function () {
@@ -54,47 +75,62 @@ var Table = function Table(_ref) {
54
75
  var wrapperEnd = react.useMemo(function () {
55
76
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
56
77
  }, []);
78
+ react.useLayoutEffect(function () {
79
+ setTimeout(function () {
80
+ initialScroll && virtualizer.scrollToIndex(initialScroll, {
81
+ align: "start"
82
+ });
83
+ }, 100);
84
+ }, []);
57
85
  react.useImperativeHandle(ref, function () {
58
86
  return {
59
- hilight: function hilight(row) {
60
- var _refBody$current, _refBody$current2;
61
- (_refBody$current = refBody.current) === null || _refBody$current === void 0 || _refBody$current.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
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"
87
+ scrollTo: function scrollTo(row) {
88
+ virtualizer.scrollToIndex(row, {
89
+ align: "start"
68
90
  });
69
- el && (el.dataset.hilight = "true");
70
91
  },
71
- unhilight: function unhilight() {
72
- var _refBody$current3;
73
- (_refBody$current3 = refBody.current) === null || _refBody$current3 === void 0 || _refBody$current3.querySelectorAll(".datatable-row[data-hilight=\"true\"]").forEach(function (el) {
74
- return el && (el.dataset.hilight = undefined);
92
+ hilight: function hilight(row) {
93
+ var _scrollerRef$current;
94
+ (_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");
95
+ virtualizer.scrollToIndex(Math.floor(row), {
96
+ align: "start"
75
97
  });
98
+ setTimeout(function () {
99
+ var _scrollerRef$current2;
100
+ (_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");
101
+ }, 100);
76
102
  },
77
- scrollTo: function scrollTo(row) {
78
- var _refBody$current4;
79
- var el = (_refBody$current4 = refBody.current) === null || _refBody$current4 === void 0 ? void 0 : _refBody$current4.querySelector("[data-row=\"".concat(row, "\"]"));
80
- el === null || el === void 0 || el.scrollIntoView({
81
- behavior: "smooth"
82
- });
103
+ unhilight: function unhilight() {
104
+ var _scrollerRef$current3;
105
+ (_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
106
  }
84
107
  };
85
108
  }, []);
109
+ react.useEffect(function () {
110
+ var handle = utilities.debounce(function (top) {
111
+ onScroll === null || onScroll === void 0 || onScroll(top !== null && top !== void 0 ? top : 0);
112
+ });
113
+ handle(top);
114
+ return function () {
115
+ handle.cancel();
116
+ };
117
+ }, [top]);
86
118
  return /*#__PURE__*/jsxRuntime.jsx(Context.TableProvider, {
87
119
  children: /*#__PURE__*/jsxRuntime.jsxs("div", {
88
120
  className: "grid area-content overflow-auto relative",
89
121
  style: {
90
122
  gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
91
123
  },
124
+ "data-ref": "tableScroller",
92
125
  ref: scrollerRef,
93
126
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
94
- className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
127
+ "data-ref": "tableHeader",
128
+ className: "bg-base font-medium sticky top-0 h-8 area-head border-b select-none flex flex-nowrap z-5",
95
129
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
96
130
  className: wrapperStart,
97
- children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
131
+ children: [canExpand && /*#__PURE__*/jsxRuntime.jsx("div", {
132
+ className: "w-6"
133
+ }), checkableRows && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
98
134
  state: checkState.allChecked,
99
135
  onClick: toggleAllChecked
100
136
  }), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
@@ -130,77 +166,79 @@ var Table = function Table(_ref) {
130
166
  ref: refBody,
131
167
  children: [/*#__PURE__*/jsxRuntime.jsx("div", {
132
168
  style: {
133
- height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
169
+ height: (_items = items[hasActiveSticky ? 1 : 0]) === null || _items === void 0 ? void 0 : _items.start
134
170
  }
135
171
  }), items.map(function (_ref2) {
136
- var _state$start2, _state$cols2, _state$end2;
172
+ var _groupRenderer;
137
173
  var index = _ref2.index,
138
174
  key = _ref2.key;
139
175
  var data = getData(index);
140
- return /*#__PURE__*/jsxRuntime.jsxs("div", {
176
+ return "__GROUP__" in data ? /*#__PURE__*/jsxRuntime.jsxs("div", {
177
+ ref: measureElement,
178
+ "data-index": index,
179
+ className: classNames("px-2 py-1 text-md bg-base border-y border-tint-100 cursor-pointer flex items-center gap-1 z-3", isActiveSticky(index) && "sticky top-8"),
141
180
  role: "none",
142
- "data-row": index,
143
- className: classNames("flex flex-nowrap datatable-row data-[hilight]:outline-1 -outline-offset-1 outline-primary-500", index % 2 ? "bg-even" : "bg-odd", onRowClick && "hover:bg-primary-50 active:bg-primary-100"),
144
181
  onClick: function onClick() {
145
- return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
182
+ return toggleGroupExpand(data.key);
146
183
  },
147
- "data-index": index,
148
- ref: measureElement,
149
- children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
150
- className: wrapperStart,
151
- children: [checkableRows && keyProperty && /*#__PURE__*/jsxRuntime.jsx(CheckboxCell.CheckboxCell, {
152
- onClick: function onClick() {
153
- return toggleChecked(data[keyProperty]);
154
- },
155
- state: checkState.checked.includes(data[keyProperty]) ? 1 : 0
156
- }), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col, ids) {
157
- return /*#__PURE__*/jsxRuntime.jsx(BodyCell.BodyCell, {
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"
184
+ children: [/*#__PURE__*/jsxRuntime.jsx(core.Icon, {
185
+ rtlFlip: true,
186
+ icon: data.open ? core.CoreIcons.chevronDown : core.CoreIcons.chevronRight
187
+ }), (_groupRenderer = groupRenderer === null || groupRenderer === void 0 ? void 0 : groupRenderer(data)) !== null && _groupRenderer !== void 0 ? _groupRenderer : /*#__PURE__*/jsxRuntime.jsxs("div", {
188
+ className: "flex gap-1 items-center",
189
+ children: [/*#__PURE__*/jsxRuntime.jsx("span", {
190
+ children: data.key
191
+ }), /*#__PURE__*/jsxRuntime.jsxs("span", {
192
+ className: "text-sm",
193
+ children: ["(", data.itemCount, ")"]
176
194
  })]
177
195
  })]
196
+ }, key) : /*#__PURE__*/jsxRuntime.jsx(BodyRow.BodyRow, {
197
+ rowKey: key,
198
+ index: index,
199
+ checkableRows: checkableRows,
200
+ checked: keyProperty && checkState.checked.includes(data[keyProperty]) ? 1 : 0,
201
+ expanded: !!keyProperty && checkState.expanded.includes(data[keyProperty]),
202
+ data: data,
203
+ hideableColumns: hideableColumns,
204
+ keyProperty: keyProperty,
205
+ measureElement: measureElement,
206
+ onRowClick: onRowClick,
207
+ state: state,
208
+ canExpand: canExpand,
209
+ toggleExpand: toggleExpand,
210
+ expandRow: children,
211
+ toggleChecked: toggleChecked,
212
+ wrapperEnd: wrapperEnd,
213
+ wrapperStart: wrapperStart
178
214
  }, key);
179
215
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
180
216
  className: "flex-1 flex flex-nowrap",
181
217
  children: [/*#__PURE__*/jsxRuntime.jsxs("div", {
182
218
  className: wrapperStart,
183
- children: [checkableRows && /*#__PURE__*/jsxRuntime.jsx("div", {
219
+ children: [canExpand && /*#__PURE__*/jsxRuntime.jsx("div", {
220
+ className: "w-6"
221
+ }), checkableRows && /*#__PURE__*/jsxRuntime.jsx("div", {
184
222
  className: "w-6"
185
- }), (_state$start3 = state.start) === null || _state$start3 === void 0 ? void 0 : _state$start3.map(function (col) {
223
+ }), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col) {
186
224
  return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
187
225
  })]
188
- }), (_state$cols3 = state.cols) === null || _state$cols3 === void 0 ? void 0 : _state$cols3.map(function (col) {
226
+ }), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col) {
189
227
  return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
190
228
  }), /*#__PURE__*/jsxRuntime.jsxs("div", {
191
229
  className: wrapperEnd,
192
- children: [(_state$end3 = state.end) === null || _state$end3 === void 0 ? void 0 : _state$end3.map(function (col) {
230
+ children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col) {
193
231
  return /*#__PURE__*/jsxRuntime.jsx(EmptyCell.EmptyCell, _objectSpread({}, col), String(col.id));
194
232
  }), hideableColumns && /*#__PURE__*/jsxRuntime.jsx("div", {
195
233
  className: "w-6"
196
234
  })]
197
235
  })]
198
236
  })]
199
- }), !loading && data.length === 0 && /*#__PURE__*/jsxRuntime.jsx(core.EmptyContent, {
237
+ }), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsxRuntime.jsx(core.EmptyContent, {
200
238
  size: "sm",
201
239
  className: "bg-dimmed",
202
240
  message: t("datagrid.empty")
203
- })]
241
+ }))]
204
242
  })
205
243
  });
206
244
  };
@@ -44,14 +44,14 @@ var useResizer = function useResizer(colEl, ghostEl, callback) {
44
44
  /** ***************** attach handlers *******************/
45
45
  var box = colEl.getBoundingClientRect();
46
46
  if (colEl.parentElement != null) {
47
- var _colEl$parentElement;
48
- var parentBox = (_colEl$parentElement = colEl.parentElement) === null || _colEl$parentElement === void 0 ? void 0 : _colEl$parentElement.getBoundingClientRect();
47
+ var _colEl$closest;
48
+ var parentBox = (_colEl$closest = colEl.closest("[data-ref='tableScroller']")) === null || _colEl$closest === void 0 ? void 0 : _colEl$closest.getBoundingClientRect();
49
49
  if (isRtl) {
50
50
  placeholder.style.left = "unset";
51
- placeholder.style.right = "".concat(box.right - parentBox.right, "px");
51
+ placeholder.style.right = "".concat(parentBox.width - box.right, "px");
52
52
  } else {
53
53
  placeholder.style.right = "unset";
54
- placeholder.style.left = "".concat(box.left - parentBox.left, "px");
54
+ placeholder.style.left = "".concat(box.left, "px");
55
55
  }
56
56
  }
57
57
  placeholder.style.width = "".concat(colEl.offsetWidth, "px");
@@ -1,61 +1,162 @@
1
1
  'use strict';
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
+ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
4
5
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
+ var utilities = require('@react-fabric/utilities');
5
7
  var reactVirtual = require('@tanstack/react-virtual');
6
8
  var react = require('react');
7
9
 
8
10
  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
11
  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
- var useVirtualTable = function useVirtualTable(data, keyProperty, onCheckChanged) {
12
+ var useVirtualTable = function useVirtualTable(data, options) {
13
+ var _virtualizer$range;
11
14
  // TODO: refactor data into item list, apply grouping if groupColumn provided
12
15
  // TODO: when grouping maintain map of group with children, {___GROUP___:true, label, items, open}
13
16
 
14
- var scrollerRef = react.useRef(null);
15
- var virtualizer = reactVirtual.useVirtualizer({
16
- count: data.length,
17
- getScrollElement: function getScrollElement() {
18
- return scrollerRef.current;
19
- },
20
- estimateSize: function estimateSize() {
21
- return 24;
22
- }
23
- });
24
17
  var _useReducer = react.useReducer(function (state, action) {
18
+ if (action.type === "updateState") {
19
+ state.checked = action.checked;
20
+ }
21
+ if (action.type === "expand") {
22
+ if (state.expanded.includes(action.key)) state.expanded.splice(state.expanded.indexOf(action.key), 1);else state.expanded.push(action.key);
23
+ }
25
24
  if (action.type === "check") {
25
+ var _options$onCheckChang;
26
26
  if (state.checked.includes(action.key)) state.checked.splice(state.checked.indexOf(action.key), 1);else state.checked.push(action.key);
27
+ (_options$onCheckChang = options.onCheckChanged) === null || _options$onCheckChang === void 0 || _options$onCheckChang.call(options, state.checked);
27
28
  }
28
29
  if (action.type === "checkall") {
30
+ var _options$onCheckChang2;
29
31
  if (state.allChecked !== 0) {
30
32
  state.checked = [];
31
- } else if (keyProperty) {
33
+ } else if (options.keyProperty) {
32
34
  state.checked = data.map(function (item) {
33
- return item[keyProperty];
35
+ return item[options.keyProperty];
36
+ });
37
+ }
38
+ (_options$onCheckChang2 = options.onCheckChanged) === null || _options$onCheckChang2 === void 0 || _options$onCheckChang2.call(options, state.checked);
39
+ }
40
+ var checkList = data.filter(function (hit) {
41
+ return state.checked.includes(hit[options.keyProperty]);
42
+ });
43
+ if (action.type === "groupExpand") {
44
+ var group = state.groups.find(function (group) {
45
+ return group.key === action.key;
46
+ });
47
+ if (group) {
48
+ group.open = !group.open;
49
+ state.groups = state.groups.slice();
50
+ state.items = state.groups.map(function (group) {
51
+ return [group, group.open ? state.grouped[group.key] : undefined];
52
+ }).flat(2).filter(Boolean);
53
+ }
54
+ }
55
+ if (action.type === "grouped") {
56
+ if (action.key) {
57
+ state.grouped = utilities.groupBy(data, action.key);
58
+ state.groups = Object.keys(state.grouped).sort(utilities.compareValues("asc")).map(function (group) {
59
+ return {
60
+ __GROUP__: true,
61
+ open: true,
62
+ key: group,
63
+ items: state.grouped[group],
64
+ itemCount: state.grouped[group].length
65
+ };
34
66
  });
67
+ state.items = state.groups.map(function (group) {
68
+ return [group].concat(_toConsumableArray(state.grouped[group.key]));
69
+ }).flat();
70
+ } else {
71
+ state.items = data;
35
72
  }
36
73
  }
37
- onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
38
74
  return _objectSpread(_objectSpread({}, state), {}, {
39
- allChecked: state.checked.length === data.length ? 1 : state.checked.length ? 2 : 0
75
+ allChecked: checkList.length === data.length ? 1 : state.checked.length ? 2 : 0
40
76
  });
41
77
  }, {
78
+ items: data,
79
+ grouped: {},
80
+ groups: [],
42
81
  checked: [],
82
+ expanded: [],
43
83
  allChecked: 0
44
84
  }),
45
85
  _useReducer2 = _slicedToArray(_useReducer, 2),
46
86
  state = _useReducer2[0],
47
87
  dispatch = _useReducer2[1];
88
+ var activeStickyIndexRef = react.useRef(0);
89
+ var stickyIndexes = react.useMemo(function () {
90
+ return state.items.map(function (hit, idx) {
91
+ return "__GROUP__" in hit ? idx : undefined;
92
+ }).filter(Boolean);
93
+ }, [state.items]);
94
+ var isActiveSticky = function isActiveSticky(index) {
95
+ return activeStickyIndexRef.current === index;
96
+ };
97
+ var _useState = react.useState(false),
98
+ _useState2 = _slicedToArray(_useState, 2),
99
+ hasActiveSticky = _useState2[0],
100
+ setHasActiveSticky = _useState2[1];
101
+ var scrollerRef = react.useRef(null);
102
+ var virtualizer = reactVirtual.useVirtualizer({
103
+ count: state.items.length,
104
+ getScrollElement: function getScrollElement() {
105
+ return scrollerRef.current;
106
+ },
107
+ estimateSize: function estimateSize() {
108
+ return 32;
109
+ },
110
+ rangeExtractor: react.useCallback(function (range) {
111
+ var _reverse$find;
112
+ activeStickyIndexRef.current = (_reverse$find = _toConsumableArray(stickyIndexes).reverse().find(function (index) {
113
+ return range.startIndex > index;
114
+ })) !== null && _reverse$find !== void 0 ? _reverse$find : 0;
115
+ setHasActiveSticky(range.startIndex !== activeStickyIndexRef.current);
116
+ var next = new Set([activeStickyIndexRef.current].concat(_toConsumableArray(reactVirtual.defaultRangeExtractor(range))));
117
+ return _toConsumableArray(next);
118
+ }, [stickyIndexes])
119
+ });
48
120
  var virtualItems = virtualizer.getVirtualItems();
49
121
  var getData = react.useCallback(function (index) {
50
- return data[index];
51
- }, [data]);
122
+ return state.items[index];
123
+ }, [state.items]);
124
+ react.useEffect(function () {
125
+ dispatch({
126
+ type: "grouped",
127
+ key: options.groupProperty
128
+ });
129
+ }, [options.groupProperty]);
130
+ react.useEffect(function () {
131
+ var _options$checked;
132
+ dispatch({
133
+ type: "updateState",
134
+ checked: (_options$checked = options.checked) !== null && _options$checked !== void 0 ? _options$checked : []
135
+ });
136
+ }, [options.checked]);
52
137
  return {
53
138
  scrollerRef: scrollerRef,
54
139
  items: virtualItems,
55
140
  checkState: state,
56
141
  getData: getData,
142
+ virtualizer: virtualizer,
143
+ hasActiveSticky: hasActiveSticky,
144
+ isActiveSticky: isActiveSticky,
145
+ top: (_virtualizer$range = virtualizer.range) === null || _virtualizer$range === void 0 ? void 0 : _virtualizer$range.startIndex,
57
146
  totalSize: virtualizer.getTotalSize,
58
147
  measureElement: virtualizer.measureElement,
148
+ toggleGroupExpand: function toggleGroupExpand(key) {
149
+ return dispatch({
150
+ type: "groupExpand",
151
+ key: key
152
+ });
153
+ },
154
+ toggleExpand: function toggleExpand(key) {
155
+ return dispatch({
156
+ type: "expand",
157
+ key: key
158
+ });
159
+ },
59
160
  toggleChecked: function toggleChecked(key) {
60
161
  return dispatch({
61
162
  type: "check",