@react-fabric/data 1.0.0-beta.5 → 1.0.0-beta.51

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 (88) 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/AddColumn.js +1 -1
  8. package/dist/cjs/table/BodyCell.js +38 -5
  9. package/dist/cjs/table/BodyRow.js +107 -0
  10. package/dist/cjs/table/CheckboxCell.js +1 -1
  11. package/dist/cjs/table/ColumnFilters.js +97 -0
  12. package/dist/cjs/table/HeaderCell.js +70 -37
  13. package/dist/cjs/table/Table.js +113 -71
  14. package/dist/cjs/table/useResizer.js +4 -4
  15. package/dist/cjs/table/useVirtualTable.js +122 -18
  16. package/dist/cjs/tree/TreeNode.js +45 -25
  17. package/dist/cjs/tree/TreePanel.js +28 -10
  18. package/dist/cjs/tree/useTree.js +97 -15
  19. package/dist/cjs/tree/utils.js +20 -5
  20. package/dist/cjs/virtual/Gallery.js +51 -35
  21. package/dist/cjs/virtual/List.js +44 -31
  22. package/dist/esm/checklist/CheckList.js +27 -18
  23. package/dist/esm/histogram/Histogram.js +21 -11
  24. package/dist/esm/hooks/usePagination.js +7 -4
  25. package/dist/esm/json/JsonViewer.js +41 -28
  26. package/dist/esm/table/AddColumn.js +1 -1
  27. package/dist/esm/table/BodyCell.js +38 -5
  28. package/dist/esm/table/BodyRow.js +107 -0
  29. package/dist/esm/table/CheckboxCell.js +1 -1
  30. package/dist/esm/table/ColumnFilters.js +97 -0
  31. package/dist/esm/table/HeaderCell.js +71 -38
  32. package/dist/esm/table/Table.js +115 -73
  33. package/dist/esm/table/useResizer.js +4 -4
  34. package/dist/esm/table/useVirtualTable.js +124 -20
  35. package/dist/esm/tree/TreeNode.js +47 -27
  36. package/dist/esm/tree/TreePanel.js +28 -10
  37. package/dist/esm/tree/useTree.js +99 -17
  38. package/dist/esm/tree/utils.js +20 -5
  39. package/dist/esm/virtual/Gallery.js +51 -35
  40. package/dist/esm/virtual/List.js +44 -31
  41. package/dist/types/checklist/CheckList.d.ts +2 -2
  42. package/dist/types/histogram/Histogram.d.ts +3 -4
  43. package/dist/types/index.d.ts +1 -1
  44. package/dist/types/json/JsonViewer.d.ts +0 -1
  45. package/dist/types/table/AddColumn.d.ts +2 -2
  46. package/dist/types/table/BodyCell.d.ts +4 -3
  47. package/dist/types/table/BodyRow.d.ts +20 -0
  48. package/dist/types/table/ColumnFilters.d.ts +9 -0
  49. package/dist/types/table/EmptyCell.d.ts +2 -2
  50. package/dist/types/table/HeaderCell.d.ts +2 -2
  51. package/dist/types/table/Table.d.ts +1 -1
  52. package/dist/types/table/types.d.ts +20 -7
  53. package/dist/types/table/useTableColumns.d.ts +6 -6
  54. package/dist/types/table/useVirtualTable.d.ts +23 -7
  55. package/dist/types/tree/TreeNode.d.ts +1 -1
  56. package/dist/types/tree/TreePanel.d.ts +1 -1
  57. package/dist/types/tree/types.d.ts +25 -5
  58. package/dist/types/tree/useTree.d.ts +2 -9
  59. package/dist/types/tree/utils.d.ts +4 -1
  60. package/dist/types/virtual/Gallery.d.ts +12 -4
  61. package/dist/types/virtual/List.d.ts +8 -4
  62. package/package.json +13 -10
  63. package/src/checklist/CheckList.tsx +81 -77
  64. package/src/histogram/Histogram.tsx +17 -11
  65. package/src/hooks/usePagination.tsx +13 -7
  66. package/src/index.ts +1 -1
  67. package/src/json/JsonViewer.tsx +45 -35
  68. package/src/table/AddColumn.tsx +3 -3
  69. package/src/table/BodyCell.tsx +34 -5
  70. package/src/table/BodyRow.tsx +143 -0
  71. package/src/table/CheckboxCell.tsx +1 -1
  72. package/src/table/ColumnFilters.tsx +105 -0
  73. package/src/table/EmptyCell.tsx +2 -2
  74. package/src/table/HeaderCell.tsx +72 -14
  75. package/src/table/Table.tsx +164 -77
  76. package/src/table/types.ts +24 -6
  77. package/src/table/useResizer.ts +5 -3
  78. package/src/table/useTableColumns.ts +7 -7
  79. package/src/table/useVirtualTable.ts +146 -24
  80. package/src/tree/TreeNode.tsx +98 -56
  81. package/src/tree/TreePanel.tsx +23 -3
  82. package/src/tree/types.ts +32 -4
  83. package/src/tree/useTree.ts +109 -26
  84. package/src/tree/utils.ts +23 -8
  85. package/src/virtual/Gallery.tsx +63 -42
  86. package/src/virtual/List.tsx +44 -32
  87. package/dist/cjs/histogram/Histogram.module.css +0 -1
  88. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -1,12 +1,13 @@
