@react-fabric/data 1.0.0-beta.58 → 1.0.0-beta.59

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.
@@ -87,13 +87,13 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
87
87
  estimateSize: function estimateSize() {
88
88
  return height;
89
89
  },
90
- overscan: 2
90
+ overscan: 0
91
91
  });
92
92
  var virtualItems = virtualizer.getVirtualItems();
93
93
  var currentIndex = react.useRef(0);
94
94
  react.useEffect(function () {
95
- var _virtualItems$2$index, _virtualItems$;
96
- currentIndex.current = (_virtualItems$2$index = (_virtualItems$ = virtualItems[2]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$2$index !== void 0 ? _virtualItems$2$index : 0;
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;
97
97
  if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
98
98
  }, [virtualItems]);
99
99
  var calculateActiveScroll = react.useCallback(function () {
@@ -144,13 +144,17 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
144
144
  };
145
145
  }
146
146
  }, [onLoadMore, virtualItems]);
147
+ var isRenderedRef = react.useRef(false);
147
148
  react.useLayoutEffect(function () {
148
- setTimeout(function () {
149
- initialScroll && virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
150
- align: "start"
151
- });
152
- }, 100);
153
- }, [columnCount]);
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]);
154
158
  react.useImperativeHandle(galleryRef, function () {
155
159
  return {
156
160
  scrollToItem: function scrollToItem(index) {
@@ -204,10 +208,17 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
204
208
  "data-index": index,
205
209
  ref: virtualizer.measureElement,
206
210
  children: columnMap.map(function (col) {
211
+ var _itemList;
207
212
  return /*#__PURE__*/jsxRuntime.jsx("div", {
208
213
  "data-index": index * columnCount + col,
209
214
  className: classNames("grid rounded-capped"),
210
- children: itemList[index * columnCount + col] && children(itemList[index * columnCount + col])
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]) : /*#__PURE__*/jsxRuntime.jsx(core.Skeleton, {
220
+ className: "p-2"
221
+ })
211
222
  }, "".concat(key, ":").concat(col));
212
223
  })
213
224
  }, key);
