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

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 (109) 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 +48 -16
  4. package/dist/cjs/histogram/Histogram.js +48 -10
  5. package/dist/cjs/hooks/useFilteredList.js +20 -0
  6. package/dist/cjs/hooks/usePagination.js +27 -4
  7. package/dist/cjs/hooks/useSelectableList.js +29 -0
  8. package/dist/cjs/i18n/ar.json.js +8 -1
  9. package/dist/cjs/i18n/en.json.js +8 -1
  10. package/dist/cjs/json/JsonViewer.js +67 -27
  11. package/dist/cjs/pagination/Pagination.js +10 -0
  12. package/dist/cjs/table/AddColumn.js +1 -1
  13. package/dist/cjs/table/BodyCell.js +38 -5
  14. package/dist/cjs/table/BodyRow.js +107 -0
  15. package/dist/cjs/table/CheckboxCell.js +1 -1
  16. package/dist/cjs/table/ColumnFilters.js +97 -0
  17. package/dist/cjs/table/HeaderCell.js +70 -37
  18. package/dist/cjs/table/Table.js +113 -71
  19. package/dist/cjs/table/types.js +29 -0
  20. package/dist/cjs/table/useResizer.js +4 -4
  21. package/dist/cjs/table/useVirtualTable.js +122 -18
  22. package/dist/cjs/tree/TreeNode.js +45 -25
  23. package/dist/cjs/tree/TreePanel.js +28 -10
  24. package/dist/cjs/tree/useTree.js +97 -15
  25. package/dist/cjs/tree/utils.js +20 -5
  26. package/dist/cjs/virtual/Gallery.js +84 -35
  27. package/dist/cjs/virtual/List.js +82 -32
  28. package/dist/esm/checklist/CheckList.js +50 -18
  29. package/dist/esm/histogram/Histogram.js +49 -11
  30. package/dist/esm/hooks/useFilteredList.js +20 -0
  31. package/dist/esm/hooks/usePagination.js +27 -4
  32. package/dist/esm/hooks/useSelectableList.js +29 -0
  33. package/dist/esm/i18n/ar.json.js +8 -2
  34. package/dist/esm/i18n/en.json.js +8 -2
  35. package/dist/esm/json/JsonViewer.js +68 -28
  36. package/dist/esm/pagination/Pagination.js +10 -0
  37. package/dist/esm/table/AddColumn.js +1 -1
  38. package/dist/esm/table/BodyCell.js +38 -5
  39. package/dist/esm/table/BodyRow.js +107 -0
  40. package/dist/esm/table/CheckboxCell.js +1 -1
  41. package/dist/esm/table/ColumnFilters.js +97 -0
  42. package/dist/esm/table/HeaderCell.js +71 -38
  43. package/dist/esm/table/Table.js +115 -73
  44. package/dist/esm/table/types.js +29 -0
  45. package/dist/esm/table/useResizer.js +4 -4
  46. package/dist/esm/table/useVirtualTable.js +124 -20
  47. package/dist/esm/tree/TreeNode.js +47 -27
  48. package/dist/esm/tree/TreePanel.js +28 -10
  49. package/dist/esm/tree/useTree.js +99 -17
  50. package/dist/esm/tree/utils.js +20 -5
  51. package/dist/esm/virtual/Gallery.js +84 -35
  52. package/dist/esm/virtual/List.js +82 -32
  53. package/dist/types/checklist/CheckList.d.ts +24 -2
  54. package/dist/types/histogram/Histogram.d.ts +31 -4
  55. package/dist/types/hooks/useFilteredList.d.ts +20 -2
  56. package/dist/types/hooks/usePagination.d.ts +19 -0
  57. package/dist/types/hooks/useSelectableList.d.ts +29 -0
  58. package/dist/types/index.d.ts +1 -1
  59. package/dist/types/json/JsonViewer.d.ts +27 -2
  60. package/dist/types/pagination/Pagination.d.ts +10 -1
  61. package/dist/types/table/AddColumn.d.ts +2 -2
  62. package/dist/types/table/BodyCell.d.ts +4 -3
  63. package/dist/types/table/BodyRow.d.ts +20 -0
  64. package/dist/types/table/ColumnFilters.d.ts +9 -0
  65. package/dist/types/table/EmptyCell.d.ts +2 -2
  66. package/dist/types/table/HeaderCell.d.ts +2 -2
  67. package/dist/types/table/Table.d.ts +14 -1
  68. package/dist/types/table/types.d.ts +48 -7
  69. package/dist/types/table/useTableColumns.d.ts +6 -6
  70. package/dist/types/table/useVirtualTable.d.ts +23 -8
  71. package/dist/types/tree/TreeNode.d.ts +1 -1
  72. package/dist/types/tree/TreePanel.d.ts +42 -1
  73. package/dist/types/tree/types.d.ts +25 -5
  74. package/dist/types/tree/useTree.d.ts +3 -10
  75. package/dist/types/tree/utils.d.ts +4 -1
  76. package/dist/types/virtual/Gallery.d.ts +44 -4
  77. package/dist/types/virtual/List.d.ts +44 -4
  78. package/package.json +13 -10
  79. package/src/checklist/CheckList.tsx +103 -77
  80. package/src/histogram/Histogram.tsx +45 -11
  81. package/src/hooks/useFilteredList.tsx +19 -0
  82. package/src/hooks/usePagination.tsx +32 -7
  83. package/src/hooks/useSelectableList.ts +29 -0
  84. package/src/i18n/ar.json +5 -0
  85. package/src/i18n/en.json +5 -0
  86. package/src/index.ts +1 -1
  87. package/src/json/JsonViewer.tsx +71 -35
  88. package/src/pagination/Pagination.tsx +10 -0
  89. package/src/table/AddColumn.tsx +3 -3
  90. package/src/table/BodyCell.tsx +34 -5
  91. package/src/table/BodyRow.tsx +143 -0
  92. package/src/table/CheckboxCell.tsx +1 -1
  93. package/src/table/ColumnFilters.tsx +105 -0
  94. package/src/table/EmptyCell.tsx +2 -2
  95. package/src/table/HeaderCell.tsx +72 -14
  96. package/src/table/Table.tsx +177 -77
  97. package/src/table/types.ts +52 -6
  98. package/src/table/useResizer.ts +5 -3
  99. package/src/table/useTableColumns.ts +7 -7
  100. package/src/table/useVirtualTable.ts +146 -24
  101. package/src/tree/TreeNode.tsx +98 -56
  102. package/src/tree/TreePanel.tsx +64 -3
  103. package/src/tree/types.ts +32 -4
  104. package/src/tree/useTree.ts +109 -26
  105. package/src/tree/utils.ts +23 -8
  106. package/src/virtual/Gallery.tsx +96 -42
  107. package/src/virtual/List.tsx +82 -33
  108. package/dist/cjs/histogram/Histogram.module.css +0 -1
  109. package/dist/esm/histogram/Histogram.module.css +0 -1