1
1
  'use client';
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
- import { useDebounce, Loading, EmptyContent } from '@react-fabric/core';
4
+ import { useDebounce, Loading, Icon, CoreIcons, EmptyContent } from '@react-fabric/core';
5
+ import { debounce } from '@react-fabric/utilities';
5
6
  import classNames from 'classnames';
6
- import { useRef, useMemo, useImperativeHandle } from 'react';
7
+ import { useRef, useMemo, useLayoutEffect, useImperativeHandle, useEffect } from 'react';
7
8
  import { useTranslation } from 'react-i18next';
8
9
  import { AddColumn } from './AddColumn.js';
9
- import { BodyCell } from './BodyCell.js';
10
+ import { BodyRow } from './BodyRow.js';
10
11
  import { CheckboxCell } from './CheckboxCell.js';
11
12
  import { TableProvider } from './Context.js';
12
13
  import { EmptyCell } from './EmptyCell.js';
@@ -18,16 +19,26 @@ import { jsx, jsxs } from '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
+ onFilter = _ref.onFilter,
41
+ onScroll = _ref.onScroll,
31
42
  onRowClick = _ref.onRowClick,
32
43
  onCheckedChanged = _ref.onCheckedChanged;
33
44
  var _useTranslation = useTranslation("data"),
@@ -38,14 +49,25 @@ var Table = function Table(_ref) {
38
49
  var _useTableColumns = useTableColumns(columns),
39
50
  state = _useTableColumns.state,
40
51
  onHide = _useTableColumns.onHide;
41
- var _useVirtualTable = useVirtualTable(data, keyProperty, fireCheckChanged),
52
+ var _useVirtualTable = useVirtualTable(data, {
53
+ checked: checked,
54
+ keyProperty: keyProperty,
55
+ groupProperty: groupProperty,
56
+ onCheckChanged: fireCheckChanged
57
+ }),
42
58
  scrollerRef = _useVirtualTable.scrollerRef,
43
59
  items = _useVirtualTable.items,
60
+ top = _useVirtualTable.top,
44
61
  checkState = _useVirtualTable.checkState,
62
+ virtualizer = _useVirtualTable.virtualizer,
63
+ hasActiveSticky = _useVirtualTable.hasActiveSticky,
64
+ toggleExpand = _useVirtualTable.toggleExpand,
45
65
  toggleChecked = _useVirtualTable.toggleChecked,
46
66
  toggleAllChecked = _useVirtualTable.toggleAllChecked,
67
+ toggleGroupExpand = _useVirtualTable.toggleGroupExpand,
47
68
  getData = _useVirtualTable.getData,
48
69
  totalSize = _useVirtualTable.totalSize,
70
+ isActiveSticky = _useVirtualTable.isActiveSticky,
49
71
  measureElement = _useVirtualTable.measureElement;
50
72
  var refBody = useRef(null);
51
73
  var wrapperStart = useMemo(function () {
@@ -54,66 +76,84 @@ var Table = function Table(_ref) {
54
76
  var wrapperEnd = useMemo(function () {
55
77
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
56
78
  }, []);
79
+ useLayoutEffect(function () {
80
+ setTimeout(function () {
81
+ initialScroll && virtualizer.scrollToIndex(initialScroll, {
82
+ align: "start"
83
+ });
84
+ }, 100);
85
+ }, []);
57
86
  useImperativeHandle(ref, function () {
58
87
  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"
88
+ scrollTo: function scrollTo(row) {
89
+ virtualizer.scrollToIndex(row, {
90
+ align: "start"
68
91
  });
69
- el && (el.dataset.hilight = "true");
70
92
  },
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);
93
+ hilight: function hilight(row) {
94
+ var _scrollerRef$current;
95
+ (_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");
96
+ virtualizer.scrollToIndex(Math.floor(row), {
97
+ align: "start"
75
98
  });
99
+ setTimeout(function () {
100
+ var _scrollerRef$current2;
101
+ (_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");
102
+ }, 100);
76
103
  },
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
- });
104
+ unhilight: function unhilight() {
105
+ var _scrollerRef$current3;
106
+ (_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
107
  }
84
108
  };
85
109
  }, []);
110
+ useEffect(function () {
111
+ var handle = debounce(function (top) {
112
+ onScroll === null || onScroll === void 0 || onScroll(top !== null && top !== void 0 ? top : 0);
113
+ });
114
+ handle(top);
115
+ return function () {
116
+ handle.cancel();
117
+ };
118
+ }, [top]);
86
119
  return /*#__PURE__*/jsx(TableProvider, {
87
120
  children: /*#__PURE__*/jsxs("div", {
88
121
  className: "grid area-content overflow-auto relative",
89
122
  style: {
90
123
  gridTemplate: "\"head\" auto \"loader\" auto \"content\" 1fr \"foot\" auto/1fr"
91
124
  },
125
+ "data-ref": "tableScroller",
92
126
  ref: scrollerRef,
93
127
  children: [/*#__PURE__*/jsxs("div", {
94
- className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
128
+ "data-ref": "tableHeader",
129
+ className: "bg-base font-medium sticky top-0 h-8 area-head border-b select-none flex flex-nowrap z-5",
95
130
  children: [/*#__PURE__*/jsxs("div", {
96
131
  className: wrapperStart,
97
- children: [checkableRows && /*#__PURE__*/jsx(CheckboxCell, {
132
+ children: [canExpand && /*#__PURE__*/jsx("div", {
133
+ className: "w-6"
134
+ }), checkableRows && /*#__PURE__*/jsx(CheckboxCell, {
98
135
  state: checkState.allChecked,
99
136
  onClick: toggleAllChecked
100
137
  }), (_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.map(function (col, idx) {
101
138
  return /*#__PURE__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
102
139
  sort: sort,
103
- onSort: onSort
140
+ onSort: onSort,
141
+ onFilter: onFilter
104
142
  }), idx);
105
143
  })]
106
144
  }), (_state$cols = state.cols) === null || _state$cols === void 0 ? void 0 : _state$cols.map(function (col, idx) {
107
145
  return /*#__PURE__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
108
146
  sort: sort,
109
- onSort: onSort
147
+ onSort: onSort,
148
+ onFilter: onFilter
110
149
  }), idx);
111
150
  }), /*#__PURE__*/jsxs("div", {
112
151
  className: wrapperEnd,
113
152
  children: [(_state$end = state.end) === null || _state$end === void 0 ? void 0 : _state$end.map(function (col, idx) {
114
153
  return /*#__PURE__*/jsx(HeaderCell, _objectSpread(_objectSpread({}, col), {}, {
115
154
  sort: sort,
116
- onSort: onSort
155
+ onSort: onSort,
156
+ onFilter: onFilter
117
157
  }), idx);
118
158
  }), hideableColumns && /*#__PURE__*/jsx(AddColumn, {
119
159
  onClick: onHide,
@@ -123,84 +163,86 @@ var Table = function Table(_ref) {
123
163
  })]
124
164
  })]
125
165
  }), loading && /*#__PURE__*/jsx(Loading, {}), data.length > 0 && /*#__PURE__*/jsxs("div", {
126
- className: "area-content flex flex-col flex-nowrap",
166
+ className: "area-content flex flex-col flex-nowrap min-h-full",
127
167
  style: {
128
168
  height: totalSize()
129
169
  },
130
170
  ref: refBody,
131
171
  children: [/*#__PURE__*/jsx("div", {
132
172
  style: {
133
- height: (_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.start
173
+ height: (_items = items[hasActiveSticky ? 1 : 0]) === null || _items === void 0 ? void 0 : _items.start
134
174
  }
135
175
  }), items.map(function (_ref2) {
136
- var _state$start2, _state$cols2, _state$end2;
176
+ var _groupRenderer;
137
177
  var index = _ref2.index,
138
178
  key = _ref2.key;
139
179
  var data = getData(index);
140
- return /*#__PURE__*/jsxs("div", {
180
+ return "__GROUP__" in data ? /*#__PURE__*/jsxs("div", {
181
+ ref: measureElement,
182
+ "data-index": index,
183
+ 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
184
  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
185
  onClick: function onClick() {
145
- return checkableRows && keyProperty && !onRowClick ? toggleChecked(data[keyProperty]) : onRowClick === null || onRowClick === void 0 ? void 0 : onRowClick(data);
186
+ return toggleGroupExpand(data.key);
146
187
  },
147
- "data-index": index,
148
- ref: measureElement,
149
- children: [/*#__PURE__*/jsxs("div", {
150
- className: wrapperStart,
151
- children: [checkableRows && keyProperty && /*#__PURE__*/jsx(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__*/jsx(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__*/jsx(BodyCell, {
164
- column: col,
165
- item: data
166
- }, "".concat(key, ":").concat(idc));
167
- }), /*#__PURE__*/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__*/jsx(BodyCell, {
171
- column: col,
172
- item: data
173
- }, "".concat(key, ":").concat(ide));
174
- }), hideableColumns && /*#__PURE__*/jsx("div", {
175
- className: "w-6"
188
+ children: [/*#__PURE__*/jsx(Icon, {
189
+ rtlFlip: true,
190
+ icon: data.open ? CoreIcons.chevronDown : CoreIcons.chevronRight
191
+ }), (_groupRenderer = groupRenderer === null || groupRenderer === void 0 ? void 0 : groupRenderer(data)) !== null && _groupRenderer !== void 0 ? _groupRenderer : /*#__PURE__*/jsxs("div", {
192
+ className: "flex gap-1 items-center",
193
+ children: [/*#__PURE__*/jsx("span", {
194
+ children: data.key
195
+ }), /*#__PURE__*/jsxs("span", {
196
+ className: "text-sm",
197
+ children: ["(", data.itemCount, ")"]
176
198
  })]
177
199
  })]
200
+ }, key) : /*#__PURE__*/jsx(BodyRow, {
201
+ rowKey: key.toString(),
202
+ index: index,
203
+ checkableRows: checkableRows,
204
+ checked: keyProperty && checkState.checked.includes(data[keyProperty]) ? 1 : 0,
205
+ expanded: !!keyProperty && checkState.expanded.includes(data[keyProperty]),
206
+ data: data,
207
+ hideableColumns: hideableColumns,
208
+ keyProperty: keyProperty,
209
+ measureElement: measureElement,
210
+ onRowClick: onRowClick,
211
+ state: state,
212
+ canExpand: canExpand,
213
+ toggleExpand: toggleExpand,
214
+ expandRow: children,
215
+ toggleChecked: toggleChecked,
216
+ wrapperEnd: wrapperEnd,
217
+ wrapperStart: wrapperStart
178
218
  }, key);
179
219
  }), /*#__PURE__*/jsxs("div", {
180
220
  className: "flex-1 flex flex-nowrap",
181
221
  children: [/*#__PURE__*/jsxs("div", {
182
222
  className: wrapperStart,
183
- children: [checkableRows && /*#__PURE__*/jsx("div", {
223
+ children: [canExpand && /*#__PURE__*/jsx("div", {
224
+ className: "w-6"
225
+ }), checkableRows && /*#__PURE__*/jsx("div", {
184
226
  className: "w-6"
185
- }), (_state$start3 = state.start) === null || _state$start3 === void 0 ? void 0 : _state$start3.map(function (col) {
227
+ }), (_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.map(function (col) {
186
228
  return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
187
229
  })]
188
- }), (_state$cols3 = state.cols) === null || _state$cols3 === void 0 ? void 0 : _state$cols3.map(function (col) {
230
+ }), (_state$cols2 = state.cols) === null || _state$cols2 === void 0 ? void 0 : _state$cols2.map(function (col) {
189
231
  return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
190
232
  }), /*#__PURE__*/jsxs("div", {
191
233
  className: wrapperEnd,
192
- children: [(_state$end3 = state.end) === null || _state$end3 === void 0 ? void 0 : _state$end3.map(function (col) {
234
+ children: [(_state$end2 = state.end) === null || _state$end2 === void 0 ? void 0 : _state$end2.map(function (col) {
193
235
  return /*#__PURE__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
194
236
  }), hideableColumns && /*#__PURE__*/jsx("div", {
195
237
  className: "w-6"
196
238
  })]
197
239
  })]
198
240
  })]
199
- }), !loading && data.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
241
+ }), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsx(EmptyContent, {
200
242
  size: "sm",
201
243
  className: "bg-dimmed",
202
244
  message: t("datagrid.empty")
203
- })]
245
+ }))]
204
246
  })
205
247
  });
206
248
  };
@@ -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,165 @@
1
1
  'use client';
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
5
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
- import { useVirtualizer } from '@tanstack/react-virtual';
6
- import { useRef, useReducer, useCallback } from 'react';
6
+ import { groupBy, compareValues } from '@react-fabric/utilities';
7
+ import { useVirtualizer, defaultRangeExtractor } from '@tanstack/react-virtual';
8
+ import { useReducer, useRef, useMemo, useState, useCallback, useEffect } from '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 = useRef(null);
15
- var virtualizer = 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 = 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) {
32
- state.checked = data.map(function (item) {
33
- return item[keyProperty];
33
+ } else if (options.keyProperty) {
34
+ state.checked = state.data.map(function (item) {
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 = state.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 === "reset") {
56
+ state.data = action.data;
57
+ if (action.key) {
58
+ state.grouped = groupBy(state.data, action.key);
59
+ state.groups = Object.keys(state.grouped).sort(compareValues("asc")).map(function (group) {
60
+ return {
61
+ __GROUP__: true,
62
+ open: true,
63
+ key: group,
64
+ items: state.grouped[group],
65
+ itemCount: state.grouped[group].length
66
+ };
34
67
  });
68
+ state.items = state.groups.map(function (group) {
69
+ return [group].concat(_toConsumableArray(state.grouped[group.key]));
70
+ }).flat();
71
+ } else {
72
+ state.items = state.data;
35
73
  }
36
74
  }
37
- onCheckChanged === null || onCheckChanged === void 0 || onCheckChanged(state.checked);
38
75
  return _objectSpread(_objectSpread({}, state), {}, {
39
- allChecked: state.checked.length === data.length ? 1 : state.checked.length ? 2 : 0
76
+ allChecked: checkList.length === state.data.length ? 1 : state.checked.length ? 2 : 0
40
77
  });
41
78
  }, {
79
+ data: data,
80
+ items: [],
81
+ grouped: {},
82
+ groups: [],
42
83
  checked: [],
84
+ expanded: [],
43
85
  allChecked: 0
44
86
  }),
45
87
  _useReducer2 = _slicedToArray(_useReducer, 2),
46
88
  state = _useReducer2[0],
47
89
  dispatch = _useReducer2[1];
90
+ var activeStickyIndexRef = useRef(0);
91
+ var stickyIndexes = useMemo(function () {
92
+ return state.items.map(function (hit, idx) {
93
+ return "__GROUP__" in hit ? idx : undefined;
94
+ }).filter(Boolean);
95
+ }, [state.items]);
96
+ var isActiveSticky = function isActiveSticky(index) {
97
+ return activeStickyIndexRef.current === index;
98
+ };
99
+ var _useState = useState(false),
100
+ _useState2 = _slicedToArray(_useState, 2),
101
+ hasActiveSticky = _useState2[0],
102
+ setHasActiveSticky = _useState2[1];
103
+ var scrollerRef = useRef(null);
104
+ var virtualizer = useVirtualizer({
105
+ count: state.items.length,
106
+ getScrollElement: function getScrollElement() {
107
+ return scrollerRef.current;
108
+ },
109
+ estimateSize: function estimateSize() {
110
+ return 32;
111
+ },
112
+ rangeExtractor: useCallback(function (range) {
113
+ var _reverse$find;
114
+ activeStickyIndexRef.current = (_reverse$find = _toConsumableArray(stickyIndexes).reverse().find(function (index) {
115
+ return range.startIndex > index;
116
+ })) !== null && _reverse$find !== void 0 ? _reverse$find : 0;
117
+ setHasActiveSticky(range.startIndex !== activeStickyIndexRef.current);
118
+ var next = new Set([activeStickyIndexRef.current].concat(_toConsumableArray(defaultRangeExtractor(range))));
119
+ return _toConsumableArray(next);
120
+ }, [stickyIndexes])
121
+ });
48
122
  var virtualItems = virtualizer.getVirtualItems();
49
123
  var getData = useCallback(function (index) {
50
- return data[index];
51
- }, [data]);
124
+ return state.items[index];
125
+ }, [state.items]);
126
+ useEffect(function () {
127
+ dispatch({
128
+ type: "reset",
129
+ key: options.groupProperty,
130
+ data: data
131
+ });
132
+ }, [data, options.groupProperty]);
133
+ useEffect(function () {
134
+ var _options$checked;
135
+ dispatch({
136
+ type: "updateState",
137
+ checked: (_options$checked = options.checked) !== null && _options$checked !== void 0 ? _options$checked : []
138
+ });
139
+ }, [options.checked]);
52
140
  return {
53
141
  scrollerRef: scrollerRef,
54
142
  items: virtualItems,
55
143
  checkState: state,
56
144
  getData: getData,
145
+ virtualizer: virtualizer,
146
+ hasActiveSticky: hasActiveSticky,
147
+ isActiveSticky: isActiveSticky,
148
+ top: (_virtualizer$range = virtualizer.range) === null || _virtualizer$range === void 0 ? void 0 : _virtualizer$range.startIndex,
57
149
  totalSize: virtualizer.getTotalSize,
58
150
  measureElement: virtualizer.measureElement,
151
+ toggleGroupExpand: function toggleGroupExpand(key) {
152
+ return dispatch({
153
+ type: "groupExpand",
154
+ key: key
155
+ });
156
+ },
157
+ toggleExpand: function toggleExpand(key) {
158
+ return dispatch({
159
+ type: "expand",
160
+ key: key
161
+ });
162
+ },
59
163
  toggleChecked: function toggleChecked(key) {
60
164
  return dispatch({
61
165
  type: "check",
@@ -2,9 +2,11 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import { getBadgeProps, Icon, CoreIcons, Badge } from '@react-fabric/core';
5
+ import { isString, isEmpty } from '@react-fabric/utilities';
5
6
  import classNames from 'classnames';
6
- import { useMemo } from 'react';
7
- import { jsxs, jsx } from 'react/jsx-runtime';
7
+ import { useMemo, isValidElement } from 'react';
8
+ import { useTranslation } from 'react-i18next';
9
+ import { jsx, jsxs } from 'react/jsx-runtime';
8
10
 
9
11
  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; }
10
12
  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,26 +19,34 @@ var TreeNode = function TreeNode(_ref) {
17
19
  defaultLeafIcon = _ref.defaultLeafIcon,
18
20
  defaultNodeIcon = _ref.defaultNodeIcon,
19
21
  onToggle = _ref.onToggle,
22
+ onClick = _ref.onClick,
20
23
  onSelect = _ref.onSelect,
21
24
  onChecked = _ref.onChecked,
22
- children = _ref.children;
25
+ children = _ref.children,
26
+ leafClassName = _ref.leafClassName,
27
+ nodeClassName = _ref.nodeClassName;
28
+ var _useTranslation = useTranslation("data"),
29
+ t = _useTranslation.t;
23
30
  var badgeProps = useMemo(function () {
24
31
  return getBadgeProps(node.badge);
25
32
  }, [node.badge]);
26
33
  var filler = useMemo(function () {
27
- return node.lines.slice(noLines ? 1 : 0).map(function (line, idx) {
28
- return /*#__PURE__*/jsxs("svg", {
29
- viewBox: "0 0 24 24",
30
- className: "flex-initial w-6 fill-tint-200",
31
- children: [line === 0 && /*#__PURE__*/jsx("path", {
32
- d: ""
33
- }), !noLines && line === 1 && /*#__PURE__*/jsx("path", {
34
- d: "M7.45 26.1v-28.2h1.1v28.2h-1.1z"
35
- }), !noLines && line === 2 && /*#__PURE__*/jsx("path", {
36
- d: "M14.989 12.389l0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v14.1l0.161 0.389 0.389 0.161h6.6z"
37
- }), !noLines && line === 3 && /*#__PURE__*/jsx("path", {
38
- d: "M8.55 12.55h6.050l0.389-0.161 0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v28.2h1.1z"
39
- })]
34
+ return node.lines.slice(1).map(function (line, idx) {
35
+ return /*#__PURE__*/jsx("div", {
36
+ className: classNames("flex-initial self-stretch flex items-center w-6 relative", !noLines && line > 0 && "before:absolute before:top-0 before:start-[7px] before:bg-tint-200 before:min-h-[50%] before:w-[2px] before:scale-x-[.625]", !noLines && line !== 2 && "before:h-full"),
37
+ children: /*#__PURE__*/jsxs("svg", {
38
+ viewBox: "0 0 24 24",
39
+ className: "fill-tint-200 rtl:-scale-x-100",
40
+ children: [line === 0 && /*#__PURE__*/jsx("path", {
41
+ d: ""
42
+ }), !noLines && line === 1 && /*#__PURE__*/jsx("path", {
43
+ d: "M7.45 26.1v-28.2h1.1v28.2h-1.1z"
44
+ }), !noLines && line === 2 && /*#__PURE__*/jsx("path", {
45
+ d: "M14.989 12.389l0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v14.1l0.161 0.389 0.389 0.161h6.6z"
46
+ }), !noLines && line === 3 && /*#__PURE__*/jsx("path", {
47
+ d: "M8.55 12.55h6.050l0.389-0.161 0.161-0.389-0.161-0.389-0.389-0.161h-6.050v-13.55h-1.1v28.2h1.1z"
48
+ })]
49
+ })
40
50
  }, idx);
41
51
  });
42
52
  }, [noLines, node.lines]);
@@ -53,10 +63,16 @@ var TreeNode = function TreeNode(_ref) {
53
63
  return /*#__PURE__*/jsxs("div", {
54
64
  role: "treeitem",
55
65
  "aria-selected": node.selected,
56
- className: "flex flex-nowrap",
66
+ className: classNames("flex flex-nowrap items-center", node.className, node.leaf ? leafClassName : nodeClassName),
57
67
  "data-testid": node["data-testid"],
58
68
  "data-test-value": node["data-test-value"],
59
- children: [filler, !node.leaf && !node.childFiltered && /*#__PURE__*/jsx("div", {
69
+ children: [filler, node.loading && /*#__PURE__*/jsx("div", {
70
+ className: "flex-initial w-6",
71
+ children: /*#__PURE__*/jsx(Icon, {
72
+ icon: CoreIcons.spinner,
73
+ className: "animate-spin text-muted"
74
+ })
75
+ }), !node.leaf && !node.childFiltered && !node.loading && /*#__PURE__*/jsx("div", {
60
76
  className: "flex-initial w-6",
61
77
  children: /*#__PURE__*/jsx(Icon, {
62
78
  rtlFlip: true,
@@ -75,21 +91,22 @@ var TreeNode = function TreeNode(_ref) {
75
91
  icon: node.checked === 2 ? CoreIcons.checkboxInt : node.checked === 1 ? CoreIcons.checkboxOn : CoreIcons.checkboxOff,
76
92
  className: classNames(node.disabled ? "text-muted" : "text-primary-500 hover:text-primary-600")
77
93
  })
78
- }), /*#__PURE__*/jsxs("div", {
94
+ }), !node.empty && /*#__PURE__*/jsxs("div", {
79
95
  role: "none",
80
- className: classNames("group data-[selected]:bg-primary-100 flex flex-nowrap flex-1 items-center overflow-hidden select-none", node.childSelected && "font-medium", canSelect && "hover:bg-primary-50 cursor-pointer"),
96
+ className: classNames("group/tool data-[selected]:bg-primary-100 flex flex-nowrap flex-1 overflow-hidden select-none", node.childSelected && "font-medium", node.disabled && "text-muted opacity-65", !node.disabled && (canSelect || onClick) && "hover:bg-primary-50 cursor-pointer"),
81
97
  "data-selected": node.selected,
82
- onClick: function onClick() {
83
- return canSelect ? onSelect(node.id) : canCheck ? onChecked(node.id) : onToggle(node.id);
98
+ onClick: node.disabled ? undefined : function () {
99
+ onClick === null || onClick === void 0 || onClick(node.id, node.data);
100
+ canSelect ? onSelect(node.id) : canCheck ? onChecked(node.id) : onToggle(node.id);
84
101
  },
85
- children: [nodeIcon && /*#__PURE__*/jsx("div", {
86
- className: "flex-content w-6",
87
- children: /*#__PURE__*/jsx(Icon, {
102
+ children: [nodeIcon && /*#__PURE__*/jsxs("div", {
103
+ className: "flex-content w-6 self-center leading-none",
104
+ children: [/*#__PURE__*/isValidElement(nodeIcon) && nodeIcon, isString(nodeIcon) && /*#__PURE__*/jsx(Icon, {
88
105
  icon: nodeIcon,
89
106
  bg: node.iconBg,
90
107
  color: node.iconColor,
91
108
  rtlFlip: node.rtlFlip
92
- })
109
+ })]
93
110
  }), node.childSelected && !node.open && /*#__PURE__*/jsx("span", {
94
111
  className: " flex-content text-primary-500",
95
112
  children: "\u2022"
@@ -97,9 +114,12 @@ var TreeNode = function TreeNode(_ref) {
97
114
  role: "none",
98
115
  className: "flex-1 truncate",
99
116
  children: children
100
- }), node.badge && /*#__PURE__*/jsx(Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
117
+ }), !isEmpty(node.badge) && /*#__PURE__*/jsx(Badge, _objectSpread(_objectSpread({}, badgeProps), {}, {
101
118
  className: classNames("me-1 self-center flex-content bg-opacity-50", badgeProps.className)
102
119
  }))]
120
+ }), node.empty && /*#__PURE__*/jsx("div", {
121
+ className: "text-muted text-sm select-none",
122
+ children: t("tree.noItems")
103
123
  })]
104
124
  });
105
125
  };