@4399ywkf/design 1.3.8 → 1.3.9

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.
@@ -18,7 +18,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
18
18
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
19
19
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
20
  import { useDebounceFn } from 'ahooks';
21
- import { cloneDeep } from 'lodash-es';
21
+ import { cloneDeep, debounce } from 'lodash-es';
22
22
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
23
23
  import "./styles/index.less";
24
24
  import "./styles/test.less";
@@ -202,25 +202,40 @@ var WaterfallVirtual = function WaterfallVirtual(props) {
202
202
  });
203
203
  }, [cardList, scrollPos, isInitialized, overscan]);
204
204
 
205
+ // 在组件顶部添加
206
+ var queueDataRef = useRef(queueData);
207
+
208
+ // 在 queueData 更新时同步 ref
209
+ useEffect(function () {
210
+ queueDataRef.current = queueData;
211
+ }, [queueData]);
212
+
205
213
  // 变更queueData中list的具体高度
206
- var changeQueueDataHeight = useCallback(function (columnIndex, index, height) {
214
+ var changeQueueDataHeight = useCallback(debounce(function (columnIndex, index, height) {
207
215
  setQueueData(function (prev) {
208
- var newQueueData = _toConsumableArray(prev);
209
- var item = newQueueData[columnIndex].list[index];
216
+ // 使用最新的状态进行计算
217
+ var currentData = queueDataRef.current;
218
+
219
+ // 添加边界检查,防止索引越界
220
+ if (!currentData[columnIndex] || !currentData[columnIndex].list[index]) {
221
+ return prev; // 如果索引无效,返回原数据
222
+ }
223
+ var item = currentData[columnIndex].list[index];
210
224
  item.style.height = "".concat(height, "px");
211
225
  item.h = height;
212
226
  var currentHeight = item.y + item.h + gap;
213
227
  // index 之后的item 的 y 需要重新计算
214
- for (var i = index + 1; i < newQueueData[columnIndex].list.length; i++) {
215
- var _item = newQueueData[columnIndex].list[i];
228
+ for (var i = index + 1; i < currentData[columnIndex].list.length; i++) {
229
+ var _item = currentData[columnIndex].list[i];
216
230
  _item.y = currentHeight;
217
231
  currentHeight += _item.h + gap;
218
232
  _item.style.transform = "translate3d(".concat(_item.x, "px, ").concat(_item.y, "px, 0)");
219
233
  }
220
- newQueueData[columnIndex].height = newQueueData[columnIndex].list[newQueueData[columnIndex].list.length - 1].y + newQueueData[columnIndex].list[newQueueData[columnIndex].list.length - 1].h + gap;
221
- return cloneDeep(newQueueData);
234
+ currentData[columnIndex].height = currentData[columnIndex].list[currentData[columnIndex].list.length - 1].y + currentData[columnIndex].list[currentData[columnIndex].list.length - 1].h + gap;
235
+ return cloneDeep(currentData);
222
236
  });
223
- }, [queueData]);
237
+ }, 16), [gap] // 只依赖 gap,移除 queueData 依赖
238
+ );
224
239
 
225
240
  // 初始化滚动状态
226
241
  var initScrollState = useCallback(function () {
@@ -2,3 +2,4 @@ export * from './useCopyData';
2
2
  export * from './useDownloadImage';
3
3
  export * from './useImgToClipboard';
4
4
  export * from './useScreenshot';
5
+ export * from './useScrolling';
@@ -1,4 +1,5 @@
1
1
  export * from "./useCopyData";
2
2
  export * from "./useDownloadImage";
3
3
  export * from "./useImgToClipboard";
4
- export * from "./useScreenshot";
4
+ export * from "./useScreenshot";
5
+ export * from "./useScrolling";
@@ -0,0 +1,2 @@
1
+ import { RefObject } from 'react';
2
+ export declare function useScrolling(ref: RefObject<HTMLElement>, checkInterval?: number): boolean;
@@ -0,0 +1,43 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { useEffect, useRef, useState } from 'react';
8
+ export function useScrolling(ref) {
9
+ var checkInterval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 60;
10
+ var _useState = useState(false),
11
+ _useState2 = _slicedToArray(_useState, 2),
12
+ isScrolling = _useState2[0],
13
+ setIsScrolling = _useState2[1];
14
+ var lastScrollTop = useRef(0);
15
+ var frame = useRef(null);
16
+ var stillCount = useRef(0);
17
+ useEffect(function () {
18
+ var el = ref.current;
19
+ if (!el) return;
20
+ var checkScrolling = function checkScrolling() {
21
+ var current = el.scrollTop;
22
+ if (current !== lastScrollTop.current) {
23
+ if (!isScrolling) setIsScrolling(true);
24
+ lastScrollTop.current = current;
25
+ stillCount.current = 0;
26
+ } else {
27
+ stillCount.current++;
28
+ // 连续几帧没变化,认为停止滚动
29
+ if (isScrolling && stillCount.current >= checkInterval) {
30
+ setIsScrolling(false);
31
+ }
32
+ }
33
+ frame.current = requestAnimationFrame(checkScrolling);
34
+ };
35
+ frame.current = requestAnimationFrame(checkScrolling);
36
+ return function () {
37
+ if (frame.current !== null) {
38
+ cancelAnimationFrame(frame.current);
39
+ }
40
+ };
41
+ }, [ref, isScrolling, checkInterval]);
42
+ return isScrolling;
43
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4399ywkf/design",
3
- "version": "1.3.8",
3
+ "version": "1.3.9",
4
4
  "description": "4399ywkf Design React UI Library.",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",