@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.
- package/{src/histogram/Histogram.module.css → css/_histogram.css} +16 -13
- package/css/styles.css +24 -0
- package/dist/cjs/checklist/CheckList.js +48 -16
- package/dist/cjs/histogram/Histogram.js +48 -10
- package/dist/cjs/hooks/useFilteredList.js +20 -0
- 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 +67 -27
- package/dist/cjs/pagination/Pagination.js +10 -0
- package/dist/cjs/table/AddColumn.js +1 -1
- package/dist/cjs/table/BodyCell.js +38 -5
- package/dist/cjs/table/BodyRow.js +107 -0
- package/dist/cjs/table/CheckboxCell.js +1 -1
- package/dist/cjs/table/ColumnFilters.js +97 -0
- package/dist/cjs/table/HeaderCell.js +70 -37
- package/dist/cjs/table/Table.js +113 -71
- package/dist/cjs/table/types.js +29 -0
- package/dist/cjs/table/useResizer.js +4 -4
- package/dist/cjs/table/useVirtualTable.js +122 -18
- package/dist/cjs/tree/TreeNode.js +45 -25
- package/dist/cjs/tree/TreePanel.js +28 -10
- package/dist/cjs/tree/useTree.js +97 -15
- package/dist/cjs/tree/utils.js +20 -5
- package/dist/cjs/virtual/Gallery.js +84 -35
- package/dist/cjs/virtual/List.js +82 -32
- package/dist/esm/checklist/CheckList.js +50 -18
- package/dist/esm/histogram/Histogram.js +49 -11
- package/dist/esm/hooks/useFilteredList.js +20 -0
- 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 +68 -28
- package/dist/esm/pagination/Pagination.js +10 -0
- package/dist/esm/table/AddColumn.js +1 -1
- package/dist/esm/table/BodyCell.js +38 -5
- package/dist/esm/table/BodyRow.js +107 -0
- package/dist/esm/table/CheckboxCell.js +1 -1
- package/dist/esm/table/ColumnFilters.js +97 -0
- package/dist/esm/table/HeaderCell.js +71 -38
- package/dist/esm/table/Table.js +115 -73
- package/dist/esm/table/types.js +29 -0
- package/dist/esm/table/useResizer.js +4 -4
- package/dist/esm/table/useVirtualTable.js +124 -20
- package/dist/esm/tree/TreeNode.js +47 -27
- package/dist/esm/tree/TreePanel.js +28 -10
- package/dist/esm/tree/useTree.js +99 -17
- package/dist/esm/tree/utils.js +20 -5
- package/dist/esm/virtual/Gallery.js +84 -35
- package/dist/esm/virtual/List.js +82 -32
- package/dist/types/checklist/CheckList.d.ts +24 -2
- package/dist/types/histogram/Histogram.d.ts +31 -4
- package/dist/types/hooks/useFilteredList.d.ts +20 -2
- package/dist/types/hooks/usePagination.d.ts +19 -0
- package/dist/types/hooks/useSelectableList.d.ts +29 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/json/JsonViewer.d.ts +27 -2
- package/dist/types/pagination/Pagination.d.ts +10 -1
- package/dist/types/table/AddColumn.d.ts +2 -2
- package/dist/types/table/BodyCell.d.ts +4 -3
- package/dist/types/table/BodyRow.d.ts +20 -0
- package/dist/types/table/ColumnFilters.d.ts +9 -0
- package/dist/types/table/EmptyCell.d.ts +2 -2
- package/dist/types/table/HeaderCell.d.ts +2 -2
- package/dist/types/table/Table.d.ts +14 -1
- package/dist/types/table/types.d.ts +48 -7
- package/dist/types/table/useTableColumns.d.ts +6 -6
- package/dist/types/table/useVirtualTable.d.ts +23 -8
- 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 +25 -5
- package/dist/types/tree/useTree.d.ts +3 -10
- package/dist/types/tree/utils.d.ts +4 -1
- package/dist/types/virtual/Gallery.d.ts +44 -4
- package/dist/types/virtual/List.d.ts +44 -4
- package/package.json +13 -10
- package/src/checklist/CheckList.tsx +103 -77
- package/src/histogram/Histogram.tsx +45 -11
- package/src/hooks/useFilteredList.tsx +19 -0
- 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/index.ts +1 -1
- package/src/json/JsonViewer.tsx +71 -35
- package/src/pagination/Pagination.tsx +10 -0
- package/src/table/AddColumn.tsx +3 -3
- package/src/table/BodyCell.tsx +34 -5
- package/src/table/BodyRow.tsx +143 -0
- package/src/table/CheckboxCell.tsx +1 -1
- package/src/table/ColumnFilters.tsx +105 -0
- package/src/table/EmptyCell.tsx +2 -2
- package/src/table/HeaderCell.tsx +72 -14
- package/src/table/Table.tsx +177 -77
- package/src/table/types.ts +52 -6
- package/src/table/useResizer.ts +5 -3
- package/src/table/useTableColumns.ts +7 -7
- package/src/table/useVirtualTable.ts +146 -24
- package/src/tree/TreeNode.tsx +98 -56
- package/src/tree/TreePanel.tsx +64 -3
- package/src/tree/types.ts +32 -4
- package/src/tree/useTree.ts +109 -26
- package/src/tree/utils.ts +23 -8
- package/src/virtual/Gallery.tsx +96 -42
- package/src/virtual/List.tsx +82 -33
- package/dist/cjs/histogram/Histogram.module.css +0 -1
- package/dist/esm/histogram/Histogram.module.css +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
3
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
6
|
var core = require('@react-fabric/core');
|
|
5
7
|
var utilities = require('@react-fabric/utilities');
|
|
6
8
|
var reactVirtual = require('@tanstack/react-virtual');
|
|
@@ -10,6 +12,9 @@ var react = require('react');
|
|
|
10
12
|
var Scroller = require('./Scroller.js');
|
|
11
13
|
var jsxRuntime = require('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 = react.useDeferredValue(items.length);
|
|
34
45
|
var extraSize = react.useMemo(function () {
|
|
35
|
-
return onLoadMore ?
|
|
46
|
+
return onLoadMore ? 8 : 0;
|
|
36
47
|
}, [onLoadMore]);
|
|
37
|
-
var itemList = createItemList(items.map(function (item,
|
|
48
|
+
var itemList = createItemList(items.map(function (item, index) {
|
|
38
49
|
return {
|
|
39
|
-
index:
|
|
40
|
-
|
|
41
|
-
isLast:
|
|
50
|
+
index: index,
|
|
51
|
+
item: item,
|
|
52
|
+
isLast: index + 1 === items.length
|
|
42
53
|
};
|
|
43
54
|
}));
|
|
44
55
|
var scrollerRef = react.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
|
-
|
|
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 = react.useRef(0);
|
|
@@ -112,26 +125,25 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
|
|
|
112
125
|
setScrollActive(calculateActiveScroll());
|
|
113
126
|
}, [count, calculateActiveScroll]);
|
|
114
127
|
react.useEffect(function () {
|
|
115
|
-
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}, [onLoadMore, loading, itemList, virtualItems, count, columnCount]);
|
|
124
|
-
react.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 = utilities.debounce(onLoadMore);
|
|
129
|
-
|
|
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,
|
|
146
|
+
}, [onLoadMore, virtualItems]);
|
|
135
147
|
react.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: "
|
|
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: "
|
|
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__*/jsxRuntime.jsx("div", {
|
|
178
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
|
|
167
179
|
ref: scrollerRef,
|
|
168
180
|
onScroll: handleScroll,
|
|
169
|
-
className: classNames("area-content bg-base overflow-auto
|
|
181
|
+
className: classNames("area-content bg-base overflow-auto")
|
|
182
|
+
}, aria), {}, {
|
|
170
183
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
171
|
-
className: classNames("
|
|
184
|
+
className: classNames("flex flex-nowrap justify-center gap-2 min-h-full"),
|
|
172
185
|
children: [/*#__PURE__*/jsxRuntime.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__*/jsxRuntime.jsxs("div", {
|
|
175
192
|
style: {
|
|
176
|
-
height: virtualizer.getTotalSize()
|
|
193
|
+
height: virtualizer.getTotalSize() + extraSize
|
|
177
194
|
},
|
|
178
195
|
children: [/*#__PURE__*/jsxRuntime.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__*/jsxRuntime.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__*/jsxRuntime.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 = react.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
|
exports.VirtualGallery = VirtualGallery;
|
package/dist/cjs/virtual/List.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
3
4
|
var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
5
|
+
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
4
6
|
var core = require('@react-fabric/core');
|
|
5
7
|
var utilities = require('@react-fabric/utilities');
|
|
6
8
|
var reactVirtual = require('@tanstack/react-virtual');
|
|
@@ -10,14 +12,21 @@ var react = require('react');
|
|
|
10
12
|
var Scroller = require('./Scroller.js');
|
|
11
13
|
var jsxRuntime = require('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 = react.useDeferredValue(items.length);
|
|
36
46
|
var extraSize = react.useMemo(function () {
|
|
37
|
-
return onLoadMore ?
|
|
47
|
+
return onLoadMore ? 8 : 0;
|
|
38
48
|
}, [onLoadMore]);
|
|
39
|
-
var itemList = createItemList(items.map(function (item,
|
|
49
|
+
var itemList = createItemList(items.map(function (item, index) {
|
|
40
50
|
return {
|
|
41
|
-
index:
|
|
42
|
-
|
|
43
|
-
isLast:
|
|
51
|
+
index: index,
|
|
52
|
+
item: item,
|
|
53
|
+
isLast: index + 1 === items.length
|
|
44
54
|
};
|
|
45
55
|
}));
|
|
46
56
|
var scrollerRef = react.useRef(null);
|
|
47
57
|
var virtualizer = reactVirtual.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
|
react.useEffect(function () {
|
|
106
|
-
|
|
107
|
-
var
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
return db.cancel();
|
|
113
|
-
};
|
|
114
|
-
}, [onLoadMore, loading, itemList, virtualItems, count]);
|
|
115
|
-
react.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 = utilities.debounce(onLoadMore);
|
|
120
|
-
|
|
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,
|
|
133
|
+
}, [onLoadMore, virtualItems]);
|
|
126
134
|
react.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: "
|
|
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: "
|
|
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__*/jsxRuntime.jsx("div", {
|
|
165
|
+
return /*#__PURE__*/jsxRuntime.jsx("div", _objectSpread(_objectSpread({
|
|
158
166
|
ref: scrollerRef,
|
|
159
167
|
onScroll: handleScroll,
|
|
160
|
-
className: classNames("area-content bg-base overflow-auto
|
|
168
|
+
className: classNames("area-content bg-base overflow-auto")
|
|
169
|
+
}, aria), {}, {
|
|
161
170
|
children: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
162
|
-
className: classNames("
|
|
171
|
+
className: classNames("flex flex-nowrap gap-2 justify-center min-h-full min-w-full", orientation === "horizontal" && "flex-col"),
|
|
163
172
|
children: [/*#__PURE__*/jsxRuntime.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__*/jsxRuntime.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__*/jsxRuntime.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
|
-
}),
|
|
189
|
-
className: orientation === "horizontal" ? "min-w-16" : "
|
|
190
|
-
children:
|
|
201
|
+
}), loading && /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
202
|
+
className: orientation === "horizontal" ? "min-w-16" : "",
|
|
203
|
+
children: /*#__PURE__*/jsxRuntime.jsx(core.Skeleton, {})
|
|
191
204
|
})]
|
|
192
205
|
}), !hideScroller && /*#__PURE__*/jsxRuntime.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 = react.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
|
exports.VirtualList = VirtualList;
|
|
@@ -2,19 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
4
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
5
|
-
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
6
5
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
7
|
-
import
|
|
6
|
+
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
7
|
+
import { EmptyContent, Icon, CoreIcons, Badge } from '@react-fabric/core';
|
|
8
8
|
import { isString } from '@react-fabric/utilities';
|
|
9
|
-
import {
|
|
9
|
+
import { useState, useEffect, useMemo, createElement, Fragment, isValidElement } from 'react';
|
|
10
10
|
import { useTranslation } from 'react-i18next';
|
|
11
11
|
import { useSelectableList } from '../hooks/useSelectableList.js';
|
|
12
12
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
13
13
|
|
|
14
|
-
var _excluded = ["
|
|
14
|
+
var _excluded = ["id", "allowNegative", "selected", "icon", "label", "isDisabled", "onClick", "badge"],
|
|
15
|
+
_excluded2 = ["items", "maxCount", "allowNegative", "emptyMessage", "sortItems", "selected", "nonselected", "onChange", "onClick"];
|
|
15
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; }
|
|
16
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; }
|
|
17
|
-
var CheckItem =
|
|
18
|
+
var CheckItem = function CheckItem(_ref) {
|
|
18
19
|
var id = _ref.id,
|
|
19
20
|
allowNegative = _ref.allowNegative,
|
|
20
21
|
selected = _ref.selected,
|
|
@@ -22,8 +23,9 @@ var CheckItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
22
23
|
label = _ref.label,
|
|
23
24
|
isDisabled = _ref.isDisabled,
|
|
24
25
|
_onClick = _ref.onClick,
|
|
25
|
-
badge = _ref.badge
|
|
26
|
-
|
|
26
|
+
badge = _ref.badge,
|
|
27
|
+
aria = _objectWithoutProperties(_ref, _excluded);
|
|
28
|
+
return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({
|
|
27
29
|
role: "none",
|
|
28
30
|
className: "ax-checkList__item",
|
|
29
31
|
"data-disabled": isDisabled,
|
|
@@ -32,7 +34,8 @@ var CheckItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
32
34
|
},
|
|
33
35
|
onContextMenu: function onContextMenu(e) {
|
|
34
36
|
return [allowNegative && _onClick(id, true), e.preventDefault()];
|
|
35
|
-
}
|
|
37
|
+
}
|
|
38
|
+
}, aria), {}, {
|
|
36
39
|
children: [!allowNegative && /*#__PURE__*/jsx(Icon, {
|
|
37
40
|
"data-type": "checkbox",
|
|
38
41
|
className: "ax-checkList__checkbox",
|
|
@@ -67,9 +70,31 @@ var CheckItem = /*#__PURE__*/memo(function (_ref) {
|
|
|
67
70
|
}), /*#__PURE__*/jsx("label", {
|
|
68
71
|
children: label
|
|
69
72
|
}), /*#__PURE__*/jsx(Badge, _objectSpread({}, badge))]
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
+
}));
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* CheckList component to display a list of selectable items with checkboxes.
|
|
78
|
+
* It supports selection, deselection, and allows for negative selections.
|
|
79
|
+
*
|
|
80
|
+
* @param {CheckListProps} props - The properties for the CheckList component.
|
|
81
|
+
* @returns {JSX.Element} The rendered CheckList component.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```jsx
|
|
85
|
+
* <CheckList
|
|
86
|
+
* items={[
|
|
87
|
+
* { id: "1", label: "Item 1", icon: "icon1" },
|
|
88
|
+
* { id: "2", label: "Item 2", icon: "icon2", badge: { text: "New" } },
|
|
89
|
+
* ]}
|
|
90
|
+
* maxCount={5}
|
|
91
|
+
* allowNegative={true}
|
|
92
|
+
* emptyMessage="No items available"
|
|
93
|
+
* onChange={(selectedItems) => console.log(selectedItems)}
|
|
94
|
+
* onClick={(itemId, isNegative) => console.log(itemId, isNegative)}
|
|
95
|
+
* />
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
73
98
|
var CheckList = function CheckList(_ref2) {
|
|
74
99
|
var _ref2$items = _ref2.items,
|
|
75
100
|
items = _ref2$items === void 0 ? [] : _ref2$items,
|
|
@@ -79,12 +104,20 @@ var CheckList = function CheckList(_ref2) {
|
|
|
79
104
|
emptyMessage = _ref2.emptyMessage,
|
|
80
105
|
_ref2$sortItems = _ref2.sortItems,
|
|
81
106
|
sortItems = _ref2$sortItems === void 0 ? true : _ref2$sortItems,
|
|
82
|
-
|
|
107
|
+
selected = _ref2.selected,
|
|
108
|
+
nonselected = _ref2.nonselected,
|
|
109
|
+
onChange = _ref2.onChange,
|
|
110
|
+
onClick = _ref2.onClick,
|
|
111
|
+
aria = _objectWithoutProperties(_ref2, _excluded2);
|
|
83
112
|
var _useTranslation = useTranslation("data"),
|
|
84
113
|
t = _useTranslation.t;
|
|
85
|
-
var _useSelectableList = useSelectableList(
|
|
86
|
-
items: items
|
|
87
|
-
|
|
114
|
+
var _useSelectableList = useSelectableList({
|
|
115
|
+
items: items,
|
|
116
|
+
selected: selected,
|
|
117
|
+
nonselected: nonselected,
|
|
118
|
+
onChange: onChange,
|
|
119
|
+
onClick: onClick
|
|
120
|
+
}),
|
|
88
121
|
selection = _useSelectableList.selection,
|
|
89
122
|
toggleSelection = _useSelectableList.toggleSelection;
|
|
90
123
|
var _useState = useState(false),
|
|
@@ -105,8 +138,7 @@ var CheckList = function CheckList(_ref2) {
|
|
|
105
138
|
return 0;
|
|
106
139
|
}).slice(0, !showMore && maxCount > 0 ? maxCount : undefined);
|
|
107
140
|
}, [items, selection, maxCount, showMore, sortItems]);
|
|
108
|
-
return /*#__PURE__*/jsxs("div", {
|
|
109
|
-
className: "ax-checkList",
|
|
141
|
+
return /*#__PURE__*/jsxs("div", _objectSpread(_objectSpread({}, aria), {}, {
|
|
110
142
|
children: [listItems.map(function (item, index) {
|
|
111
143
|
return /*#__PURE__*/createElement(CheckItem, _objectSpread(_objectSpread({}, item), {}, {
|
|
112
144
|
key: index,
|
|
@@ -128,7 +160,7 @@ var CheckList = function CheckList(_ref2) {
|
|
|
128
160
|
className: "text-sm",
|
|
129
161
|
message: emptyMessage !== null && emptyMessage !== void 0 ? emptyMessage : t("checkList.empty")
|
|
130
162
|
})]
|
|
131
|
-
});
|
|
163
|
+
}));
|
|
132
164
|
};
|
|
133
165
|
|
|
134
166
|
export { CheckList };
|