@@ -56,7 +56,7 @@ var _VirtualList = function _VirtualList(_ref) {
56
56
  var scrollerRef = react.useRef(null);
57
57
  var virtualizer = reactVirtual.useVirtualizer({
58
58
  count: count,
59
- overscan: 2,
59
+ overscan: 0,
60
60
  horizontal: orientation === "horizontal",
61
61
  getScrollElement: function getScrollElement() {
62
62
  return scrollerRef.current;
@@ -68,8 +68,8 @@ var _VirtualList = function _VirtualList(_ref) {
68
68
  var virtualItems = virtualizer.getVirtualItems();
69
69
  var currentIndex = react.useRef(0);
70
70
  react.useEffect(function () {
71
- var _virtualItems$2$index, _virtualItems$;
72
- currentIndex.current = (_virtualItems$2$index = (_virtualItems$ = virtualItems[2]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$2$index !== void 0 ? _virtualItems$2$index : 0;
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;
73
73
  if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
74
74
  }, [virtualItems]);
75
75
  var calculateActiveScroll = react.useCallback(function () {
@@ -131,13 +131,17 @@ var _VirtualList = function _VirtualList(_ref) {
131
131
  };
132
132
  }
133
133
  }, [onLoadMore, virtualItems]);
134
+ var isRenderedRef = react.useRef(false);
134
135
  react.useLayoutEffect(function () {
135
- setTimeout(function () {
136
- initialScroll && virtualizer.scrollToIndex(initialScroll, {
137
- align: "start"
138
- });
139
- }, 100);
140
- }, []);
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]);
141
145
  react.useImperativeHandle(listRef, function () {
142
146
  return {
143
147
  scrollToItem: function scrollToItem(index) {
@@ -189,13 +193,20 @@ var _VirtualList = function _VirtualList(_ref) {
189
193
  display: "inline-block"
190
194
  }
191
195
  }), virtualItems.map(function (_ref3) {
196
+ var _itemList$index;
192
197
  var key = _ref3.key,
193
198
  index = _ref3.index;
194
199
  return /*#__PURE__*/jsxRuntime.jsx("div", {
195
200
  "data-index": index,
196
201
  ref: virtualizer.measureElement,
197
202
  className: classNames("rounded-capped", orientation === "horizontal" ? "inline-grid" : "grid"),
198
- children: children(itemList[index])
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]) : /*#__PURE__*/jsxRuntime.jsx(core.Skeleton, {
208
+ className: "p-2"
209
+ })
199
210
  }, key);
200
211
  })]
201
212
  }), loading && /*#__PURE__*/jsxRuntime.jsx("div", {
@@ -87,13 +87,13 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
87
87
  estimateSize: function estimateSize() {
88
88
  return height;
89
89
  },
90
- overscan: 2
90
+ overscan: 0
91
91
  });
92
92
  var virtualItems = virtualizer.getVirtualItems();
93
93
  var currentIndex = useRef(0);
94
94
  useEffect(function () {
95
- var _virtualItems$2$index, _virtualItems$;
96
- currentIndex.current = (_virtualItems$2$index = (_virtualItems$ = virtualItems[2]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$2$index !== void 0 ? _virtualItems$2$index : 0;
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;
97
97
  if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
98
98
  }, [virtualItems]);
99
99
  var calculateActiveScroll = useCallback(function () {
@@ -144,13 +144,17 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
144
144
  };
145
145
  }
146
146
  }, [onLoadMore, virtualItems]);
147
+ var isRenderedRef = useRef(false);
147
148
  useLayoutEffect(function () {
148
- setTimeout(function () {
149
- initialScroll && virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
150
- align: "start"
151
- });
152
- }, 100);
153
- }, [columnCount]);
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]);
154
158
  useImperativeHandle(galleryRef, function () {
155
159
  return {
156
160
  scrollToItem: function scrollToItem(index) {
@@ -204,10 +208,17 @@ var _VirtualGallery = function _VirtualGallery(_ref) {
204
208
  "data-index": index,
205
209
  ref: virtualizer.measureElement,
206
210
  children: columnMap.map(function (col) {
211
+ var _itemList;
207
212
  return /*#__PURE__*/jsx("div", {
208
213
  "data-index": index * columnCount + col,
209
214
  className: classNames("grid rounded-capped"),
210
- children: itemList[index * columnCount + col] && children(itemList[index * columnCount + col])
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]) : /*#__PURE__*/jsx(Skeleton, {
220
+ className: "p-2"
221
+ })
211
222
  }, "".concat(key, ":").concat(col));
212
223
  })
213
224
  }, key);
@@ -56,7 +56,7 @@ var _VirtualList = function _VirtualList(_ref) {
56
56
  var scrollerRef = useRef(null);
57
57
  var virtualizer = useVirtualizer({
58
58
  count: count,
59
- overscan: 2,
59
+ overscan: 0,
60
60
  horizontal: orientation === "horizontal",
61
61
  getScrollElement: function getScrollElement() {
62
62
  return scrollerRef.current;
@@ -68,8 +68,8 @@ var _VirtualList = function _VirtualList(_ref) {
68
68
  var virtualItems = virtualizer.getVirtualItems();
69
69
  var currentIndex = useRef(0);
70
70
  useEffect(function () {
71
- var _virtualItems$2$index, _virtualItems$;
72
- currentIndex.current = (_virtualItems$2$index = (_virtualItems$ = virtualItems[2]) === null || _virtualItems$ === void 0 ? void 0 : _virtualItems$.index) !== null && _virtualItems$2$index !== void 0 ? _virtualItems$2$index : 0;
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;
73
73
  if (scrollerRef.current && virtualItems[0] && scrollerRef.current.scrollTop < virtualItems[0].size) currentIndex.current = 0;
74
74
  }, [virtualItems]);
75
75
  var calculateActiveScroll = useCallback(function () {
@@ -131,13 +131,17 @@ var _VirtualList = function _VirtualList(_ref) {
131
131
  };
132
132
  }
133
133
  }, [onLoadMore, virtualItems]);
134
+ var isRenderedRef = useRef(false);
134
135
  useLayoutEffect(function () {
135
- setTimeout(function () {
136
- initialScroll && virtualizer.scrollToIndex(initialScroll, {
137
- align: "start"
138
- });
139
- }, 100);
140
- }, []);
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]);
141
145
  useImperativeHandle(listRef, function () {
142
146
  return {
143
147
  scrollToItem: function scrollToItem(index) {
@@ -189,13 +193,20 @@ var _VirtualList = function _VirtualList(_ref) {
189
193
  display: "inline-block"
190
194
  }
191
195
  }), virtualItems.map(function (_ref3) {
196
+ var _itemList$index;
192
197
  var key = _ref3.key,
193
198
  index = _ref3.index;
194
199
  return /*#__PURE__*/jsx("div", {
195
200
  "data-index": index,
196
201
  ref: virtualizer.measureElement,
197
202
  className: classNames("rounded-capped", orientation === "horizontal" ? "inline-grid" : "grid"),
198
- children: children(itemList[index])
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]) : /*#__PURE__*/jsx(Skeleton, {
208
+ className: "p-2"
209
+ })
199
210
  }, key);
200
211
  })]
201
212
  }), loading && /*#__PURE__*/jsx("div", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-fabric/data",
3
- "version": "1.0.0-beta.58",
3
+ "version": "1.0.0-beta.59",
4
4
  "description": "RUF: Data package",
5
5
  "author": "Adarsh Pastakia <adarshpastakia@outlook.com>",
6
6
  "license": "MIT",
@@ -35,10 +35,10 @@
35
35
  "watch": "npm-run-all -p watch:rollup watch:dts"
36
36
  },