@@ -1,6 +1,8 @@
1
1
  'use client';
2
2
 
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
6
  import { useEffectDebugger, useDebounce, Skeleton } from '@react-fabric/core';
5
7
  import { debounce } from '@react-fabric/utilities';
6
8
  import { useVirtualizer } from '@tanstack/react-virtual';
@@ -10,6 +12,9 @@ import { useDeferredValue, useMemo, useRef, useState, useEffect, useCallback, us
10
12
  import { Scroller } from './Scroller.js';
11
13
  import { jsx, jsxs } from 'react/jsx-runtime';
12
14
 
15
+ var _excluded = ["items", "children", "columns", "fullWidth", "maxWidth", "minWidth", "total", "padding", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "galleryRef"];
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
18
  var createItemList = memoizeOne(function (items) {
14
19
  return items;
15
20
  });
@@ -18,6 +23,11 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
18
23
  var items = _ref.items,
19
24
  children = _ref.children,
20
25
  columns = _ref.columns,
26
+ fullWidth = _ref.fullWidth,
27
+ maxWidth = _ref.maxWidth,
28
+ minWidth = _ref.minWidth,
29
+ _ref$total = _ref.total,
30
+ total = _ref$total === void 0 ? 0 : _ref$total,
21
31
  _ref$padding = _ref.padding,
22
32
  padding = _ref$padding === void 0 ? "md" : _ref$padding,
23
33
  _ref$defaultHeight = _ref.defaultHeight,
@@ -29,16 +39,17 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
29
39
  loading = _ref.loading,
30
40
  onLoadMore = _ref.onLoadMore,
31
41
  onScroll = _ref.onScroll,
32
- galleryRef = _ref.galleryRef;
42
+ galleryRef = _ref.galleryRef,
43
+ aria = _objectWithoutProperties(_ref, _excluded);
33
44
  var count = useDeferredValue(items.length);
34
45
  var extraSize = useMemo(function () {
35
- return onLoadMore ? 64 : 0;
46
+ return onLoadMore ? 8 : 0;
36
47
  }, [onLoadMore]);
37
- var itemList = createItemList(items.map(function (item, idx) {
48
+ var itemList = createItemList(items.map(function (item, index) {
38
49
  return {
39
- index: idx,
40
- data: item,
41
- isLast: idx + 1 === items.length
50
+ index: index,
51
+ item: item,
52
+ isLast: index + 1 === items.length
42
53
  };
43
54
  }));
44
55
  var scrollerRef = useRef(null);
@@ -55,8 +66,9 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
55
66
  if (scrollerRef.current) {
56
67
  var el = scrollerRef.current;
57
68
  var handler = function handler() {
58
- var _el$offsetWidth;
59
- setColumnCount(columns !== null && columns !== void 0 ? columns : Math.max(1, Math.floor((((_el$offsetWidth = el === null || el === void 0 ? void 0 : el.offsetWidth) !== null && _el$offsetWidth !== void 0 ? _el$offsetWidth : 800) - 32) / width)));
69
+ var _getComputedStyle$pad, _el$firstElementChild, _el$offsetWidth;
70
+ var pad = parseInt((_getComputedStyle$pad = getComputedStyle((_el$firstElementChild = el.firstElementChild) === null || _el$firstElementChild === void 0 ? void 0 : _el$firstElementChild.firstElementChild).padding) !== null && _getComputedStyle$pad !== void 0 ? _getComputedStyle$pad : 8);
71
+ setColumnCount(columns !== null && columns !== void 0 ? columns : Math.max(1, Math.floor((((_el$offsetWidth = el === null || el === void 0 ? void 0 : el.offsetWidth) !== null && _el$offsetWidth !== void 0 ? _el$offsetWidth : 800) - 32 - (isNaN(pad) ? 8 : pad) * 2) / width)));
60
72
  };
61
73
  var ob = new ResizeObserver(handler);
62
74
  handler();
@@ -74,7 +86,8 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
74
86
  },
75
87
  estimateSize: function estimateSize() {
76
88
  return height;
77
- }
89
+ },
90
+ overscan: 2
78
91
  });
79
92
  var virtualItems = virtualizer.getVirtualItems();
80
93
  var currentIndex = useRef(0);
@@ -112,26 +125,25 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
112
125
  setScrollActive(calculateActiveScroll());
113
126
  }, [count, calculateActiveScroll]);
