@react-fabric/data 1.0.0-beta.3 → 1.0.0-beta.31

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 (83) hide show
  1. package/dist/cjs/checklist/CheckList.js +143 -0
  2. package/dist/cjs/histogram/Histogram.js +16 -5
  3. package/dist/cjs/hooks/usePagination.js +7 -4
  4. package/dist/cjs/hooks/useSelectableList.js +54 -0
  5. package/dist/cjs/index.js +2 -0
  6. package/dist/cjs/json/JsonViewer.js +30 -23
  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 +104 -66
  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 +143 -0
  21. package/dist/esm/histogram/Histogram.js +16 -5
  22. package/dist/esm/hooks/usePagination.js +7 -4
  23. package/dist/esm/hooks/useSelectableList.js +54 -0
  24. package/dist/esm/index.js +1 -0
  25. package/dist/esm/json/JsonViewer.js +31 -24
  26. package/dist/esm/table/BodyCell.js +38 -5
  27. package/dist/esm/table/BodyRow.js +107 -0
  28. package/dist/esm/table/CheckboxCell.js +1 -1
  29. package/dist/esm/table/HeaderCell.js +30 -37
  30. package/dist/esm/table/Table.js +106 -68
  31. package/dist/esm/table/useResizer.js +4 -4
  32. package/dist/esm/table/useVirtualTable.js +120 -19
  33. package/dist/esm/tree/TreeNode.js +46 -26
  34. package/dist/esm/tree/TreePanel.js +28 -10
  35. package/dist/esm/tree/useTree.js +98 -16
  36. package/dist/esm/tree/utils.js +20 -5
  37. package/dist/esm/virtual/Gallery.js +43 -29
  38. package/dist/esm/virtual/List.js +43 -31
  39. package/dist/types/checklist/CheckList.d.ts +30 -0
  40. package/dist/types/histogram/Histogram.d.ts +3 -3
  41. package/dist/types/hooks/useSelectableList.d.ts +28 -0
  42. package/dist/types/index.d.ts +2 -1
  43. package/dist/types/table/AddColumn.d.ts +2 -2
  44. package/dist/types/table/BodyCell.d.ts +4 -3
  45. package/dist/types/table/BodyRow.d.ts +20 -0
  46. package/dist/types/table/EmptyCell.d.ts +2 -2
  47. package/dist/types/table/HeaderCell.d.ts +2 -2
  48. package/dist/types/table/Table.d.ts +1 -1
  49. package/dist/types/table/types.d.ts +19 -8
  50. package/dist/types/table/useTableColumns.d.ts +6 -6
  51. package/dist/types/table/useVirtualTable.d.ts +20 -5
  52. package/dist/types/tree/TreeNode.d.ts +1 -1
  53. package/dist/types/tree/TreePanel.d.ts +1 -1
  54. package/dist/types/tree/types.d.ts +25 -5
  55. package/dist/types/tree/useTree.d.ts +2 -9
  56. package/dist/types/tree/utils.d.ts +4 -1
  57. package/dist/types/virtual/Gallery.d.ts +11 -3
  58. package/dist/types/virtual/List.d.ts +7 -3
  59. package/package.json +8 -7
  60. package/src/checklist/CheckList.tsx +222 -0
  61. package/src/histogram/Histogram.tsx +9 -2
  62. package/src/hooks/usePagination.tsx +13 -7
  63. package/src/hooks/useSelectableList.ts +94 -0
  64. package/src/index.ts +2 -1
  65. package/src/json/JsonViewer.tsx +31 -31
  66. package/src/table/AddColumn.tsx +2 -2
  67. package/src/table/BodyCell.tsx +34 -5
  68. package/src/table/BodyRow.tsx +143 -0
  69. package/src/table/CheckboxCell.tsx +1 -1
  70. package/src/table/EmptyCell.tsx +2 -2
  71. package/src/table/HeaderCell.tsx +27 -13
  72. package/src/table/Table.tsx +141 -73
  73. package/src/table/types.ts +22 -7
  74. package/src/table/useResizer.ts +5 -3
  75. package/src/table/useTableColumns.ts +7 -7
  76. package/src/table/useVirtualTable.ts +142 -27
  77. package/src/tree/TreeNode.tsx +90 -56
  78. package/src/tree/TreePanel.tsx +23 -3
  79. package/src/tree/types.ts +32 -4
  80. package/src/tree/useTree.ts +102 -23
  81. package/src/tree/utils.ts +23 -8
  82. package/src/virtual/Gallery.tsx +45 -34
  83. package/src/virtual/List.tsx +40 -27
