@sheinx/hooks 3.6.6 → 3.6.7-beta.1
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/cjs/components/use-popup/popup-context.d.ts +2 -0
- package/cjs/components/use-popup/popup-context.d.ts.map +1 -1
- package/cjs/components/use-popup/popup-context.js +2 -0
- package/cjs/components/use-popup/use-popup.d.ts +4 -0
- package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
- package/cjs/components/use-popup/use-popup.js +33 -8
- package/esm/components/use-popup/popup-context.d.ts +2 -0
- package/esm/components/use-popup/popup-context.d.ts.map +1 -1
- package/esm/components/use-popup/popup-context.js +2 -0
- package/esm/components/use-popup/use-popup.d.ts +4 -0
- package/esm/components/use-popup/use-popup.d.ts.map +1 -1
- package/esm/components/use-popup/use-popup.js +34 -9
- package/package.json +1 -1
@@ -1,5 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
declare const context: React.Context<{
|
3
|
+
addParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
4
|
+
removeParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
3
5
|
bindChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
4
6
|
removeChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
5
7
|
}>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"popup-context.d.ts","sourceRoot":"","sources":["popup-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"popup-context.d.ts","sourceRoot":"","sources":["popup-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAS7C,QAAA,MAAM,OAAO;sBANO,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;yBACvC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;sBAC7C,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;wBACxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;EAGnB,CAAC;AAE9C,eAAe,OAAO,CAAC"}
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
exports.default = void 0;
|
8
8
|
var _react = require("react");
|
9
9
|
var defaultContext = {
|
10
|
+
addParent: function addParent(_ref) {},
|
11
|
+
removeParent: function removeParent(_ref) {},
|
10
12
|
bindChild: function bindChild(_ref) {},
|
11
13
|
removeChild: function removeChild(_ref) {}
|
12
14
|
};
|
@@ -39,10 +39,14 @@ declare const usePopup: (props: BasePopupProps) => {
|
|
39
39
|
openPop: () => void;
|
40
40
|
closePop: () => void;
|
41
41
|
Provider: React.Provider<{
|
42
|
+
addParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
43
|
+
removeParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
42
44
|
bindChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
43
45
|
removeChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
44
46
|
}>;
|
45
47
|
providerValue: {
|
48
|
+
addParent: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
49
|
+
removeParent: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
46
50
|
bindChild: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
47
51
|
removeChild: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
48
52
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA4E,MAAM,OAAO,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhE,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;;0BAkIK;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;0BAM9B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;qBA5B7B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;2BApFzC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;8BAOvC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;2BA2JxD,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;6BAMxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;;CA8BlE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
@@ -34,21 +34,32 @@ var usePopup = function usePopup(props) {
|
|
34
34
|
setOpenState = _useState2[1];
|
35
35
|
var _useContext = (0, _react.useContext)(_popupContext.default),
|
36
36
|
bindChild = _useContext.bindChild,
|
37
|
-
removeChild = _useContext.removeChild
|
37
|
+
removeChild = _useContext.removeChild,
|
38
|
+
addParent = _useContext.addParent,
|
39
|
+
removeParent = _useContext.removeParent;
|
38
40
|
var targetRef = (0, _react.useRef)(null);
|
39
41
|
var popupRef = (0, _react.useRef)(null);
|
40
|
-
(0, _react.useEffect)(function () {
|
41
|
-
bindChild(popupRef);
|
42
|
-
return function () {
|
43
|
-
removeChild(popupRef);
|
44
|
-
};
|
45
|
-
}, []);
|
46
42
|
var _useRef = (0, _react.useRef)({
|
47
43
|
triggerTimer: null,
|
48
44
|
// 记录所有的子popup 点击子 popup 不关闭弹窗
|
49
45
|
chain: [targetRef, popupRef]
|
50
46
|
}),
|
51
47
|
context = _useRef.current;
|
48
|
+
var handleAddParent = function handleAddParent(elRef) {
|
49
|
+
context.chain.push(elRef);
|
50
|
+
|
51
|
+
// 继续向上添加当前的 popupRef 到父级
|
52
|
+
addParent(elRef);
|
53
|
+
};
|
54
|
+
var handleRemoveParent = function handleRemoveParent(elRef) {
|
55
|
+
var index = context.chain.findIndex(function (item) {
|
56
|
+
return item === elRef;
|
57
|
+
});
|
58
|
+
if (index > -1) {
|
59
|
+
context.chain.splice(index, 1);
|
60
|
+
removeParent(elRef);
|
61
|
+
}
|
62
|
+
};
|
52
63
|
var open = openState;
|
53
64
|
var changeOpen = function changeOpen(openIn, delay) {
|
54
65
|
if (context.triggerTimer) clearTimeout(context.triggerTimer);
|
@@ -182,8 +193,13 @@ var usePopup = function usePopup(props) {
|
|
182
193
|
});
|
183
194
|
var providerValue = (0, _react.useMemo)(function () {
|
184
195
|
return {
|
196
|
+
addParent: handleAddParent,
|
197
|
+
removeParent: handleRemoveParent,
|
185
198
|
bindChild: function bindChild(elRef) {
|
186
|
-
|
199
|
+
if (elRef.current) {
|
200
|
+
addParent(elRef);
|
201
|
+
context.chain.push(elRef);
|
202
|
+
}
|
187
203
|
},
|
188
204
|
removeChild: function removeChild(elRef) {
|
189
205
|
var index = context.chain.findIndex(function (item) {
|
@@ -191,10 +207,19 @@ var usePopup = function usePopup(props) {
|
|
191
207
|
});
|
192
208
|
if (index > -1) {
|
193
209
|
context.chain.splice(index, 1);
|
210
|
+
removeParent(elRef);
|
194
211
|
}
|
195
212
|
}
|
196
213
|
};
|
197
214
|
}, []);
|
215
|
+
(0, _react.useLayoutEffect)(function () {
|
216
|
+
if (open) {
|
217
|
+
bindChild(popupRef);
|
218
|
+
}
|
219
|
+
return function () {
|
220
|
+
removeChild(popupRef);
|
221
|
+
};
|
222
|
+
}, [open]);
|
198
223
|
return {
|
199
224
|
open: open,
|
200
225
|
position: position,
|
@@ -1,5 +1,7 @@
|
|
1
1
|
import React from 'react';
|
2
2
|
declare const context: React.Context<{
|
3
|
+
addParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
4
|
+
removeParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
3
5
|
bindChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
4
6
|
removeChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
5
7
|
}>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"popup-context.d.ts","sourceRoot":"","sources":["popup-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"popup-context.d.ts","sourceRoot":"","sources":["popup-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAwB,MAAM,OAAO,CAAC;AAS7C,QAAA,MAAM,OAAO;sBANO,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;yBACvC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;sBAC7C,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;wBACxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;EAGnB,CAAC;AAE9C,eAAe,OAAO,CAAC"}
|
@@ -39,10 +39,14 @@ declare const usePopup: (props: BasePopupProps) => {
|
|
39
39
|
openPop: () => void;
|
40
40
|
closePop: () => void;
|
41
41
|
Provider: React.Provider<{
|
42
|
+
addParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
43
|
+
removeParent: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
42
44
|
bindChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
43
45
|
removeChild: (_ref: React.MutableRefObject<HTMLElement | null>) => void;
|
44
46
|
}>;
|
45
47
|
providerValue: {
|
48
|
+
addParent: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
49
|
+
removeParent: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
46
50
|
bindChild: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
47
51
|
removeChild: (elRef: React.MutableRefObject<HTMLElement | null>) => void;
|
48
52
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,
|
1
|
+
{"version":3,"file":"use-popup.d.ts","sourceRoot":"","sources":["use-popup.ts"],"names":[],"mappings":"AAAA,OAAO,KAA4E,MAAM,OAAO,CAAC;AACjG,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAOhE,QAAA,MAAM,QAAQ,UAAW,cAAc;;;;;;0BAkIK;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;0BAM9B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;qBA5B7B;YAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAAA;SAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;2BApFzC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;8BAOvC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;2BA2JxD,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;6BAMxC,MAAM,gBAAgB,CAAC,WAAW,GAAG,IAAI,CAAC;;CA8BlE,CAAC;AAEF,eAAe,QAAQ,CAAC"}
|
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
4
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
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
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
7
|
-
import { useContext,
|
7
|
+
import { useContext, useLayoutEffect, useEffect, useRef, useState, useMemo } from 'react';
|
8
8
|
import useClickAway from "../../common/use-click-away";
|
9
9
|
import { getPosition } from "../../utils/position";
|
10
10
|
import usePersistFn from "../../common/use-persist-fn";
|
@@ -27,21 +27,32 @@ var usePopup = function usePopup(props) {
|
|
27
27
|
setOpenState = _useState2[1];
|
28
28
|
var _useContext = useContext(popupContext),
|
29
29
|
bindChild = _useContext.bindChild,
|
30
|
-
removeChild = _useContext.removeChild
|
30
|
+
removeChild = _useContext.removeChild,
|
31
|
+
addParent = _useContext.addParent,
|
32
|
+
removeParent = _useContext.removeParent;
|
31
33
|
var targetRef = useRef(null);
|
32
34
|
var popupRef = useRef(null);
|
33
|
-
useEffect(function () {
|
34
|
-
bindChild(popupRef);
|
35
|
-
return function () {
|
36
|
-
removeChild(popupRef);
|
37
|
-
};
|
38
|
-
}, []);
|
39
35
|
var _useRef = useRef({
|
40
36
|
triggerTimer: null,
|
41
37
|
// 记录所有的子popup 点击子 popup 不关闭弹窗
|
42
38
|
chain: [targetRef, popupRef]
|
43
39
|
}),
|
44
40
|
context = _useRef.current;
|
41
|
+
var handleAddParent = function handleAddParent(elRef) {
|
42
|
+
context.chain.push(elRef);
|
43
|
+
|
44
|
+
// 继续向上添加当前的 popupRef 到父级
|
45
|
+
addParent(elRef);
|
46
|
+
};
|
47
|
+
var handleRemoveParent = function handleRemoveParent(elRef) {
|
48
|
+
var index = context.chain.findIndex(function (item) {
|
49
|
+
return item === elRef;
|
50
|
+
});
|
51
|
+
if (index > -1) {
|
52
|
+
context.chain.splice(index, 1);
|
53
|
+
removeParent(elRef);
|
54
|
+
}
|
55
|
+
};
|
45
56
|
var open = openState;
|
46
57
|
var changeOpen = function changeOpen(openIn, delay) {
|
47
58
|
if (context.triggerTimer) clearTimeout(context.triggerTimer);
|
@@ -175,8 +186,13 @@ var usePopup = function usePopup(props) {
|
|
175
186
|
});
|
176
187
|
var providerValue = useMemo(function () {
|
177
188
|
return {
|
189
|
+
addParent: handleAddParent,
|
190
|
+
removeParent: handleRemoveParent,
|
178
191
|
bindChild: function bindChild(elRef) {
|
179
|
-
|
192
|
+
if (elRef.current) {
|
193
|
+
addParent(elRef);
|
194
|
+
context.chain.push(elRef);
|
195
|
+
}
|
180
196
|
},
|
181
197
|
removeChild: function removeChild(elRef) {
|
182
198
|
var index = context.chain.findIndex(function (item) {
|
@@ -184,10 +200,19 @@ var usePopup = function usePopup(props) {
|
|
184
200
|
});
|
185
201
|
if (index > -1) {
|
186
202
|
context.chain.splice(index, 1);
|
203
|
+
removeParent(elRef);
|
187
204
|
}
|
188
205
|
}
|
189
206
|
};
|
190
207
|
}, []);
|
208
|
+
useLayoutEffect(function () {
|
209
|
+
if (open) {
|
210
|
+
bindChild(popupRef);
|
211
|
+
}
|
212
|
+
return function () {
|
213
|
+
removeChild(popupRef);
|
214
|
+
};
|
215
|
+
}, [open]);
|
191
216
|
return {
|
192
217
|
open: open,
|
193
218
|
position: position,
|