114
127
  useEffect(function () {
115
- var db = debounce(function () {
116
- var lastItem = virtualItems === null || virtualItems === void 0 ? void 0 : virtualItems.slice(-1).pop();
117
- if (lastItem && !loading && lastItem.index * columnCount + columnCount >= count - 1) onLoadMore === null || onLoadMore === void 0 || onLoadMore();
118
- });
119
- db();
120
- return function () {
121
- return db.cancel();
122
- };
123
- }, [onLoadMore, loading, itemList, virtualItems, count, columnCount]);
124
- useEffect(function () {
125
- var _virtualItems$2;
126
- var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
127
- if (onLoadMore && firstItem !== undefined && items[firstItem * columnCount] === null) {
128
+ if (onLoadMore) {
129
+ var _virtualItems$2, _virtualItems$slice$p;
130
+ var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
131
+ var lastItem = virtualItems === null || virtualItems === void 0 || (_virtualItems$slice$p = virtualItems.slice(-1).pop()) === null || _virtualItems$slice$p === void 0 ? void 0 : _virtualItems$slice$p.index;
132
+ var firstIndex = firstItem * columnCount;
133
+ var lastIndex = (lastItem !== null && lastItem !== void 0 ? lastItem : 0) * columnCount + columnCount;
134
+ var canLoadPrevPage = firstItem !== undefined && items[firstIndex] === null;
135
+ var canLoadNextPage = lastItem !== undefined && lastIndex >= count - 1 && count < total;
128
136
  var db = debounce(onLoadMore);
129
- db(firstItem * columnCount);
137
+ if (canLoadPrevPage) {
138
+ db(firstIndex);
139
+ } else if (!loading && canLoadNextPage) {
140
+ db(lastIndex + 1);
141
+ }
130
142
  return function () {
131
143
  return db.cancel();
132
144
  };
133
145
  }
134
- }, [onLoadMore, items, columnCount, virtualItems, count]);
146
+ }, [onLoadMore, virtualItems]);
135
147
  useLayoutEffect(function () {
136
148
  setTimeout(function () {
137
149
  initialScroll && virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
@@ -143,14 +155,14 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
143
155
  return {
144
156
  scrollToItem: function scrollToItem(index) {
145
157
  virtualizer.scrollToIndex(Math.floor(index / columnCount), {
146
- align: "start"
158
+ align: "auto"
147
159
  });
148
160
  },
149
161
  hilight: function hilight(index) {
150
162
  var _scrollerRef$current2;
151
163
  (_scrollerRef$current2 = scrollerRef.current) === null || _scrollerRef$current2 === void 0 || (_scrollerRef$current2 = _scrollerRef$current2.querySelector(".hilight")) === null || _scrollerRef$current2 === void 0 || _scrollerRef$current2.classList.remove("hilight", "ring-1");
152
164
  virtualizer.scrollToIndex(Math.floor(index / columnCount), {
153
- align: "start"
165
+ align: "auto"
154
166
  });
155
167
  setTimeout(function () {
156
168
  var _scrollerRef$current3;
@@ -163,17 +175,22 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
163
175
  }
164
176
  };
165
177
  }, [virtualizer, columnCount]);
166
- return /*#__PURE__*/jsx("div", {
178
+ return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
167
179
  ref: scrollerRef,
168
180
  onScroll: handleScroll,
169
- className: classNames("area-content bg-base overflow-auto contain-strict"),
181
+ className: classNames("area-content bg-base overflow-auto")
182
+ }, aria), {}, {
170
183
  children: /*#__PURE__*/jsxs("div", {
171
- className: classNames("inline-flex flex-nowrap gap-2 justify-center min-h-full min-w-full"),
184
+ className: classNames("flex flex-nowrap justify-center gap-2 min-h-full"),
172
185
  children: [/*#__PURE__*/jsx("div", {
173
- className: classNames("box-content", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
186
+ className: classNames("box-content", fullWidth && "flex-1", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
187
+ style: {
188
+ minWidth: minWidth,
189
+ maxWidth: maxWidth
190
+ },
174
191
  children: /*#__PURE__*/jsxs("div", {
175
192
  style: {
176
- height: virtualizer.getTotalSize()
193
+ height: virtualizer.getTotalSize() + extraSize
177
194
  },
178
195
  children: [/*#__PURE__*/jsx("div", {
179
196
  style: {
@@ -181,12 +198,11 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
181
198
  }
182
199
  }), virtualItems.map(function (_ref3) {
183
200
  var key = _ref3.key,
184
- index = _ref3.index,
185
- measureElement = _ref3.measureElement;
201
+ index = _ref3.index;
186
202
  return /*#__PURE__*/jsx("div", {
187
203
  className: "flex",
188
204
  "data-index": index,
189
- ref: measureElement,
205
+ ref: virtualizer.measureElement,
190
206
  children: columnMap.map(function (col) {
191
207
  return /*#__PURE__*/jsx("div", {
192
208
  "data-index": index * columnCount + col,
@@ -220,10 +236,43 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
220
236
  })
221
237
  })]
222
238
  })
223
- });
239
+ }));
224
240
  };
225
241
  _VirtualGallery.displayName = "VirtualGallery";
226
242
  var GenericMemo = memo;
243
+
244
+ /**
245
+ * VirtualGallery component provides a virtualized gallery view for displaying a large list of items efficiently.
246
+ * It supports features like fixed columns, loading states, and customizable item rendering.
247
+ * The component uses virtualization to render only the visible items, improving performance for large datasets.
248
+ * It also provides a scroller for easy navigation through the items.
249
+ *
250
+ * @param {VirtualGalleryProps<T>} props - The properties for the VirtualGallery component.
251
+ * @returns {JSX.Element} The rendered VirtualGallery component.
252
+ *
253
+ * @example
254
+ * ```jsx
255
+ * <VirtualGallery
256
+ * items={items}
257
+ * columns={3}
258
+ * defaultHeight={100}
259
+ * defaultWidth={100}
260
+ * fullWidth={true}
261
+ * onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
262
+ * onScroll={(top) => console.log("Scrolled to top:", top)}
263
+ * >
264
+ * {({ item, index, isLast }) => (
265
+ * <div className="gallery-item" key={item.id}>
266
+ * <img src={item.image} alt={item.label} />
267
+ * <p>{item.label}</p>
268
+ * </div>
269
+ * )}
270
+ * </VirtualGallery>
271
+ * ```
272
+ *
273
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-virtualgallery--docs}
274
+ * @see {@link https://tanstack.com/docs/react-virtual/latest/overview}
275
+ */
227
276
  var VirtualGallery = GenericMemo(_VirtualGallery);
228
277
 
229
278
  export { VirtualGallery };
@@ -1,6 +1,8 @@
1
1
  'use client';
2
2
 
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
4
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
6
  import { useDebounce, Skeleton } from '@react-fabric/core';
5
7
  import { debounce } from '@react-fabric/utilities';
6
8
  import { useVirtualizer } from '@tanstack/react-virtual';
@@ -10,14 +12,21 @@ import { useDeferredValue, useMemo, useRef, useEffect, useCallback, useState, us
10
12
  import { Scroller } from './Scroller.js';
11
13
  import { jsx, jsxs } from 'react/jsx-runtime';
12
14
 
15
+ var _excluded = ["items", "total", "children", "fullWidth", "maxWidth", "minWidth", "padding", "orientation", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "listRef"];
16
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
18
  var createItemList = memoizeOne(function (items) {
14
19
  return items;
15
20
  });
16
21
  var _VirtualList = function _VirtualList(_ref) {
17
22
  var _virtualItems$3, _virtualItems$4;
18
23
  var items = _ref.items,
24
+ _ref$total = _ref.total,
25
+ total = _ref$total === void 0 ? 0 : _ref$total,
19
26
  children = _ref.children,
20
27
  fullWidth = _ref.fullWidth,
28
+ maxWidth = _ref.maxWidth,
29
+ minWidth = _ref.minWidth,
21
30
  _ref$padding = _ref.padding,
22
31
  padding = _ref$padding === void 0 ? "md" : _ref$padding,
23
32
  _ref$orientation = _ref.orientation,
@@ -31,21 +40,23 @@ var _VirtualList = function _VirtualList(_ref) {
31
40
  loading = _ref.loading,
32
41
  onLoadMore = _ref.onLoadMore,
33
42
  onScroll = _ref.onScroll,
34
- listRef = _ref.listRef;
43
+ listRef = _ref.listRef,
44
+ aria = _objectWithoutProperties(_ref, _excluded);
35
45
  var count = useDeferredValue(items.length);
36
46
  var extraSize = useMemo(function () {
37
- return onLoadMore ? 64 : 0;
47
+ return onLoadMore ? 8 : 0;
38
48
  }, [onLoadMore]);
39
- var itemList = createItemList(items.map(function (item, idx) {
49
+ var itemList = createItemList(items.map(function (item, index) {
40
50
  return {
41
- index: idx,
42
- data: item,
43
- isLast: idx + 1 === items.length
51
+ index: index,
52
+ item: item,
53
+ isLast: index + 1 === items.length
44
54
  };
45
55
  }));
46
56
  var scrollerRef = useRef(null);
47
57
  var virtualizer = useVirtualizer({
48
58
  count: count,
59
+ overscan: 2,
49
60
  horizontal: orientation === "horizontal",
50
61
  getScrollElement: function getScrollElement() {
51
62
  return scrollerRef.current;
@@ -103,26 +114,23 @@ var _VirtualList = function _VirtualList(_ref) {
103
114
  setScrollActive(calculateActiveScroll());
104
115
  }, [itemList, calculateActiveScroll]);
105
116
  useEffect(function () {
106
- var db = debounce(function () {
107
- var lastItem = virtualItems === null || virtualItems === void 0 ? void 0 : virtualItems.slice(-1).pop();
108
- if (lastItem && !loading && lastItem.index === count - 1) onLoadMore === null || onLoadMore === void 0 || onLoadMore();
109
- });
110
- db();
111
- return function () {
112
- return db.cancel();
113
- };
114
- }, [onLoadMore, loading, itemList, virtualItems, count]);
115
- useEffect(function () {
116
- var _virtualItems$2;
117
- var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
118
- if (onLoadMore && firstItem !== undefined && items[firstItem] === null) {
117
+ if (onLoadMore) {
118
+ var _virtualItems$2, _virtualItems$slice$p;
119
+ var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
120
+ var lastItem = virtualItems === null || virtualItems === void 0 || (_virtualItems$slice$p = virtualItems.slice(-1).pop()) === null || _virtualItems$slice$p === void 0 ? void 0 : _virtualItems$slice$p.index;
121
+ var canLoadPrevPage = firstItem !== undefined && items[firstItem] === null;
122
+ var canLoadNextPage = lastItem !== undefined && lastItem === count - 1 && count < total;
119
123
  var db = debounce(onLoadMore);
120
- db(firstItem);
124
+ if (canLoadPrevPage) {
125
+ db(firstItem);
126
+ } else if (!loading && canLoadNextPage) {
127
+ db(lastItem + 1);
128
+ }
121
129
  return function () {
122
130
  return db.cancel();
123
131
  };
124
132
  }
125
- }, [onLoadMore, items, virtualItems, count]);
133
+ }, [onLoadMore, virtualItems]);
126
134
  useLayoutEffect(function () {
127
135
  setTimeout(function () {
128
136
  initialScroll && virtualizer.scrollToIndex(initialScroll, {
@@ -134,14 +142,14 @@ var _VirtualList = function _VirtualList(_ref) {
134
142
  return {
135
143
  scrollToItem: function scrollToItem(index) {
136
144
  virtualizer.scrollToIndex(index, {
137
- align: "start"
145
+ align: "auto"
138
146
  });
139
147
  },
140
148
  hilight: function hilight(index) {
141
149
  var _scrollerRef$current2;
142
150
  (_scrollerRef$current2 = scrollerRef.current) === null || _scrollerRef$current2 === void 0 || (_scrollerRef$current2 = _scrollerRef$current2.querySelector(".hilight")) === null || _scrollerRef$current2 === void 0 || _scrollerRef$current2.classList.remove("hilight", "ring-1");
143
151
  virtualizer.scrollToIndex(Math.floor(index), {
144
- align: "start"
152
+ align: "auto"
145
153
  });
146
154
  setTimeout(function () {
147
155
  var _scrollerRef$current3;
@@ -154,19 +162,24 @@ var _VirtualList = function _VirtualList(_ref) {
154
162
  }
155
163
  };
156
164
  }, [virtualizer]);
157
- return /*#__PURE__*/jsx("div", {
165
+ return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
158
166
  ref: scrollerRef,
159
167
  onScroll: handleScroll,
160
- className: classNames("area-content bg-base overflow-auto contain-strict"),
168
+ className: classNames("area-content bg-base overflow-auto")
169
+ }, aria), {}, {
161
170
  children: /*#__PURE__*/jsxs("div", {
162
- className: classNames("inline-flex flex-nowrap gap-2 justify-center min-h-full min-w-full", orientation === "horizontal" && "flex-col"),
171
+ className: classNames("flex flex-nowrap gap-2 justify-center min-h-full min-w-full", orientation === "horizontal" && "flex-col"),
163
172
  children: [/*#__PURE__*/jsxs("div", {
164
173
  className: classNames("box-content inline-flex flex-nowrap", orientation === "vertical" && "flex-col", orientation === "horizontal" && "flex-row", fullWidth && "flex-1", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
174
+ style: {
175
+ minWidth: minWidth,
176
+ maxWidth: maxWidth
177
+ },
165
178
  children: [/*#__PURE__*/jsxs("div", {
166
179
  style: orientation === "vertical" ? {
167
- height: virtualizer.getTotalSize()
180
+ height: virtualizer.getTotalSize() + extraSize
168
181
  } : {
169
- width: virtualizer.getTotalSize()
182
+ width: virtualizer.getTotalSize() + extraSize
170
183
  },
171
184
  children: [/*#__PURE__*/jsx("div", {
172
185
  style: orientation === "vertical" ? {
@@ -185,9 +198,9 @@ var _VirtualList = function _VirtualList(_ref) {
185
198
  children: children(itemList[index])
186
199
  }, key);
187
200
  })]
188
- }), onLoadMore && /*#__PURE__*/jsx("div", {
189
- className: orientation === "horizontal" ? "min-w-16" : "h-16",
190
- children: loading && /*#__PURE__*/jsx(Skeleton, {})
201
+ }), loading && /*#__PURE__*/jsx("div", {
202
+ className: orientation === "horizontal" ? "min-w-16" : "",
203
+ children: /*#__PURE__*/jsx(Skeleton, {})
191
204
  })]
192
205
  }), !hideScroller && /*#__PURE__*/jsx("div", {
193
206
  className: classNames(orientation === "vertical" && "self-end sticky bottom-2", orientation === "horizontal" && "self-end sticky end-2"),
@@ -209,10 +222,47 @@ var _VirtualList = function _VirtualList(_ref) {
209
222
  })
210
223
  })]
211
224
  })
212
- });
225
+ }));
213
226
  };
214
227
  _VirtualList.displayName = "VirtualList";
215
228
  var GenericMemo = memo;
229
+
230
+ /**
231
+ * VirtualList component for rendering large lists efficiently using virtualization.
232
+ * It supports horizontal and vertical orientations, custom item heights and widths,
233
+ * and provides a scroller for navigating through the list.
234
+ * It also supports loading more items on scroll and provides a way to hilight items.
235
+ * It can be used with a ref to control scrolling and hilighting of items.
236
+ *
237
+ * @param {VirtualListProps<T>} props - The properties for the VirtualList component.
238
+ * @returns {JSX.Element} The rendered VirtualList component.
239
+ * @template T - The type of items in the list, extending AnyObject.
240
+ *
241
+ * @example
242
+ * ```jsx
243
+ * <VirtualList
244
+ * items={items}
245
+ * children={({ item, index, isLast }) => (
246
+ * <div key={index} className="item">
247
+ * {item.label}
248
+ * </div>
249
+ * )}
250
+ * fullWidth={true}
251
+ * orientation="vertical"
252
+ * defaultHeight={50}
253
+ * onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
254
+ * onScroll={(top) => console.log("Scrolled to top:", top)}
255
+ * listRef={virtualListRef}
256
+ * >
257
+ * {({ item, index, isLast }) => (
258
+ * <div className="gallery-item" key={item.id}>
259
+ * <img src={item.image} alt={item.label} />
260
+ * <p>{item.label}</p>
261
+ * </div>
262
+ * )}
263
+ * </VirtualList>
264
+ * ```
265
+ */
216
266
  var VirtualList = GenericMemo(_VirtualList);
217
267
 
218
268
  export { VirtualList };
@@ -1,4 +1,4 @@
1
- import { type BadgeType } from "@react-fabric/core/dist/types/types";
1
+ import { type BadgeType, type TestProps } from "@react-fabric/core/dist/types/types";
2
2
  import { type FC } from "react";
3
3
  import { type SelectableProps } from "../hooks/useSelectableList";
4
4
  export interface CheckListItem extends KeyValue {
@@ -8,7 +8,7 @@ export interface CheckListItem extends KeyValue {
8
8
  badge?: BadgeType;
9
9
  isDisabled?: boolean;
10
10
  }
11
- export interface CheckListProps extends SelectableProps {
11
+ export interface CheckListProps extends SelectableProps, TestProps {
12
12
  /**
13
13
  * list items
14
14
  */
@@ -27,4 +27,26 @@ export interface CheckListProps extends SelectableProps {
27
27
  emptyMessage?: string;
28
28
  sortItems?: boolean;
29
29
  }
30
+ /**
31
+ * CheckList component to display a list of selectable items with checkboxes.
32
+ * It supports selection, deselection, and allows for negative selections.
33
+ *
34
+ * @param {CheckListProps} props - The properties for the CheckList component.
35
+ * @returns {JSX.Element} The rendered CheckList component.
36
+ *
37
+ * @example
38
+ * ```jsx
39
+ * <CheckList
40
+ * items={[
41
+ * { id: "1", label: "Item 1", icon: "icon1" },
42
+ * { id: "2", label: "Item 2", icon: "icon2", badge: { text: "New" } },
43
+ * ]}
44
+ * maxCount={5}
45
+ * allowNegative={true}
46
+ * emptyMessage="No items available"
47
+ * onChange={(selectedItems) => console.log(selectedItems)}
48
+ * onClick={(itemId, isNegative) => console.log(itemId, isNegative)}
49
+ * />
50
+ * ```
51
+ */
30
52
  export declare const CheckList: FC<CheckListProps>;
@@ -1,5 +1,4 @@
1
- /// <reference types="react" />
2
- import { type ColorType, type PaletteType } from "@react-fabric/core/dist/types/types";
1
+ import { type ColorType, type PaletteType, type TestProps } from "@react-fabric/core/dist/types/types";
3
2
  interface HistogramItem {
4
3
  id: string;
5
4
  label: string;
@@ -7,7 +6,7 @@ interface HistogramItem {
7
6
  total?: number;
8
7
  disabled?: boolean;
9
8
  }
10
- export interface HistogramProps {
9
+ export interface HistogramProps extends TestProps {
11
10
  /**
12
11
  * histogram items list
13
12
  */
@@ -37,5 +36,33 @@ export interface HistogramProps {
37
36
  */
38
37
  onClick?: (id: string, negative?: true) => void;
39
38
  }
40
- export declare const Histogram: ({ items, total, color, sortBy, emptyTitle, emptyMessage, onClick, }: HistogramProps) => import("react/jsx-runtime").JSX.Element;
39
+ /**
40
+ * Histogram component displays a bar chart of items with counts.
41
+ * It allows users to visualize the distribution of counts across different items.
42
+ * The component supports sorting, custom colors, and click handling for each item.
43
+ * It also provides an empty state when there are no items to display.
44
+ *
45
+ * @param {HistogramProps} props - The properties for the Histogram component.
46
+ * @returns {JSX.Element} - The rendered Histogram component.
47
+ *
48
+ * @example
49
+ * ```jsx
50
+ * <Histogram
51
+ * items={[
52
+ * { id: "1", label: "Item 1", count: 10 },
53
+ * { id: "2", label: "Item 2", count: 20 },
54
+ * { id: "3", label: "Item 3", count: 5, disabled: true },
55
+ * ]}
56
+ * total={30}
57
+ * color="primary-500"
58
+ * sortBy="count"
59
+ * emptyTitle="No Data Available"
60
+ * emptyMessage="Please check back later."
61
+ * onClick={(id, negative) => console.log(`Clicked on ${id}`, negative ? "Negative" : "Positive")}
62
+ * />
63
+ * ```
64
+ *
65
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-histogram--docs}
66
+ */
67
+ export declare const Histogram: ({ items, total, color, sortBy, emptyTitle, emptyMessage, onClick, ...aria }: HistogramProps) => import("react/jsx-runtime").JSX.Element;
41
68
  export {};
@@ -1,5 +1,23 @@
1
- /// <reference types="react" />
2
- export declare const useFilteredList: <T extends unknown = KeyValue<any>, Q extends unknown = string>(items: T[], matcher?: (item: T, query: Q) => boolean) => {
1
+ /**
2
+ * Custom hook to filter a list of items based on a query.
3
+ * It provides a way to search through the items and returns the filtered list.
4
+ * The hook uses a deferred value to optimize performance during transitions.
5
+ * It also allows for a custom matcher function to define how items should be matched against the query.
6
+ *
7
+ * @param items - The list of items to filter.
8
+ * @param matcher - An optional function to match items against the query.
9
+ * @returns An object containing the search function, current query, filtered list, and a boolean indicating if a search is in progress.
10
+ *
11
+ * @example
12
+ * ```jsx
13
+ * useFilteredList(items, (item, query) => {
14
+ * return item.name.includes(query);
15
+ * });
16
+ * ```
17
+ *
18
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-usefilteredlist--docs}
19
+ */
20
+ export declare const useFilteredList: <T extends AnyObject = KeyValue, Q extends AnyObject = string>(items: T[], matcher?: (item: T, query: Q) => boolean) => {
3
21
  onSearch: import("react").Dispatch<import("react").SetStateAction<Q | undefined>>;
4
22
  query: Q | undefined;
5
23
  filteredList: T[];
@@ -16,6 +16,25 @@ export interface PaginationOptions {
16
16
  */
17
17
  onChange?: (page: number) => void;
18
18
  }
19
+ /**
20
+ * Custom hook to manage pagination state and logic.
21
+ * It calculates the total number of pages, generates page ranges,
22
+ * and provides a way to change the current page.
23
+ * It also handles the transition of page changes to optimize performance.
24
+ *
25
+ * @param options - The pagination options including total records, current page, records per page, and change handler.
26
+ * @returns An object containing the current page, total pages, head label, ranges for pagination pills, and a function to change the page.
27
+ *
28
+ * @example
29
+ * ```jsx
30
+ * const { page, totalPages, headLabel, ranges, onPageChange } = usePagination({
31
+ * totalRecords: 100,
32
+ * currentPage: 0,
33
+ * perPage: 10,
34
+ * onChange: (newPage) => console.log("Page changed to:", newPage),
35
+ * });
36
+ * ```
37
+ */
19
38
  export declare const usePagination: ({ totalRecords, currentPage, perPage, onChange, }: PaginationOptions) => {
20
39
  page: number;
21
40
  totalPages: number;
@@ -22,6 +22,35 @@ export interface SelectableProps {
22
22
  */
23
23
  onClick?: (id: string, isNegative: boolean) => void;
24
24
  }
25
+ /**
26
+ * Custom hook to manage selection of items in a list.
27
+ * It allows toggling selection state of items, handling both selected and non-selected states.
28
+ * The hook maintains a selection state and provides a function to toggle the selection of items.
29
+ * It also supports callbacks for when the selection changes or when an item is clicked.
30
+ *
31
+ * @param items - The list of items to manage selection for.
32
+ * @param selected - An array of item IDs that are currently selected.
33
+ * @param nonselected - An array of item IDs that are currently non-selected.
34
+ * @param onChange - Callback function that is called when the selection changes.
35
+ * @param onClick - Callback function that is called when an item is clicked.
36
+ * @returns An object containing the current selection state and a function to toggle selection of items.
37
+ *
38
+ * @example
39
+ * ```jsx
40
+ * const { selection, toggleSelection } = useSelectableList({
41
+ * items: [{ id: '1', label: 'Item 1' }, { id: '2', label: 'Item 2' }],
42
+ * selected: ['1'],
43
+ * nonselected: ['2'],
44
+ * onChange: (selectedIds, nonSelectedIds) => {
45
+ * console.log('Selected:', selectedIds);
46
+ * console.log('Non-selected:', nonSelectedIds);
47
+ * },
48
+ * onClick: (id, isNegative) => {
49
+ * console.log(`Item ${id} clicked, isNegative: ${isNegative}`);
50
+ * },
51
+ * });
52
+ * ```
53
+ */
25
54
  export declare const useSelectableList: ({ items, selected, nonselected, onChange, onClick, }: SelectableProps) => {
26
55
  selection: KeyValue<number>;
27
56
  toggleSelection: (id: string, isNegative?: boolean) => void;
@@ -4,7 +4,7 @@ export { Histogram } from "./histogram/Histogram";
4
4
  export { JsonViewer } from "./json/JsonViewer";
5
5
  export { Pagination } from "./pagination/Pagination";
6
6
  export { Table } from "./table/Table";
7
- export { type TableRef } from "./table/types";
7
+ export { type TableColumn, type TableRef } from "./table/types";
8
8
  export { TreePanel } from "./tree/TreePanel";
9
9
  export { type TreeNodeType as TreeNode } from "./tree/types";
10
10
  export { VirtualGallery, type VirtualGalleryRef } from "./virtual/Gallery";
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import { type CssProp } from "@react-fabric/core/dist/types/types";
3
2
  export interface JsonViewProps<T> extends CssProp {
4
3
  /**
@@ -56,4 +55,30 @@ export interface JsonViewProps<T> extends CssProp {
56
55
  */
57
56
  formatter?: (path?: string, value?: AnyObject) => string | JSX.Element | undefined;
58
57
  }
59
- export declare const JsonViewer: <T extends KeyValue<any> = KeyValue<any>>({ className, json, copy, propertyScheme, filters, inline, labelWidth, formatter, labeler, onFilter, emptyMessage, showPropertyTree, ...rest }: JsonViewProps<T>) => import("react/jsx-runtime").JSX.Element;
58
+ /**
59
+ * JsonViewer component to display JSON data in a structured format.
60
+ * It supports inline display, property filtering, and custom formatting.
61
+ * The component can handle nested objects and arrays, displaying them in a tree-like structure.
62
+ * It also provides options for copying values and filtering properties.
63
+ *
64
+ * @param {JsonViewProps<T>} props - The properties for the JsonViewer component.
65
+ * @returns {JSX.Element} The rendered JsonViewer component.
66
+ *
67
+ * @example
68
+ * ```jsx
69
+ * <JsonViewer
70
+ * json={{ name: "John", age: 30, address: { city: "New York", zip: "10001" } }}
71
+ * copy={true}
72
+ * filters={true}
73
+ * propertyScheme={{ date: ["createdAt"], phone: ["contact"] }}
74
+ * inline={true}
75
+ * labelWidth="25%"
76
+ * formatter={(path, value) => (path === "age" ? `${value} years` : value)}
77
+ * labeler={(path) => path.replace(/_/g, " ").toUpperCase()}
78
+ * onFilter={(path, value, negate) => console.log(`Filter ${negate ? "negate" : ""} on ${path}:`, value)}
79
+ * />
80
+ * ```
81
+ *
82
+ * @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-jsonviewer--docs}
83
+ */
84
+ export declare const JsonViewer: <T extends KeyValue = KeyValue>({ className, json, copy, propertyScheme, filters, inline, labelWidth, formatter, labeler, onFilter, emptyMessage, showPropertyTree, ...rest }: JsonViewProps<T>) => import("react/jsx-runtime").JSX.Element;