@@ -0,0 +1,107 @@
1
+ 'use client';
2
+
3
+ import classNames from 'classnames';
4
+ import { BodyCell } from './BodyCell.js';
5
+ import { CheckboxCell } from './CheckboxCell.js';
6
+ import { Icon, CoreIcons } from '@react-fabric/core';
7
+ import { jsxs, jsx } from '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__*/jsxs("div", {
52
+ ref: measureElement,
53
+ "data-index": index,
54
+ className: index % 2 ? "bg-even" : "bg-odd",
55
+ children: [/*#__PURE__*/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", index % 2 ? "bg-even" : "bg-odd"),
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__*/jsxs("div", {
63
+ className: wrapperStart,
64
+ children: [!!canExpand && /*#__PURE__*/jsx("div", {
65
+ className: classNames("group font-medium w-6 flex flex-nowrap text-start py-1", !canExpand(data) && "pointer-events-none opacity-35"),
66
+ children: /*#__PURE__*/jsx(Icon, {
67
+ className: "p-1 text-tint-700 hover:text-primary-600",
68
+ icon: expanded ? CoreIcons.collapse : CoreIcons.expand,
69
+ onClick: function onClick(e) {
70
+ return [keyProperty && toggleExpand(data[keyProperty]), e.stopPropagation()];
71
+ }
72
+ })
73
+ }), checkableRows && keyProperty && /*#__PURE__*/jsx(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__*/jsx(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__*/jsx(BodyCell, {
87
+ column: col,
88
+ item: data,
89
+ index: idc
90
+ }, "".concat(String(rowKey), ":").concat(idc));
91
+ }), /*#__PURE__*/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__*/jsx(BodyCell, {
95
+ column: col,
96
+ item: data,
97
+ index: ide
98
+ }, "".concat(String(rowKey), ":").concat(ide));
99
+ }), hideableColumns && /*#__PURE__*/jsx("div", {
100
+ className: "w-6"
101
+ })]
102
+ })]
103
+ }), expanded && expandRow(data)]
104
+ });
105
+ };
106
+
107
+ export { BodyRow };
@@ -30,7 +30,7 @@ var CheckboxCell = function CheckboxCell(_ref) {
30
30
  var state = _ref.state,
31
31
  _onClick = _ref.onClick;
32
32
  return /*#__PURE__*/jsx("div", {
33
- className: "group font-medium border-e w-6 flex flex-nowrap text-start items-center",
33
+ className: "group font-medium border-e w-6 flex flex-nowrap text-start py-1",
34
34
  children: /*#__PURE__*/jsx(Icon, {
35
35
  icon: state === 2 ? CoreIcons.checkboxInt : state === 1 ? CoreIcons.checkboxOn : CoreIcons.checkboxOff,
36
36
  className: "p-1 text-tint-700 hover:text-primary-600",
@@ -1,44 +1,23 @@
1
1
  'use client';
2
2
 
3
- import { MenuItem, CoreIcons, Tooltip, Icon, DropdownTool, Menu } from '@react-fabric/core';
3
+ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
4
+ import { MenuItem, CoreIcons, Divider, Tooltip, Icon, DropdownTool, Menu } from '@react-fabric/core';
4
5
  import { useMemo, useCallback } from 'react';
5
6
  import { useTableContext } from './Context.js';
6
7
  import { COL_DEFAULT_WIDTH, COL_MIN_WIDTH, COL_MAX_WIDTH } from './types.js';
7
8
  import { jsx, jsxs } from '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 = useCallback(function () {
34
+ var handleSort = 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 = useMemo(function () {
62
41
  var ret = [];
63
42
  if (sortable) {
64
43
  ret.push( /*#__PURE__*/jsx(MenuItem, {
65
44
  label: "Sort ascending",
66
- icon: CoreIcons.sortAsc
45
+ icon: CoreIcons.sortAsc,
46
+ onClick: function onClick() {
47
+ return handleSort("asc");
48
+ }
67
49
  }, "sort-asc"), /*#__PURE__*/jsx(MenuItem, {
68
50
  label: "Sort descending",
69
- icon: CoreIcons.sortDesc
51
+ icon: 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__*/jsx(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__*/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 : COL_DEFAULT_WIDTH,
81
74
  minWidth: minWidth !== null && minWidth !== void 0 ? minWidth : COL_MIN_WIDTH,
82
75
  maxWidth: maxWidth !== null && maxWidth !== void 0 ? maxWidth : COL_MAX_WIDTH
83
76
  },
84
77
  children: [/*#__PURE__*/jsx(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__*/jsxs("div", {
88
81
  className: "flex-initial px-2 py-1 text-sm truncate sticky start-0",
89
82
  children: [icon && /*#__PURE__*/jsx(Icon, {
@@ -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,25 @@ 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
+ onScroll = _ref.onScroll,
31
41
  onRowClick = _ref.onRowClick,
32
42
  onCheckedChanged = _ref.onCheckedChanged;
33
43
  var _useTranslation = useTranslation("data"),
@@ -38,14 +48,25 @@ var Table = function Table(_ref) {
38
48
  var _useTableColumns = useTableColumns(columns),
39
49
  state = _useTableColumns.state,
40
50
  onHide = _useTableColumns.onHide;
41
- var _useVirtualTable = useVirtualTable(data, keyProperty, fireCheckChanged),
51
+ var _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 = useRef(null);
51
72
  var wrapperStart = useMemo(function () {
@@ -54,47 +75,62 @@ var Table = function Table(_ref) {
54
75
  var wrapperEnd = useMemo(function () {
55
76
  return "bg-inherit sticky end-0 flex flex-nowrap z-1 border-s -ms-px";
56
77
  }, []);
78
+ useLayoutEffect(function () {
79
+ setTimeout(function () {
80
+ initialScroll && virtualizer.scrollToIndex(initialScroll, {
81
+ align: "start"
82
+ });
83
+ }, 100);
84
+ }, []);
57
85
  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
+ useEffect(function () {
110
+ var handle = 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__*/jsx(TableProvider, {
87
119
  children: /*#__PURE__*/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__*/jsxs("div", {
127
+ "data-ref": "tableHeader",
94
128
  className: "bg-base font-medium sticky top-0 area-head border-b select-none flex flex-nowrap z-2",
95
129
  children: [/*#__PURE__*/jsxs("div", {
96
130
  className: wrapperStart,
97
- children: [checkableRows && /*#__PURE__*/jsx(CheckboxCell, {
131
+ children: [canExpand && /*#__PURE__*/jsx("div", {
132
+ className: "w-6"
133
+ }), checkableRows && /*#__PURE__*/jsx(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__*/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__*/jsxs("div", {
176
+ return "__GROUP__" in data ? /*#__PURE__*/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", isActiveSticky(index) && "sticky top-8 z-30"),
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 && !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__*/jsxs("div", {
150
- className: wrapperStart,
151
- children: [checkableRows && /*#__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"
184
+ children: [/*#__PURE__*/jsx(Icon, {
185
+ rtlFlip: true,
186
+ icon: data.open ? CoreIcons.chevronDown : CoreIcons.chevronRight
187
+ }), (_groupRenderer = groupRenderer === null || groupRenderer === void 0 ? void 0 : groupRenderer(data)) !== null && _groupRenderer !== void 0 ? _groupRenderer : /*#__PURE__*/jsxs("div", {
188
+ className: "flex gap-1 items-center",
189
+ children: [/*#__PURE__*/jsx("span", {
190
+ children: data.key
191
+ }), /*#__PURE__*/jsxs("span", {
192
+ className: "text-sm",
193
+ children: ["(", data.itemCount, ")"]
176
194
  })]
177
195
  })]
196
+ }, key) : /*#__PURE__*/jsx(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__*/jsxs("div", {
180
216
  className: "flex-1 flex flex-nowrap",
181
217
  children: [/*#__PURE__*/jsxs("div", {
182
218
  className: wrapperStart,
183
- children: [checkableRows && /*#__PURE__*/jsx("div", {
219
+ children: [canExpand && /*#__PURE__*/jsx("div", {
220
+ className: "w-6"
221
+ }), checkableRows && /*#__PURE__*/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__*/jsx(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__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
190
228
  }), /*#__PURE__*/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__*/jsx(EmptyCell, _objectSpread({}, col), String(col.id));
194
232
  }), hideableColumns && /*#__PURE__*/jsx("div", {
195
233
  className: "w-6"
196
234
  })]
197
235
  })]
198
236
  })]
199
- }), !loading && data.length === 0 && /*#__PURE__*/jsx(EmptyContent, {
237
+ }), !loading && data.length === 0 && (emptyDisplay !== null && emptyDisplay !== void 0 ? emptyDisplay : /*#__PURE__*/jsx(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");