37
37
  "dependencies": {
38
- "@react-fabric/core": "^1.0.0-beta.58",
39
- "@react-fabric/date": "^1.0.0-beta.58",
40
- "@react-fabric/form": "^1.0.0-beta.58",
41
- "@react-fabric/utilities": "^1.0.0-beta.58",
38
+ "@react-fabric/core": "^1.0.0-beta.59",
39
+ "@react-fabric/date": "^1.0.0-beta.59",
40
+ "@react-fabric/form": "^1.0.0-beta.59",
41
+ "@react-fabric/utilities": "^1.0.0-beta.59",
42
42
  "@tanstack/react-virtual": "~3.13.12",
43
43
  "classnames": "~2.5.1",
44
44
  "color": "~5.0.2",
@@ -54,5 +54,5 @@
54
54
  "node": ">=18.12.0",
55
55
  "npm": ">=8.19.0"
56
56
  },
57
- "gitHead": "7e66f8c498e37a40e410ecafff2ea6b31505dc1a"
57
+ "gitHead": "74efd06c9c5ac629b6ef5cdc6d53ecb1c356f2eb"
58
58
  }
@@ -182,14 +182,14 @@ const _VirtualGallery = <T extends AnyObject>({
182
182
  count: Math.ceil(count / columnCount),
183
183
  getScrollElement: () => scrollerRef.current,
184
184
  estimateSize: () => height,
185
- overscan: 2,
185
+ overscan: 0,
186
186
  });
187
187
 
188
188
  const virtualItems = virtualizer.getVirtualItems();
189
189
 
190
190
  const currentIndex = useRef(0);
191
191
  useEffect(() => {
192
- currentIndex.current = virtualItems[2]?.index ?? 0;
192
+ currentIndex.current = virtualItems[0]?.index ?? 0;
193
193
  if (
194
194
  scrollerRef.current &&
195
195
  virtualItems[0] &&
@@ -246,14 +246,18 @@ const _VirtualGallery = <T extends AnyObject>({
246
246
  }
247
247
  }, [onLoadMore, virtualItems]);
248
248
 
249
+ const isRenderedRef = useRef(false);
249
250
  useLayoutEffect(() => {
250
- setTimeout(() => {
251
+ if (!isRenderedRef.current && itemList.length > 0) {
252
+ isRenderedRef.current = true;
251
253
  initialScroll &&
252
- virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
253
- align: "start",
254
- });
255
- }, 100);
256
- }, [columnCount]);
254
+ setTimeout(() => {
255
+ virtualizer.scrollToIndex(Math.floor(initialScroll / columnCount), {
256
+ align: "start",
257
+ });
258
+ }, 200);
259
+ }
260
+ }, [columnCount, initialScroll, itemList]);
257
261
 
