@sheinx/hooks 3.1.27 → 3.2.0-beta.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAMnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB,wBAsO3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAMnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB,wBAqO3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -11,6 +11,7 @@ declare const useMenuItem: (props: UseMenuItemProps) => {
11
11
  handleMouseEnter: (e: React.MouseEvent) => void;
12
12
  handleMouseLeave: () => void;
13
13
  handleExpandClick: (e: React.MouseEvent) => void;
14
+ isLeaf: boolean;
14
15
  };
15
16
  export default useMenuItem;
16
17
  //# sourceMappingURL=use-menu-item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu-item.d.ts","sourceRoot":"","sources":["use-menu-item.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAEpE,QAAA,MAAM,WAAW,UAAW,gBAAgB;;;;;;;;yBA4BD,gBAAgB;0BA2Df,gBAAgB;;2BAhCf,gBAAgB;CA6E5D,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-menu-item.d.ts","sourceRoot":"","sources":["use-menu-item.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAEpE,QAAA,MAAM,WAAW,UAAW,gBAAgB;;;;;;;;yBA8BD,gBAAgB;0BA8Df,gBAAgB;;2BAhCf,gBAAgB;;CAgF5D,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -17,15 +17,13 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
17
  var useMenuItem = function useMenuItem(props) {
18
18
  var _useRef = (0, _react.useRef)({
19
19
  id: '',
20
- timer: null,
21
- isUp: false
20
+ timer: null
22
21
  }),
23
22
  context = _useRef.current;
24
23
  var _props$parentId = props.parentId,
25
24
  parentId = _props$parentId === void 0 ? '' : _props$parentId,
26
- dataItem = props.dataItem,
27
- _props$toggleDuration = props.toggleDuration,
28
- toggleDuration = _props$toggleDuration === void 0 ? 200 : _props$toggleDuration;
25
+ dataItem = props.dataItem;
26
+ var isLeaf = ((dataItem || {}).children || []).length === 0;
29
27
  if (!context.id) {
30
28
  context.id = "".concat(parentId, ",").concat((0, _uid.getUidStr)());
31
29
  }
@@ -40,6 +38,10 @@ var useMenuItem = function useMenuItem(props) {
40
38
  _useState4 = _slicedToArray(_useState3, 2),
41
39
  isInPath = _useState4[0],
42
40
  setInPath = _useState4[1];
41
+ var _useState5 = (0, _react.useState)(false),
42
+ _useState6 = _slicedToArray(_useState5, 2),
43
+ isUp = _useState6[0],
44
+ setIsUp = _useState6[1];
43
45
  var update = (0, _usePersistFn.default)(function (getStatus) {
44
46
  var status = getStatus(context.id, props.dataItem);
45
47
  if (isChecked !== status.isChecked) {
@@ -72,8 +74,11 @@ var useMenuItem = function useMenuItem(props) {
72
74
  props.onClick(dataItem);
73
75
  }
74
76
  }
75
- var isLeaf = ((dataItem || {}).children || []).length === 0;
76
- if (!isLeaf) e.nativeEvent.stopImmediatePropagation();
77
+ // 阻止冒泡
78
+ if (!isLeaf) {
79
+ e.stopPropagation();
80
+ e.nativeEvent.stopImmediatePropagation();
81
+ }
77
82
  });
78
83
  var handleExpandClick = (0, _usePersistFn.default)(function (e) {
79
84
  e.stopPropagation();
@@ -90,29 +95,29 @@ var useMenuItem = function useMenuItem(props) {
90
95
  }
91
96
  });
92
97
  var handleMouseLeave = (0, _usePersistFn.default)(function () {
93
- if (expandAble && props.mode !== 'inline') {
94
- if (context.timer) {
95
- clearTimeout(context.timer);
96
- context.timer = null;
97
- }
98
- context.timer = setTimeout(function () {
99
- props.onOpenChange(function (before) {
100
- var openKeySet = new Set(before);
101
- openKeySet.delete(props.keyResult);
102
- return Array.from(openKeySet);
103
- });
104
- }, toggleDuration);
105
- document.removeEventListener('click', handleMouseLeave);
106
- }
98
+ // if (expandAble && props.mode !== 'inline') {
99
+ // if (context.timer) {
100
+ // clearTimeout(context.timer);
101
+ // context.timer = null;
102
+ // }
103
+ // context.timer = setTimeout(() => {
104
+ // props.onOpenChange((before) => {
105
+ // const openKeySet = new Set(before);
106
+ // openKeySet.delete(props.keyResult);
107
+ // return Array.from(openKeySet);
108
+ // });
109
+ // }, toggleDuration);
110
+ // document.removeEventListener('click', handleMouseLeave);
111
+ // }
107
112
  });
108
113
  var handleMouseEnter = (0, _usePersistFn.default)(function (e) {
109
114
  if (expandAble && props.mode !== 'inline') {
110
115
  var _props$scrollRef;
111
- if (context.timer) {
112
- clearTimeout(context.timer);
113
- context.timer = null;
114
- }
115
- var isUp = false;
116
+ // if (context.timer) {
117
+ // clearTimeout(context.timer);
118
+ // context.timer = null;
119
+ // }
120
+ var up = false;
116
121
  if (props.mode === 'vertical-auto' && (_props$scrollRef = props.scrollRef) !== null && _props$scrollRef !== void 0 && _props$scrollRef.current) {
117
122
  var _props$scrollRef$curr;
118
123
  var target = e.currentTarget;
@@ -120,15 +125,17 @@ var useMenuItem = function useMenuItem(props) {
120
125
  var scrollRect = (_props$scrollRef$curr = props.scrollRef.current) === null || _props$scrollRef$curr === void 0 ? void 0 : _props$scrollRef$curr.getBoundingClientRect();
121
126
  var topLine = scrollRect === null || scrollRect === void 0 ? void 0 : scrollRect.top;
122
127
  var bottomLine = scrollRect === null || scrollRect === void 0 ? void 0 : scrollRect.bottom;
123
- isUp = rect.bottom - topLine > (bottomLine - topLine) / 2;
128
+ up = rect.bottom - topLine > (bottomLine - topLine) / 2;
124
129
  }
125
- context.isUp = isUp;
126
- props.onOpenChange(function (before) {
127
- var openKeySet = new Set(before);
128
- openKeySet.add(props.keyResult);
129
- return Array.from(openKeySet);
130
- });
131
- document.addEventListener('click', handleMouseLeave);
130
+ if (isUp !== up) {
131
+ setIsUp(up);
132
+ }
133
+ // props.onOpenChange((before) => {
134
+ // const openKeySet = new Set(before);
135
+ // openKeySet.add(props.keyResult);
136
+ // return Array.from(openKeySet);
137
+ // });
138
+ // document.addEventListener('click', handleMouseLeave);
132
139
  }
133
140
  });
134
141
  (0, _react.useEffect)(function () {
@@ -144,11 +151,12 @@ var useMenuItem = function useMenuItem(props) {
144
151
  isOpen: gopenKeySet.has(props.keyResult),
145
152
  isDisabled: isDisabled,
146
153
  expandAble: expandAble,
147
- isUp: context.isUp,
154
+ isUp: isUp,
148
155
  handleItemClick: handleItemClick,
149
156
  handleMouseEnter: handleMouseEnter,
150
157
  handleMouseLeave: handleMouseLeave,
151
- handleExpandClick: handleExpandClick
158
+ handleExpandClick: handleExpandClick,
159
+ isLeaf: isLeaf
152
160
  };
153
161
  };
154
162
  var _default = exports.default = useMenuItem;
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu.d.ts","sourceRoot":"","sources":["use-menu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,QAAA,MAAM,OAAO,UAAW,YAAY;;gCAwBgB,YAAY,EAAE,KAAK,YAAY,EAAE;qBAyC3D,MAAM,cAAc,UAAU;uBAI5B,MAAM;yBA5DS,MAAM;CA0EhD,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-menu.d.ts","sourceRoot":"","sources":["use-menu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,QAAA,MAAM,OAAO,UAAW,YAAY;;gCAyBgB,YAAY,EAAE,KAAK,YAAY,EAAE;qBAkD3D,MAAM,cAAc,UAAU;uBAK5B,MAAM;yBAtES,MAAM;CAqFhD,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -13,7 +13,8 @@ var useMenu = function useMenu(props) {
13
13
  var _useRef = (0, _react.useRef)({
14
14
  updateMap: new Map(),
15
15
  activeId: '',
16
- cachedOpenKeys: props.openKeys || []
16
+ cachedOpenKeys: props.openKeys || [],
17
+ updateTimer: 0
17
18
  }),
18
19
  context = _useRef.current;
19
20
  var render = (0, _useRender.default)();
@@ -68,14 +69,23 @@ var useMenu = function useMenu(props) {
68
69
  updateItem(getStatus);
69
70
  });
70
71
  });
72
+ var updateWithThreshold = (0, _usePersistFn.default)(function () {
73
+ if (context.updateTimer) clearTimeout(context.updateTimer);
74
+ context.updateTimer = window.setTimeout(function () {
75
+ update();
76
+ // 需要更新两次 否则 inPath 状态错误
77
+ update();
78
+ }, 50);
79
+ });
71
80
  var bindUpdate = function bindUpdate(id, updateItem) {
72
81
  context.updateMap.set(id, updateItem);
82
+ updateWithThreshold();
73
83
  };
74
84
  var unbindUpdate = function unbindUpdate(id) {
75
85
  context.updateMap.delete(id);
76
86
  };
77
87
  (0, _react.useEffect)(function () {
78
- update();
88
+ updateWithThreshold();
79
89
  });
80
90
  return {
81
91
  openKeys: value,
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAMnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB,wBAsO3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAMnD,MAAM,MAAM,kBAAkB,GAC1B,aAAa,GACb,UAAU,GACV,cAAc,GACd,WAAW,GACX,MAAM,GACN,OAAO,CAAC;AACZ,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,cAAc,GACd,UAAU,GACV,WAAW,GACX,KAAK,GACL,QAAQ,CAAC;AAYb,KAAK,YAAY,GAAG,kBAAkB,GAAG,gBAAgB,GAAG,OAAO,CAAC;AACpE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,YAAY,GAAG,SAAS,CAAC;IACnC,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,OAAO,CAAC;IAEd,WAAW,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAE1C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAEzC,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IAC3C,YAAY,EAAE,MAAM,WAAW,GAAG,IAAI,GAAG,SAAS,CAAC;IACnD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,GAAG,KAAK,CAAC;IAC7B,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAQD,eAAO,MAAM,gBAAgB,WAAY,mBAAmB,wBAqO3D,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -11,6 +11,7 @@ declare const useMenuItem: (props: UseMenuItemProps) => {
11
11
  handleMouseEnter: (e: React.MouseEvent) => void;
12
12
  handleMouseLeave: () => void;
13
13
  handleExpandClick: (e: React.MouseEvent) => void;
14
+ isLeaf: boolean;
14
15
  };
15
16
  export default useMenuItem;
16
17
  //# sourceMappingURL=use-menu-item.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu-item.d.ts","sourceRoot":"","sources":["use-menu-item.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAEpE,QAAA,MAAM,WAAW,UAAW,gBAAgB;;;;;;;;yBA4BD,gBAAgB;0BA2Df,gBAAgB;;2BAhCf,gBAAgB;CA6E5D,CAAC;AAEF,eAAe,WAAW,CAAC"}
1
+ {"version":3,"file":"use-menu-item.d.ts","sourceRoot":"","sources":["use-menu-item.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,iBAAiB,CAAC;AAEpE,QAAA,MAAM,WAAW,UAAW,gBAAgB;;;;;;;;yBA8BD,gBAAgB;0BA8Df,gBAAgB;;2BAhCf,gBAAgB;;CAgF5D,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -10,15 +10,13 @@ import { getUidStr } from "../../utils/uid";
10
10
  var useMenuItem = function useMenuItem(props) {
11
11
  var _useRef = useRef({
12
12
  id: '',
13
- timer: null,
14
- isUp: false
13
+ timer: null
15
14
  }),
16
15
  context = _useRef.current;
17
16
  var _props$parentId = props.parentId,
18
17
  parentId = _props$parentId === void 0 ? '' : _props$parentId,
19
- dataItem = props.dataItem,
20
- _props$toggleDuration = props.toggleDuration,
21
- toggleDuration = _props$toggleDuration === void 0 ? 200 : _props$toggleDuration;
18
+ dataItem = props.dataItem;
19
+ var isLeaf = ((dataItem || {}).children || []).length === 0;
22
20
  if (!context.id) {
23
21
  context.id = "".concat(parentId, ",").concat(getUidStr());
24
22
  }
@@ -33,6 +31,10 @@ var useMenuItem = function useMenuItem(props) {
33
31
  _useState4 = _slicedToArray(_useState3, 2),
34
32
  isInPath = _useState4[0],
35
33
  setInPath = _useState4[1];
34
+ var _useState5 = useState(false),
35
+ _useState6 = _slicedToArray(_useState5, 2),
36
+ isUp = _useState6[0],
37
+ setIsUp = _useState6[1];
36
38
  var update = usePersistFn(function (getStatus) {
37
39
  var status = getStatus(context.id, props.dataItem);
38
40
  if (isChecked !== status.isChecked) {
@@ -65,8 +67,11 @@ var useMenuItem = function useMenuItem(props) {
65
67
  props.onClick(dataItem);
66
68
  }
67
69
  }
68
- var isLeaf = ((dataItem || {}).children || []).length === 0;
69
- if (!isLeaf) e.nativeEvent.stopImmediatePropagation();
70
+ // 阻止冒泡
71
+ if (!isLeaf) {
72
+ e.stopPropagation();
73
+ e.nativeEvent.stopImmediatePropagation();
74
+ }
70
75
  });
71
76
  var handleExpandClick = usePersistFn(function (e) {
72
77
  e.stopPropagation();
@@ -83,29 +88,29 @@ var useMenuItem = function useMenuItem(props) {
83
88
  }
84
89
  });
85
90
  var handleMouseLeave = usePersistFn(function () {
86
- if (expandAble && props.mode !== 'inline') {
87
- if (context.timer) {
88
- clearTimeout(context.timer);
89
- context.timer = null;
90
- }
91
- context.timer = setTimeout(function () {
92
- props.onOpenChange(function (before) {
93
- var openKeySet = new Set(before);
94
- openKeySet.delete(props.keyResult);
95
- return Array.from(openKeySet);
96
- });
97
- }, toggleDuration);
98
- document.removeEventListener('click', handleMouseLeave);
99
- }
91
+ // if (expandAble && props.mode !== 'inline') {
92
+ // if (context.timer) {
93
+ // clearTimeout(context.timer);
94
+ // context.timer = null;
95
+ // }
96
+ // context.timer = setTimeout(() => {
97
+ // props.onOpenChange((before) => {
98
+ // const openKeySet = new Set(before);
99
+ // openKeySet.delete(props.keyResult);
100
+ // return Array.from(openKeySet);
101
+ // });
102
+ // }, toggleDuration);
103
+ // document.removeEventListener('click', handleMouseLeave);
104
+ // }
100
105
  });
101
106
  var handleMouseEnter = usePersistFn(function (e) {
102
107
  if (expandAble && props.mode !== 'inline') {
103
108
  var _props$scrollRef;
104
- if (context.timer) {
105
- clearTimeout(context.timer);
106
- context.timer = null;
107
- }
108
- var isUp = false;
109
+ // if (context.timer) {
110
+ // clearTimeout(context.timer);
111
+ // context.timer = null;
112
+ // }
113
+ var up = false;
109
114
  if (props.mode === 'vertical-auto' && (_props$scrollRef = props.scrollRef) !== null && _props$scrollRef !== void 0 && _props$scrollRef.current) {
110
115
  var _props$scrollRef$curr;
111
116
  var target = e.currentTarget;
@@ -113,15 +118,17 @@ var useMenuItem = function useMenuItem(props) {
113
118
  var scrollRect = (_props$scrollRef$curr = props.scrollRef.current) === null || _props$scrollRef$curr === void 0 ? void 0 : _props$scrollRef$curr.getBoundingClientRect();
114
119
  var topLine = scrollRect === null || scrollRect === void 0 ? void 0 : scrollRect.top;
115
120
  var bottomLine = scrollRect === null || scrollRect === void 0 ? void 0 : scrollRect.bottom;
116
- isUp = rect.bottom - topLine > (bottomLine - topLine) / 2;
121
+ up = rect.bottom - topLine > (bottomLine - topLine) / 2;
117
122
  }
118
- context.isUp = isUp;
119
- props.onOpenChange(function (before) {
120
- var openKeySet = new Set(before);
121
- openKeySet.add(props.keyResult);
122
- return Array.from(openKeySet);
123
- });
124
- document.addEventListener('click', handleMouseLeave);
123
+ if (isUp !== up) {
124
+ setIsUp(up);
125
+ }
126
+ // props.onOpenChange((before) => {
127
+ // const openKeySet = new Set(before);
128
+ // openKeySet.add(props.keyResult);
129
+ // return Array.from(openKeySet);
130
+ // });
131
+ // document.addEventListener('click', handleMouseLeave);
125
132
  }
126
133
  });
127
134
  useEffect(function () {
@@ -137,11 +144,12 @@ var useMenuItem = function useMenuItem(props) {
137
144
  isOpen: gopenKeySet.has(props.keyResult),
138
145
  isDisabled: isDisabled,
139
146
  expandAble: expandAble,
140
- isUp: context.isUp,
147
+ isUp: isUp,
141
148
  handleItemClick: handleItemClick,
142
149
  handleMouseEnter: handleMouseEnter,
143
150
  handleMouseLeave: handleMouseLeave,
144
- handleExpandClick: handleExpandClick
151
+ handleExpandClick: handleExpandClick,
152
+ isLeaf: isLeaf
145
153
  };
146
154
  };
147
155
  export default useMenuItem;
@@ -1 +1 @@
1
- {"version":3,"file":"use-menu.d.ts","sourceRoot":"","sources":["use-menu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,QAAA,MAAM,OAAO,UAAW,YAAY;;gCAwBgB,YAAY,EAAE,KAAK,YAAY,EAAE;qBAyC3D,MAAM,cAAc,UAAU;uBAI5B,MAAM;yBA5DS,MAAM;CA0EhD,CAAC;AAEF,eAAe,OAAO,CAAC"}
1
+ {"version":3,"file":"use-menu.d.ts","sourceRoot":"","sources":["use-menu.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAChE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD,QAAA,MAAM,OAAO,UAAW,YAAY;;gCAyBgB,YAAY,EAAE,KAAK,YAAY,EAAE;qBAkD3D,MAAM,cAAc,UAAU;uBAK5B,MAAM;yBAtES,MAAM;CAqFhD,CAAC;AAEF,eAAe,OAAO,CAAC"}
@@ -6,7 +6,8 @@ var useMenu = function useMenu(props) {
6
6
  var _useRef = useRef({
7
7
  updateMap: new Map(),
8
8
  activeId: '',
9
- cachedOpenKeys: props.openKeys || []
9
+ cachedOpenKeys: props.openKeys || [],
10
+ updateTimer: 0
10
11
  }),
11
12
  context = _useRef.current;
12
13
  var render = useRender();
@@ -61,14 +62,23 @@ var useMenu = function useMenu(props) {
61
62
  updateItem(getStatus);
62
63
  });
63
64
  });
65
+ var updateWithThreshold = usePersistFn(function () {
66
+ if (context.updateTimer) clearTimeout(context.updateTimer);
67
+ context.updateTimer = window.setTimeout(function () {
68
+ update();
69
+ // 需要更新两次 否则 inPath 状态错误
70
+ update();
71
+ }, 50);
72
+ });
64
73
  var bindUpdate = function bindUpdate(id, updateItem) {
65
74
  context.updateMap.set(id, updateItem);
75
+ updateWithThreshold();
66
76
  };
67
77
  var unbindUpdate = function unbindUpdate(id) {
68
78
  context.updateMap.delete(id);
69
79
  };
70
80
  useEffect(function () {
71
- update();
81
+ updateWithThreshold();
72
82
  });
73
83
  return {
74
84
  openKeys: value,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sheinx/hooks",
3
- "version": "3.1.27",
3
+ "version": "3.2.0-beta.2",
4
4
  "description": "",
5
5
  "keywords": [],
6
6
  "license": "MIT",