@react-fabric/data 1.0.0-beta.6 → 1.0.0-beta.61
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
- package/{dist/esm/tree/types.js → css/styles.css} +2 -7
- package/dist/cjs/checklist/CheckList.js +27 -4
- package/dist/cjs/histogram/Histogram.js +39 -9
- package/dist/cjs/hooks/useFilteredList.js +88 -10
- package/dist/cjs/hooks/usePagination.js +27 -4
- package/dist/cjs/hooks/useSelectableList.js +29 -0
- package/dist/cjs/i18n/ar.json.js +8 -1
- package/dist/cjs/i18n/en.json.js +8 -1
- package/dist/cjs/json/JsonViewer.js +68 -28
- package/dist/cjs/pagination/Pagination.js +14 -4
- package/dist/cjs/table/AddColumn.js +3 -3
- package/dist/cjs/table/BodyCell.js +14 -6
- package/dist/cjs/table/BodyRow.js +4 -4
- package/dist/cjs/table/CheckboxCell.js +2 -2
- package/dist/cjs/table/ColumnFilters.js +97 -0
- package/dist/cjs/table/HeaderCell.js +71 -43
- package/dist/cjs/table/Table.js +62 -13
- package/dist/cjs/table/types.js +29 -0
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +127 -19
- package/dist/cjs/tree/TreeNode.js +50 -32
- package/dist/cjs/tree/TreePanel.js +52 -19
- package/dist/cjs/tree/useTree.js +199 -38
- package/dist/cjs/tree/utils.js +39 -12
- package/dist/cjs/virtual/Gallery.js +97 -45
- package/dist/cjs/virtual/List.js +93 -39
- package/dist/cjs/virtual/Scroller.js +16 -8
- package/dist/esm/checklist/CheckList.js +28 -5
- package/dist/esm/histogram/Histogram.js +41 -11
- package/dist/esm/hooks/useFilteredList.js +89 -11
- package/dist/esm/hooks/usePagination.js +27 -4
- package/dist/esm/hooks/useSelectableList.js +29 -0
- package/dist/esm/i18n/ar.json.js +8 -2
- package/dist/esm/i18n/en.json.js +8 -2
- package/dist/esm/json/JsonViewer.js +69 -29
- package/dist/esm/pagination/Pagination.js +15 -5
- package/dist/esm/table/AddColumn.js +4 -4
- package/dist/esm/table/BodyCell.js +15 -7
- package/dist/esm/table/BodyRow.js +4 -4
- package/dist/esm/table/CheckboxCell.js +3 -3
- package/dist/esm/table/ColumnFilters.js +97 -0
- package/dist/esm/table/HeaderCell.js +72 -44
- package/dist/esm/table/Table.js +63 -14
- package/dist/esm/table/types.js +29 -0
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +129 -21
- package/dist/esm/tree/TreeNode.js +53 -35
- package/dist/esm/tree/TreePanel.js +54 -21
- package/dist/esm/tree/useTree.js +202 -41
- package/dist/esm/tree/utils.js +40 -13
- package/dist/esm/virtual/Gallery.js +97 -45
- package/dist/esm/virtual/List.js +93 -39
- package/dist/esm/virtual/Scroller.js +17 -9
- package/dist/types/checklist/CheckList.d.ts +22 -0
- package/dist/types/histogram/Histogram.d.ts +28 -1
- package/dist/types/hooks/useFilteredList.d.ts +66 -5
- package/dist/types/hooks/usePagination.d.ts +19 -0
- package/dist/types/hooks/useSelectableList.d.ts +29 -0
- package/dist/types/json/JsonViewer.d.ts +27 -2
- package/dist/types/pagination/Pagination.d.ts +10 -1
- package/dist/types/table/ColumnFilters.d.ts +9 -0
- package/dist/types/table/HeaderCell.d.ts +1 -1
- package/dist/types/table/Table.d.ts +14 -1
- package/dist/types/table/types.d.ts +46 -7
- package/dist/types/table/useVirtualTable.d.ts +23 -9
- package/dist/types/tree/TreeNode.d.ts +1 -1
- package/dist/types/tree/TreePanel.d.ts +42 -1
- package/dist/types/tree/types.d.ts +65 -21
- package/dist/types/tree/useTree.d.ts +9 -10
- package/dist/types/tree/utils.d.ts +10 -3
- package/dist/types/virtual/Gallery.d.ts +42 -3
- package/dist/types/virtual/List.d.ts +42 -3
- package/package.json +16 -14
- package/src/checklist/CheckList.tsx +39 -7
- package/src/histogram/Histogram.tsx +43 -19
- package/src/hooks/useFilteredList.tsx +109 -9
- package/src/hooks/usePagination.tsx +32 -7
- package/src/hooks/useSelectableList.ts +29 -0
- package/src/i18n/ar.json +5 -0
- package/src/i18n/en.json +5 -0
- package/src/json/JsonViewer.tsx +76 -37
- package/src/pagination/Pagination.tsx +15 -5
- package/src/table/AddColumn.tsx +4 -4
- package/src/table/BodyCell.tsx +24 -7
- package/src/table/BodyRow.tsx +7 -4
- package/src/table/CheckboxCell.tsx +5 -5
- package/src/table/ColumnFilters.tsx +105 -0
- package/src/table/HeaderCell.tsx +74 -21
- package/src/table/Table.tsx +107 -12
- package/src/table/types.ts +49 -10
- package/src/table/useResizer.ts +5 -3
- package/src/table/useVirtualTable.ts +158 -27
- package/src/tree/TreeNode.tsx +96 -62
- package/src/tree/TreePanel.tsx +88 -22
- package/src/tree/types.ts +73 -23
- package/src/tree/useTree.ts +220 -44
- package/src/tree/utils.ts +58 -20
- package/src/virtual/Gallery.tsx +118 -54
- package/src/virtual/List.tsx +99 -39
- package/src/virtual/Scroller.tsx +25 -9
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/cjs/tree/types.js +0 -30
- package/dist/esm/histogram/Histogram.module.css +0 -1
|
@@ -12,7 +12,7 @@ import { useDeferredValue, useMemo, useRef, useState, useEffect, useCallback, us
|
|
|
12
12
|
import { Scroller } from './Scroller.js';
|
|
13
13
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
|
-
var _excluded = ["items", "children", "columns", "padding", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "galleryRef"];
|
|
15
|
+
var _excluded = ["items", "children", "columns", "fullWidth", "maxWidth", "minWidth", "total", "padding", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "galleryRef"];
|
|
16
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
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; }
|
|
18
18
|
var createItemList = memoizeOne(function (items) {
|
|
@@ -23,6 +23,11 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
23
23
|
var items = _ref.items,
|
|
24
24
|
children = _ref.children,
|
|
25
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,
|
|
26
31
|
_ref$padding = _ref.padding,
|
|
27
32
|
padding = _ref$padding === void 0 ? "md" : _ref$padding,
|
|
28
33
|
_ref$defaultHeight = _ref.defaultHeight,
|
|
@@ -38,13 +43,13 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
38
43
|
aria = _objectWithoutProperties(_ref, _excluded);
|
|
39
44
|
var count = useDeferredValue(items.length);
|
|
40
45
|
var extraSize = useMemo(function () {
|
|
41
|
-
return onLoadMore ?
|
|
46
|
+
return onLoadMore ? 8 : 0;
|
|
42
47
|
}, [onLoadMore]);
|
|
43
|
-
var itemList = createItemList(items.map(function (item,
|
|
48
|
+
var itemList = createItemList(items.map(function (item, index) {
|
|
44
49
|
return {
|
|
45
|
-
index:
|
|
46
|
-
|
|
47
|
-
isLast:
|
|
50
|
+
index: index,
|
|
51
|
+
item: item,
|
|
52
|
+
isLast: index + 1 === items.length
|
|
48
53
|
};
|
|
49
54
|
}));
|
|
50
55
|
var scrollerRef = useRef(null);
|
|
@@ -61,8 +66,9 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
61
66
|
if (scrollerRef.current) {
|
|
62
67
|
var el = scrollerRef.current;
|
|
63
68
|
var handler = function handler() {
|
|
64
|
-
var _el$offsetWidth;
|
|
65
|
-
|
|
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)));
|
|
66
72
|
};
|
|
67
73
|
var ob = new ResizeObserver(handler);
|
|
68
74
|
handler();
|
|
@@ -80,13 +86,14 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
80
86
|
},
|
|
81
87
|
estimateSize: function estimateSize() {
|
|
82
88
|
return height;
|
|
83
|
-
}
|
|
89
|
+
},
|
|
90
|
+
overscan: 0
|
|
84
91
|
});
|
|
85
92
|
var virtualItems = virtualizer.getVirtualItems();
|
|
86
93
|
var currentIndex = useRef(0);
|
|
87
94
|
useEffect(function () {
|
|
88
|
-
var _virtualItems$
|
|
89
|
-
currentIndex.current = (_virtualItems$
|
|
95
|
+
var _virtualItems$0$index, _virtualItems$;
|
|
96
|
+
currentIndex.current = (_virtualItems$0$index = (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$0$index !== void 0 ? _virtualItems$0$index : 0;
|
|
90
97
|
if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
|
|
91
98
|
}, [virtualItems]);
|
|
92
99
|
var calculateActiveScroll = useCallback(function () {
|
|
@@ -118,45 +125,48 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
118
125
|
setScrollActive(calculateActiveScroll());
|
|
119
126
|
}, [count, calculateActiveScroll]);
|
|
120
127
|
useEffect(function () {
|
|
121
|
-
|
|
122
|
-
var
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}, [onLoadMore, loading, itemList, virtualItems, count, columnCount]);
|
|
130
|
-
useEffect(function () {
|
|
131
|
-
var _virtualItems$2;
|
|
132
|
-
var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
|
|
133
|
-
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;
|
|
134
136
|
var db = debounce(onLoadMore);
|
|
135
|
-
|
|
137
|
+
if (canLoadPrevPage) {
|
|
138
|
+
db(firstIndex);
|
|
139
|
+
} else if (!loading && canLoadNextPage) {
|
|
140
|
+
db(lastIndex + 1);
|
|
141
|
+
}
|
|
136
142
|
return function () {
|
|
137
143
|
return db.cancel();
|
|
138
144
|
};
|
|
139
145
|
}
|
|
140
|
-
}, [onLoadMore,
|
|
146
|
+
}, [onLoadMore, virtualItems]);
|
|
147
|
+
var isRenderedRef = useRef(false);
|
|
141
148
|
useLayoutEffect(function () {
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
149
|
+
if (!isRenderedRef.current && itemList.length > 0) {
|
|
150
|
+
isRenderedRef.current = true;
|
|
151
|
+
initialScroll && setTimeout(function () {
|
|
152
|
+
virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
|
|
153
|
+
align: "start"
|
|
154
|
+
});
|
|
155
|
+
}, 200);
|
|
156
|
+
}
|
|
157
|
+
}, [columnCount, initialScroll, itemList]);
|
|
148
158
|
useImperativeHandle(galleryRef, function () {
|
|
149
159
|
return {
|
|
150
160
|
scrollToItem: function scrollToItem(index) {
|
|
151
161
|
virtualizer.scrollToIndex(Math.floor(index / columnCount), {
|
|
152
|
-
align: "
|
|
162
|
+
align: "auto"
|
|
153
163
|
});
|
|
154
164
|
},
|
|
155
165
|
hilight: function hilight(index) {
|
|
156
166
|
var _scrollerRef$current2;
|
|
157
167
|
(_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");
|
|
158
168
|
virtualizer.scrollToIndex(Math.floor(index / columnCount), {
|
|
159
|
-
align: "
|
|
169
|
+
align: "auto"
|
|
160
170
|
});
|
|
161
171
|
setTimeout(function () {
|
|
162
172
|
var _scrollerRef$current3;
|
|
@@ -172,15 +182,19 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
172
182
|
return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
|
|
173
183
|
ref: scrollerRef,
|
|
174
184
|
onScroll: handleScroll,
|
|
175
|
-
className: classNames("area-content bg-base overflow-auto
|
|
185
|
+
className: classNames("area-content bg-base overflow-auto")
|
|
176
186
|
}, aria), {}, {
|
|
177
187
|
children: /*#__PURE__*/jsxs("div", {
|
|
178
|
-
className: classNames("
|
|
188
|
+
className: classNames("flex flex-nowrap justify-center gap-2 min-h-full"),
|
|
179
189
|
children: [/*#__PURE__*/jsx("div", {
|
|
180
|
-
className: classNames("box-content", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
|
|
190
|
+
className: classNames("box-content", fullWidth && "flex-1", padding === "sm" && "p-1", padding === "md" && "p-2", padding === "lg" && "p-4"),
|
|
191
|
+
style: {
|
|
192
|
+
minWidth: minWidth,
|
|
193
|
+
maxWidth: maxWidth
|
|
194
|
+
},
|
|
181
195
|
children: /*#__PURE__*/jsxs("div", {
|
|
182
196
|
style: {
|
|
183
|
-
height: virtualizer.getTotalSize()
|
|
197
|
+
height: virtualizer.getTotalSize() + extraSize
|
|
184
198
|
},
|
|
185
199
|
children: [/*#__PURE__*/jsx("div", {
|
|
186
200
|
style: {
|
|
@@ -188,23 +202,28 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
188
202
|
}
|
|
189
203
|
}), virtualItems.map(function (_ref3) {
|
|
190
204
|
var key = _ref3.key,
|
|
191
|
-
index = _ref3.index
|
|
192
|
-
measureElement = _ref3.measureElement;
|
|
205
|
+
index = _ref3.index;
|
|
193
206
|
return /*#__PURE__*/jsx("div", {
|
|
194
207
|
className: "flex",
|
|
195
208
|
"data-index": index,
|
|
196
|
-
ref: measureElement,
|
|
209
|
+
ref: virtualizer.measureElement,
|
|
197
210
|
children: columnMap.map(function (col) {
|
|
211
|
+
var _itemList, _itemList2;
|
|
198
212
|
return /*#__PURE__*/jsx("div", {
|
|
199
213
|
"data-index": index * columnCount + col,
|
|
200
214
|
className: classNames("grid rounded-capped"),
|
|
201
|
-
|
|
215
|
+
style: {
|
|
216
|
+
minWidth: width,
|
|
217
|
+
minHeight: height
|
|
218
|
+
},
|
|
219
|
+
children: (_itemList = itemList[index * columnCount + col]) !== null && _itemList !== void 0 && _itemList.item ? children(itemList[index * columnCount + col]) : ((_itemList2 = itemList[index * columnCount + col]) === null || _itemList2 === void 0 ? void 0 : _itemList2.item) === null && /*#__PURE__*/jsx(Skeleton, {
|
|
220
|
+
className: "p-2"
|
|
221
|
+
})
|
|
202
222
|
}, "".concat(key, ":").concat(col));
|
|
203
223
|
})
|
|
204
224
|
}, key);
|
|
205
|
-
}),
|
|
206
|
-
|
|
207
|
-
children: loading && /*#__PURE__*/jsx(Skeleton, {})
|
|
225
|
+
}), loading && /*#__PURE__*/jsx("div", {
|
|
226
|
+
children: /*#__PURE__*/jsx(Skeleton, {})
|
|
208
227
|
})]
|
|
209
228
|
})
|
|
210
229
|
}), !hideScroller && /*#__PURE__*/jsx("div", {
|
|
@@ -231,6 +250,39 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
231
250
|
};
|
|
232
251
|
_VirtualGallery.displayName = "VirtualGallery";
|
|
233
252
|
var GenericMemo = memo;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* VirtualGallery component provides a virtualized gallery view for displaying a large list of items efficiently.
|
|
256
|
+
* It supports features like fixed columns, loading states, and customizable item rendering.
|
|
257
|
+
* The component uses virtualization to render only the visible items, improving performance for large datasets.
|
|
258
|
+
* It also provides a scroller for easy navigation through the items.
|
|
259
|
+
*
|
|
260
|
+
* @param {VirtualGalleryProps<T>} props - The properties for the VirtualGallery component.
|
|
261
|
+
* @returns {JSX.Element} The rendered VirtualGallery component.
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```jsx
|
|
265
|
+
* <VirtualGallery
|
|
266
|
+
* items={items}
|
|
267
|
+
* columns={3}
|
|
268
|
+
* defaultHeight={100}
|
|
269
|
+
* defaultWidth={100}
|
|
270
|
+
* fullWidth={true}
|
|
271
|
+
* onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
|
|
272
|
+
* onScroll={(top) => console.log("Scrolled to top:", top)}
|
|
273
|
+
* >
|
|
274
|
+
* {({ item, index, isLast }) => (
|
|
275
|
+
* <div className="gallery-item" key={item.id}>
|
|
276
|
+
* <img src={item.image} alt={item.label} />
|
|
277
|
+
* <p>{item.label}</p>
|
|
278
|
+
* </div>
|
|
279
|
+
* )}
|
|
280
|
+
* </VirtualGallery>
|
|
281
|
+
* ```
|
|
282
|
+
*
|
|
283
|
+
* @see {@link https://adarshpastakia.github.io/react-fabric/?path=/docs/data-virtualgallery--docs}
|
|
284
|
+
* @see {@link https://tanstack.com/docs/react-virtual/latest/overview}
|
|
285
|
+
*/
|
|
234
286
|
var VirtualGallery = GenericMemo(_VirtualGallery);
|
|
235
287
|
|
|
236
288
|
export { VirtualGallery };
|
package/dist/esm/virtual/List.js
CHANGED
|
@@ -12,7 +12,7 @@ import { useDeferredValue, useMemo, useRef, useEffect, useCallback, useState, us
|
|
|
12
12
|
import { Scroller } from './Scroller.js';
|
|
13
13
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
14
14
|
|
|
15
|
-
var _excluded = ["items", "children", "fullWidth", "padding", "orientation", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "listRef"];
|
|
15
|
+
var _excluded = ["items", "total", "children", "fullWidth", "maxWidth", "minWidth", "padding", "orientation", "defaultHeight", "defaultWidth", "hideScroller", "initialScroll", "loading", "onLoadMore", "onScroll", "listRef"];
|
|
16
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
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; }
|
|
18
18
|
var createItemList = memoizeOne(function (items) {
|
|
@@ -21,8 +21,12 @@ var createItemList = memoizeOne(function (items) {
|
|
|
21
21
|
var _VirtualList = function _VirtualList(_ref) {
|
|
22
22
|
var _virtualItems$3, _virtualItems$4;
|
|
23
23
|
var items = _ref.items,
|
|
24
|
+
_ref$total = _ref.total,
|
|
25
|
+
total = _ref$total === void 0 ? 0 : _ref$total,
|
|
24
26
|
children = _ref.children,
|
|
25
27
|
fullWidth = _ref.fullWidth,
|
|
28
|
+
maxWidth = _ref.maxWidth,
|
|
29
|
+
minWidth = _ref.minWidth,
|
|
26
30
|
_ref$padding = _ref.padding,
|
|
27
31
|
padding = _ref$padding === void 0 ? "md" : _ref$padding,
|
|
28
32
|
_ref$orientation = _ref.orientation,
|
|
@@ -40,18 +44,19 @@ var _VirtualList = function _VirtualList(_ref) {
|
|
|
40
44
|
aria = _objectWithoutProperties(_ref, _excluded);
|
|
41
45
|
var count = useDeferredValue(items.length);
|
|
42
46
|
var extraSize = useMemo(function () {
|
|
43
|
-
return onLoadMore ?
|
|
47
|
+
return onLoadMore ? 8 : 0;
|
|
44
48
|
}, [onLoadMore]);
|
|
45
|
-
var itemList = createItemList(items.map(function (item,
|
|
49
|
+
var itemList = createItemList(items.map(function (item, index) {
|
|
46
50
|
return {
|
|
47
|
-
index:
|
|
48
|
-
|
|
49
|
-
isLast:
|
|
51
|
+
index: index,
|
|
52
|
+
item: item,
|
|
53
|
+
isLast: index + 1 === items.length
|
|
50
54
|
};
|
|
51
55
|
}));
|
|
52
56
|
var scrollerRef = useRef(null);
|
|
53
57
|
var virtualizer = useVirtualizer({
|
|
54
58
|
count: count,
|
|
59
|
+
overscan: 0,
|
|
55
60
|
horizontal: orientation === "horizontal",
|
|
56
61
|
getScrollElement: function getScrollElement() {
|
|
57
62
|
return scrollerRef.current;
|
|
@@ -63,8 +68,8 @@ var _VirtualList = function _VirtualList(_ref) {
|
|
|
63
68
|
var virtualItems = virtualizer.getVirtualItems();
|
|
64
69
|
var currentIndex = useRef(0);
|
|
65
70
|
useEffect(function () {
|
|
66
|
-
var _virtualItems$
|
|
67
|
-
currentIndex.current = (_virtualItems$
|
|
71
|
+
var _virtualItems$0$index, _virtualItems$;
|
|
72
|
+
currentIndex.current = (_virtualItems$0$index = (_virtualItems$ = virtualItems[0]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$0$index !== void 0 ? _virtualItems$0$index : 0;
|
|
68
73
|
if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
|
|
69
74
|
}, [virtualItems]);
|
|
70
75
|
var calculateActiveScroll = useCallback(function () {
|
|
@@ -109,45 +114,46 @@ var _VirtualList = function _VirtualList(_ref) {
|
|
|
109
114
|
setScrollActive(calculateActiveScroll());
|
|
110
115
|
}, [itemList, calculateActiveScroll]);
|
|
111
116
|
useEffect(function () {
|
|
112
|
-
|
|
113
|
-
var
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return db.cancel();
|
|
119
|
-
};
|
|
120
|
-
}, [onLoadMore, loading, itemList, virtualItems, count]);
|
|
121
|
-
useEffect(function () {
|
|
122
|
-
var _virtualItems$2;
|
|
123
|
-
var firstItem = (_virtualItems$2 = virtualItems[0]) === null || _virtualItems$2 === void 0 ? void 0 : _virtualItems$2.index;
|
|
124
|
-
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;
|
|
125
123
|
var db = debounce(onLoadMore);
|
|
126
|
-
|
|
124
|
+
if (canLoadPrevPage) {
|
|
125
|
+
db(firstItem);
|
|
126
|
+
} else if (!loading && canLoadNextPage) {
|
|
127
|
+
db(lastItem + 1);
|
|
128
|
+
}
|
|
127
129
|
return function () {
|
|
128
130
|
return db.cancel();
|
|
129
131
|
};
|
|
130
132
|
}
|
|
131
|
-
}, [onLoadMore,
|
|
133
|
+
}, [onLoadMore, virtualItems]);
|
|
134
|
+
var isRenderedRef = useRef(false);
|
|
132
135
|
useLayoutEffect(function () {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
136
|
+
if (!isRenderedRef.current && itemList.length > 0) {
|
|
137
|
+
isRenderedRef.current = true;
|
|
138
|
+
initialScroll && setTimeout(function () {
|
|
139
|
+
virtualizer.scrollToIndex(Math.floor(initialScroll), {
|
|
140
|
+
align: "start"
|
|
141
|
+
});
|
|
142
|
+
}, 200);
|
|
143
|
+
}
|
|
144
|
+
}, [itemList, initialScroll]);
|
|
139
145
|
useImperativeHandle(listRef, function () {
|
|
140
146
|
return {
|
|
141
147
|
scrollToItem: function scrollToItem(index) {
|
|
142
148
|
virtualizer.scrollToIndex(index, {
|
|
143
|
-
align: "
|
|
149
|
+
align: "auto"
|
|
144
150
|
});
|
|
145
151
|
},
|
|
146
152
|
hilight: function hilight(index) {
|
|
147
153
|
var _scrollerRef$current2;
|
|
148
154
|
(_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");
|
|
149
155
|
virtualizer.scrollToIndex(Math.floor(index), {
|
|
150
|
-
align: "
|
|
156
|
+
align: "auto"
|
|
151
157
|
});
|
|
152
158
|
setTimeout(function () {
|
|
153
159
|
var _scrollerRef$current3;
|
|
@@ -163,17 +169,21 @@ var _VirtualList = function _VirtualList(_ref) {
|
|
|
163
169
|
return /*#__PURE__*/jsx("div", _objectSpread(_objectSpread({
|
|
164
170
|
ref: scrollerRef,
|
|
165
171
|
onScroll: handleScroll,
|
|
166
|
-
className: classNames("area-content bg-base overflow-auto
|
|
172
|
+
className: classNames("area-content bg-base overflow-auto")
|
|
167
173
|
}, aria), {}, {
|
|
168
174
|
children: /*#__PURE__*/jsxs("div", {
|
|
169
|
-
className: classNames("
|
|
175
|
+
className: classNames("flex flex-nowrap gap-2 justify-center min-h-full min-w-full", orientation === "horizontal" && "flex-col"),
|
|
170
176
|
children: [/*#__PURE__*/jsxs("div", {
|
|
171
177
|
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"),
|
|
178
|
+
style: {
|
|
179
|
+
minWidth: minWidth,
|
|
180
|
+
maxWidth: maxWidth
|
|
181
|
+
},
|
|
172
182
|
children: [/*#__PURE__*/jsxs("div", {
|
|
173
183
|
style: orientation === "vertical" ? {
|
|
174
|
-
height: virtualizer.getTotalSize()
|
|
184
|
+
height: virtualizer.getTotalSize() + extraSize
|
|
175
185
|
} : {
|
|
176
|
-
width: virtualizer.getTotalSize()
|
|
186
|
+
width: virtualizer.getTotalSize() + extraSize
|
|
177
187
|
},
|
|
178
188
|
children: [/*#__PURE__*/jsx("div", {
|
|
179
189
|
style: orientation === "vertical" ? {
|
|
@@ -183,18 +193,25 @@ var _VirtualList = function _VirtualList(_ref) {
|
|
|
183
193
|
display: "inline-block"
|
|
184
194
|
}
|
|
185
195
|
}), virtualItems.map(function (_ref3) {
|
|
196
|
+
var _itemList$index, _itemList$index2;
|
|
186
197
|
var key = _ref3.key,
|
|
187
198
|
index = _ref3.index;
|
|
188
199
|
return /*#__PURE__*/jsx("div", {
|
|
189
200
|
"data-index": index,
|
|
190
201
|
ref: virtualizer.measureElement,
|
|
191
202
|
className: classNames("rounded-capped", orientation === "horizontal" ? "inline-grid" : "grid"),
|
|
192
|
-
|
|
203
|
+
style: {
|
|
204
|
+
minWidth: width,
|
|
205
|
+
minHeight: height
|
|
206
|
+
},
|
|
207
|
+
children: (_itemList$index = itemList[index]) !== null && _itemList$index !== void 0 && _itemList$index.item ? children(itemList[index]) : ((_itemList$index2 = itemList[index]) === null || _itemList$index2 === void 0 ? void 0 : _itemList$index2.item) === null && /*#__PURE__*/jsx(Skeleton, {
|
|
208
|
+
className: "p-2"
|
|
209
|
+
})
|
|
193
210
|
}, key);
|
|
194
211
|
})]
|
|
195
|
-
}),
|
|
196
|
-
className: orientation === "horizontal" ? "min-w-16" : "
|
|
197
|
-
children:
|
|
212
|
+
}), loading && /*#__PURE__*/jsx("div", {
|
|
213
|
+
className: orientation === "horizontal" ? "min-w-16" : "",
|
|
214
|
+
children: /*#__PURE__*/jsx(Skeleton, {})
|
|
198
215
|
})]
|
|
199
216
|
}), !hideScroller && /*#__PURE__*/jsx("div", {
|
|
200
217
|
className: classNames(orientation === "vertical" && "self-end sticky bottom-2", orientation === "horizontal" && "self-end sticky end-2"),
|
|
@@ -220,6 +237,43 @@ var _VirtualList = function _VirtualList(_ref) {
|
|
|
220
237
|
};
|
|
221
238
|
_VirtualList.displayName = "VirtualList";
|
|
222
239
|
var GenericMemo = memo;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* VirtualList component for rendering large lists efficiently using virtualization.
|
|
243
|
+
* It supports horizontal and vertical orientations, custom item heights and widths,
|
|
244
|
+
* and provides a scroller for navigating through the list.
|
|
245
|
+
* It also supports loading more items on scroll and provides a way to hilight items.
|
|
246
|
+
* It can be used with a ref to control scrolling and hilighting of items.
|
|
247
|
+
*
|
|
248
|
+
* @param {VirtualListProps<T>} props - The properties for the VirtualList component.
|
|
249
|
+
* @returns {JSX.Element} The rendered VirtualList component.
|
|
250
|
+
* @template T - The type of items in the list, extending AnyObject.
|
|
251
|
+
*
|
|
252
|
+
* @example
|
|
253
|
+
* ```jsx
|
|
254
|
+
* <VirtualList
|
|
255
|
+
* items={items}
|
|
256
|
+
* children={({ item, index, isLast }) => (
|
|
257
|
+
* <div key={index} className="item">
|
|
258
|
+
* {item.label}
|
|
259
|
+
* </div>
|
|
260
|
+
* )}
|
|
261
|
+
* fullWidth={true}
|
|
262
|
+
* orientation="vertical"
|
|
263
|
+
* defaultHeight={50}
|
|
264
|
+
* onLoadMore={(lastIndex) => console.log("Load more items from index:", lastIndex)}
|
|
265
|
+
* onScroll={(top) => console.log("Scrolled to top:", top)}
|
|
266
|
+
* listRef={virtualListRef}
|
|
267
|
+
* >
|
|
268
|
+
* {({ item, index, isLast }) => (
|
|
269
|
+
* <div className="gallery-item" key={item.id}>
|
|
270
|
+
* <img src={item.image} alt={item.label} />
|
|
271
|
+
* <p>{item.label}</p>
|
|
272
|
+
* </div>
|
|
273
|
+
* )}
|
|
274
|
+
* </VirtualList>
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
223
277
|
var VirtualList = GenericMemo(_VirtualList);
|
|
224
278
|
|
|
225
279
|
export { VirtualList };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import { ButtonGroup, Button
|
|
3
|
+
import { ButtonGroup, Button } from '@react-fabric/core';
|
|
4
4
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
5
5
|
|
|
6
6
|
/*
|
|
@@ -39,35 +39,43 @@ var Scroller = function Scroller(_ref) {
|
|
|
39
39
|
variant: "link",
|
|
40
40
|
className: "outline",
|
|
41
41
|
children: [/*#__PURE__*/jsx(Button, {
|
|
42
|
-
rtlFlip: true,
|
|
43
42
|
size: "sm",
|
|
44
43
|
variant: "link",
|
|
45
44
|
"aria-label": "scroll to top",
|
|
46
|
-
icon:
|
|
45
|
+
icon: {
|
|
46
|
+
icon: vertical ? "icon-[mdi--chevron-double-up]" : "icon-[mdi--chevron-double-left]",
|
|
47
|
+
rtlFlip: true
|
|
48
|
+
},
|
|
47
49
|
disabled: (scrollActive & 2) === 0,
|
|
48
50
|
onClick: onStart
|
|
49
51
|
}), /*#__PURE__*/jsx(Button, {
|
|
50
|
-
rtlFlip: true,
|
|
51
52
|
size: "sm",
|
|
52
53
|
variant: "link",
|
|
53
54
|
"aria-label": "scroll up",
|
|
54
|
-
icon:
|
|
55
|
+
icon: {
|
|
56
|
+
icon: vertical ? "icon-[mdi--chevron-up]" : "icon-[mdi--chevron-left]",
|
|
57
|
+
rtlFlip: true
|
|
58
|
+
},
|
|
55
59
|
disabled: (scrollActive & 2) === 0,
|
|
56
60
|
onClick: onPrevious
|
|
57
61
|
}), /*#__PURE__*/jsx(Button, {
|
|
58
|
-
rtlFlip: true,
|
|
59
62
|
size: "sm",
|
|
60
63
|
variant: "link",
|
|
61
64
|
"aria-label": "scroll down",
|
|
62
|
-
icon:
|
|
65
|
+
icon: {
|
|
66
|
+
icon: vertical ? "icon-[mdi--chevron-down]" : "icon-[mdi--chevron-right]",
|
|
67
|
+
rtlFlip: true
|
|
68
|
+
},
|
|
63
69
|
disabled: scrollActive % 2 === 0,
|
|
64
70
|
onClick: onNext
|
|
65
71
|
}), /*#__PURE__*/jsx(Button, {
|
|
66
|
-
rtlFlip: true,
|
|
67
72
|
size: "sm",
|
|
68
73
|
variant: "link",
|
|
69
74
|
"aria-label": "scroll to bottom",
|
|
70
|
-
icon:
|
|
75
|
+
icon: {
|
|
76
|
+
icon: vertical ? "icon-[mdi--chevron-double-down]" : "icon-[mdi--chevron-double-right]",
|
|
77
|
+
rtlFlip: true
|
|
78
|
+
},
|
|
71
79
|
disabled: scrollActive % 2 === 0,
|
|
72
80
|
onClick: onEnd
|
|
73
81
|
})]
|
|
@@ -27,4 +27,26 @@ export interface CheckListProps extends SelectableProps, TestProps {
|
|
|
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,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import { type ColorType, type PaletteType, type TestProps } from "@react-fabric/core/dist/types/types";
|
|
3
2
|
interface HistogramItem {
|
|
4
3
|
id: string;
|
|
@@ -37,5 +36,33 @@ export interface HistogramProps extends TestProps {
|
|
|
37
36
|
*/
|
|
38
37
|
onClick?: (id: string, negative?: true) => void;
|
|
39
38
|
}
|
|
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
|
+
*/
|
|
40
67
|
export declare const Histogram: ({ items, total, color, sortBy, emptyTitle, emptyMessage, onClick, ...aria }: HistogramProps) => import("react/jsx-runtime").JSX.Element;
|
|
41
68
|
export {};
|