nhanh-pure-function 1.2.6 → 1.2.8

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/lib/User.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /**
2
- * 滚动触底事件
3
- * @param {触底事件} callback
2
+ * 滚动结束监听器
3
+ * @param {(trigger?: "vertical" | "horizontal") => void} callback
4
4
  */
5
- export function _ScrollBottomListener(
6
- callback: Function
5
+ export function _ScrollEndListener(
6
+ callback: (trigger?: "vertical" | "horizontal") => void
7
7
  ): (payload: Event) => void;
8
8
 
9
9
  /**
@@ -164,7 +164,7 @@ type DragOption = {
164
164
  dragDom?: HTMLElement;
165
165
  };
166
166
  /** 拖拽 */
167
- export class Drag {
167
+ export class _Drag {
168
168
  /**
169
169
  * 初始化拖拽
170
170
  * @param dom 被拖拽的元素
@@ -191,7 +191,7 @@ type LocalDragOptions = {
191
191
  update_up?: (value: UpdateValue) => void | undefined;
192
192
  };
193
193
  /** 局部拖拽 计算位置距离/百分比 */
194
- export class LocalDrag {
194
+ export class _LocalDrag {
195
195
  /**
196
196
  * 初始化拖拽
197
197
  * @param parentDom 被拖拽元素的祖先元素
package/lib/User.js CHANGED
@@ -1,21 +1,46 @@
1
1
  import { _IsObject, _NotNull, _Debounce } from "./Utility";
2
2
 
3
3
  /**
4
- * 滚动触底事件
5
- * @param {触底事件} callback
4
+ * 滚动结束监听器
5
+ * @param {(trigger: "vertical" | "horizontal") => void} callback
6
6
  */
7
- export function _ScrollBottomListener(callback) {
7
+ export function _ScrollEndListener(callback) {
8
8
  const debouncedCallback = _Debounce(callback, 100);
9
9
  let lastScrollTop = 0;
10
+ let lastScrollLeft = 0;
10
11
  return function (payload) {
11
12
  const target = payload.target;
12
- const { scrollTop, scrollHeight, clientHeight } = target;
13
- /** 向上滚动? */
14
- const isUp = lastScrollTop > scrollTop;
15
- lastScrollTop = scrollTop;
16
- if (isUp) return;
17
- const bottom = scrollHeight - scrollTop - clientHeight;
18
- if (bottom <= 1) debouncedCallback();
13
+ if (!target) return;
14
+
15
+ const {
16
+ scrollTop,
17
+ scrollHeight,
18
+ clientHeight,
19
+ scrollLeft,
20
+ scrollWidth,
21
+ clientWidth,
22
+ } = target;
23
+ function vertical() {
24
+ if (lastScrollTop == scrollTop) return;
25
+ /** 向上滚动? */
26
+ const isUp = lastScrollTop > scrollTop;
27
+ lastScrollTop = scrollTop;
28
+ if (isUp) return;
29
+ const bottom = scrollHeight - scrollTop - clientHeight;
30
+ if (bottom <= 1) debouncedCallback("vertical");
31
+ }
32
+ function horizontal() {
33
+ if (lastScrollLeft == scrollLeft) return;
34
+ /** 向左滚动? */
35
+ const isLeft = lastScrollLeft > scrollLeft;
36
+ lastScrollLeft = scrollLeft;
37
+ if (isLeft) return;
38
+ const right = scrollWidth - scrollLeft - clientWidth;
39
+ if (right <= 1) debouncedCallback("horizontal");
40
+ }
41
+
42
+ vertical();
43
+ horizontal();
19
44
  };
20
45
  }
21
46
 
@@ -353,7 +378,7 @@ export function _CloseOnOutsideClick(querySelector, callback, options) {
353
378
  }
354
379
 
355
380
  /** 拖拽dom */
356
- export class Drag {
381
+ export class _Drag {
357
382
  #dom = null;
358
383
  #isAllowed = false;
359
384
  #eventFunction = {};
@@ -433,7 +458,7 @@ export class Drag {
433
458
  }
434
459
 
435
460
  /** 局部拖拽 计算位置距离/百分比 */
436
- export class LocalDrag {
461
+ export class _LocalDrag {
437
462
  #parentDom = null;
438
463
  #isAllowed = false;
439
464
  #eventFunction = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nhanh-pure-function",
3
- "version": "1.2.6",
3
+ "version": "1.2.8",
4
4
  "description": "纯函数工具",
5
5
  "main": "lib/Index.js",
6
6
  "scripts": {