@sheinx/hooks 3.2.0-beta.1 → 3.2.0-beta.3
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +9 -2
- package/cjs/components/use-menu/use-menu-item.d.ts +1 -0
- package/cjs/components/use-menu/use-menu-item.d.ts.map +1 -1
- package/cjs/components/use-menu/use-menu-item.js +44 -36
- package/cjs/components/use-menu/use-menu.d.ts.map +1 -1
- package/cjs/components/use-menu/use-menu.js +12 -2
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +9 -2
- package/esm/components/use-menu/use-menu-item.d.ts +1 -0
- package/esm/components/use-menu/use-menu-item.d.ts.map +1 -1
- package/esm/components/use-menu/use-menu-item.js +44 -36
- package/esm/components/use-menu/use-menu.d.ts.map +1 -1
- package/esm/components/use-menu/use-menu.js +12 -2
- package/package.json +1 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAiU7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -384,6 +384,13 @@ var useForm = function useForm(props) {
|
|
384
384
|
size: size
|
385
385
|
};
|
386
386
|
}, [labelWidth, labelAlign, labelVerticalAlign, keepErrorHeight, inline, disabled, size]);
|
387
|
+
var updateValue = function updateValue() {
|
388
|
+
if (props.value !== context.lastValue && props.value !== context.value) {
|
389
|
+
context.value = (0, _utils.deepClone)(props.value) || emptyObj;
|
390
|
+
context.lastValue = props.value;
|
391
|
+
}
|
392
|
+
};
|
393
|
+
updateValue();
|
387
394
|
React.useEffect(function () {
|
388
395
|
// 服务端错误更新
|
389
396
|
if (!props.error) context.serverErrors = {};else {
|
@@ -400,8 +407,8 @@ var useForm = function useForm(props) {
|
|
400
407
|
// 默认值更新
|
401
408
|
React.useEffect(function () {
|
402
409
|
context.removeLock = false;
|
403
|
-
|
404
|
-
|
410
|
+
// 内部 onChange 改的 value, 不需要更新
|
411
|
+
if (props.value === context.value) return;
|
405
412
|
if (initValidate && !context.resetTime) {
|
406
413
|
var keys = Object.keys(context.validateMap).filter(function (key) {
|
407
414
|
var oldValue = (0, _utils.deepGet)(context.lastValue || emptyObj, key);
|
@@ -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;;;;;;;;
|
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
|
-
|
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
|
-
|
76
|
-
if (!isLeaf)
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
113
|
-
|
114
|
-
}
|
115
|
-
var
|
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
|
-
|
128
|
+
up = rect.bottom - topLine > (bottomLine - topLine) / 2;
|
124
129
|
}
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
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:
|
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;;
|
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
|
-
|
88
|
+
updateWithThreshold();
|
79
89
|
});
|
80
90
|
return {
|
81
91
|
openKeys: value,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAuBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAsJ8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCA6CD,OAAO;;6BALb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;;;;;oBAmDnD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCA6CD,OAAO;;yBALb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;;CAiU7F,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -375,6 +375,13 @@ var useForm = function useForm(props) {
|
|
375
375
|
size: size
|
376
376
|
};
|
377
377
|
}, [labelWidth, labelAlign, labelVerticalAlign, keepErrorHeight, inline, disabled, size]);
|
378
|
+
var updateValue = function updateValue() {
|
379
|
+
if (props.value !== context.lastValue && props.value !== context.value) {
|
380
|
+
context.value = deepClone(props.value) || emptyObj;
|
381
|
+
context.lastValue = props.value;
|
382
|
+
}
|
383
|
+
};
|
384
|
+
updateValue();
|
378
385
|
React.useEffect(function () {
|
379
386
|
// 服务端错误更新
|
380
387
|
if (!props.error) context.serverErrors = {};else {
|
@@ -391,8 +398,8 @@ var useForm = function useForm(props) {
|
|
391
398
|
// 默认值更新
|
392
399
|
React.useEffect(function () {
|
393
400
|
context.removeLock = false;
|
394
|
-
|
395
|
-
|
401
|
+
// 内部 onChange 改的 value, 不需要更新
|
402
|
+
if (props.value === context.value) return;
|
396
403
|
if (initValidate && !context.resetTime) {
|
397
404
|
var keys = Object.keys(context.validateMap).filter(function (key) {
|
398
405
|
var oldValue = deepGet(context.lastValue || emptyObj, key);
|
@@ -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;;;;;;;;
|
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
|
-
|
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
|
-
|
69
|
-
if (!isLeaf)
|
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
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
106
|
-
|
107
|
-
}
|
108
|
-
var
|
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
|
-
|
121
|
+
up = rect.bottom - topLine > (bottomLine - topLine) / 2;
|
117
122
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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:
|
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;;
|
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
|
-
|
81
|
+
updateWithThreshold();
|
72
82
|
});
|
73
83
|
return {
|
74
84
|
openKeys: value,
|