258
262
  useImperativeHandle(
259
263
  galleryRef,
@@ -328,11 +332,16 @@ const _VirtualGallery = <T extends AnyObject>({
328
332
  key={`${key}:${col}`}
329
333
  data-index={index * columnCount + col}
330
334
  className={classNames("grid rounded-capped")}
335
+ style={{
336
+ minWidth: width,
337
+ minHeight: height,
338
+ }}
331
339
  >
332
- {itemList[index * columnCount + col] &&
333
- children(
334
- itemList[index * columnCount + col] as AnyObject,
335
- )}
340
+ {itemList[index * columnCount + col]?.item ? (
341
+ children(itemList[index * columnCount + col] as AnyObject)
342
+ ) : (
343
+ <Skeleton className="p-2" />
344
+ )}
336
345
  </div>
337
346
  ))}
338
347
  </div>
@@ -133,7 +133,7 @@ const _VirtualList = <T extends AnyObject>({
133
133
  const extraSize = useMemo(() => (onLoadMore ? 8 : 0), [onLoadMore]);
134
134
  const itemList: Array<{
135
135
  index: number;
136
- data: T;
136
+ item: T;
137
137
  isLast: boolean;
138
138
  isSticky: boolean;
139
139
  }> = createItemList(
@@ -149,7 +149,7 @@ const _VirtualList = <T extends AnyObject>({
149
149
  const scrollerRef = useRef<HTMLDivElement>(null);
150
150
  const virtualizer = useVirtualizer({
151
151
  count,
152
- overscan: 2,
152
+ overscan: 0,
153
153
  horizontal: orientation === "horizontal",
154
154
  getScrollElement: () => scrollerRef.current,
155
155
  estimateSize: () => (orientation === "horizontal" ? width : height),
@@ -159,7 +159,7 @@ const _VirtualList = <T extends AnyObject>({
159
159
 
160
160
  const currentIndex = useRef(0);
161
161
  useEffect(() => {
162
- currentIndex.current = virtualItems[2]?.index ?? 0;
162
+ currentIndex.current = virtualItems[0]?.index ?? 0;
163
163
  if (
164
164
  scrollerRef.current &&
165
165
  virtualItems[0] &&
@@ -225,12 +225,18 @@ const _VirtualList = <T extends AnyObject>({
225
225
  }
226
226
  }, [onLoadMore, virtualItems]);
227
227
 
228
+ const isRenderedRef = useRef(false);
228
229
  useLayoutEffect(() => {
229
- setTimeout(() => {
230
+ if (!isRenderedRef.current && itemList.length > 0) {
231
+ isRenderedRef.current = true;
230
232
  initialScroll &&
231
- virtualizer.scrollToIndex(initialScroll, { align: "start" });
232
- }, 100);
233
- }, []);
233
+ setTimeout(() => {
234
+ virtualizer.scrollToIndex(Math.floor(initialScroll), {
235
+ align: "start",
236
+ });
237
+ }, 200);
238
+ }
239
+ }, [itemList, initialScroll]);
234
240
 
235
241
  useImperativeHandle(
236
242
  listRef,
@@ -311,8 +317,16 @@ const _VirtualList = <T extends AnyObject>({
311
317
  "rounded-capped",
312
318
  orientation === "horizontal" ? "inline-grid" : "grid",
313
319
  )}
320
+ style={{
321
+ minWidth: width,
322
+ minHeight: height,
323
+ }}
314
324
  >
315
- {children(itemList[index] as AnyObject)}
325
+ {itemList[index]?.item ? (
326
+ children(itemList[index] as AnyObject)
327
+ ) : (
328
+ <Skeleton className="p-2" />
329
+ )}
316
330
  </div>
317
331
  ))}
318
332
  </div>