@rc-component/trigger 3.7.0 → 3.7.2
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/es/hooks/useAlign.js +12 -10
- package/es/index.js +4 -15
- package/es/util.js +3 -2
- package/lib/hooks/useAlign.js +12 -10
- package/lib/index.js +4 -15
- package/lib/util.js +3 -2
- package/package.json +1 -1
package/es/hooks/useAlign.js
CHANGED
|
@@ -54,12 +54,12 @@ function reversePoints(points, index) {
|
|
|
54
54
|
l: 'r',
|
|
55
55
|
r: 'l'
|
|
56
56
|
};
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
const clone = [...points];
|
|
58
|
+
clone[index] = reverseMap[points[index]] || 'c';
|
|
59
|
+
return clone;
|
|
60
|
+
}
|
|
61
|
+
function flatPoints(points) {
|
|
62
|
+
return points.join('');
|
|
63
63
|
}
|
|
64
64
|
export default function useAlign(open, popupEle, target, placement, builtinPlacements, popupAlign, onPopupAlign, mobile) {
|
|
65
65
|
const [offsetInfo, setOffsetInfo] = React.useState({
|
|
@@ -245,6 +245,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
245
245
|
const nextAlignInfo = {
|
|
246
246
|
...placementInfo
|
|
247
247
|
};
|
|
248
|
+
let nextPoints = [popupPoints, targetPoints];
|
|
248
249
|
|
|
249
250
|
// Next Offset
|
|
250
251
|
let nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
|
|
@@ -322,7 +323,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
322
323
|
prevFlipRef.current.bt = true;
|
|
323
324
|
nextOffsetY = tmpNextOffsetY;
|
|
324
325
|
popupOffsetY = -popupOffsetY;
|
|
325
|
-
|
|
326
|
+
nextPoints = [reversePoints(nextPoints[0], 0), reversePoints(nextPoints[1], 0)];
|
|
326
327
|
} else {
|
|
327
328
|
prevFlipRef.current.bt = false;
|
|
328
329
|
}
|
|
@@ -346,7 +347,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
346
347
|
prevFlipRef.current.tb = true;
|
|
347
348
|
nextOffsetY = tmpNextOffsetY;
|
|
348
349
|
popupOffsetY = -popupOffsetY;
|
|
349
|
-
|
|
350
|
+
nextPoints = [reversePoints(nextPoints[0], 0), reversePoints(nextPoints[1], 0)];
|
|
350
351
|
} else {
|
|
351
352
|
prevFlipRef.current.tb = false;
|
|
352
353
|
}
|
|
@@ -376,7 +377,7 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
376
377
|
prevFlipRef.current.rl = true;
|
|
377
378
|
nextOffsetX = tmpNextOffsetX;
|
|
378
379
|
popupOffsetX = -popupOffsetX;
|
|
379
|
-
|
|
380
|
+
nextPoints = [reversePoints(nextPoints[0], 1), reversePoints(nextPoints[1], 1)];
|
|
380
381
|
} else {
|
|
381
382
|
prevFlipRef.current.rl = false;
|
|
382
383
|
}
|
|
@@ -400,11 +401,12 @@ export default function useAlign(open, popupEle, target, placement, builtinPlace
|
|
|
400
401
|
prevFlipRef.current.lr = true;
|
|
401
402
|
nextOffsetX = tmpNextOffsetX;
|
|
402
403
|
popupOffsetX = -popupOffsetX;
|
|
403
|
-
|
|
404
|
+
nextPoints = [reversePoints(nextPoints[0], 1), reversePoints(nextPoints[1], 1)];
|
|
404
405
|
} else {
|
|
405
406
|
prevFlipRef.current.lr = false;
|
|
406
407
|
}
|
|
407
408
|
}
|
|
409
|
+
nextAlignInfo.points = [flatPoints(nextPoints[0]), flatPoints(nextPoints[1])];
|
|
408
410
|
|
|
409
411
|
// ============================ Shift ============================
|
|
410
412
|
syncNextPopupPosition();
|
package/es/index.js
CHANGED
|
@@ -16,6 +16,7 @@ import useWatch from "./hooks/useWatch";
|
|
|
16
16
|
import useWinClick from "./hooks/useWinClick";
|
|
17
17
|
import { getAlignPopupClassName } from "./util";
|
|
18
18
|
import UniqueProvider from "./UniqueProvider";
|
|
19
|
+
import { useControlledState } from '@rc-component/util';
|
|
19
20
|
export { UniqueProvider };
|
|
20
21
|
|
|
21
22
|
// Removed Props List
|
|
@@ -138,10 +139,8 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
138
139
|
} : null;
|
|
139
140
|
|
|
140
141
|
// ============================ Open ============================
|
|
141
|
-
const [internalOpen, setInternalOpen] =
|
|
142
|
-
|
|
143
|
-
// Render still use props as first priority
|
|
144
|
-
const mergedOpen = popupVisible ?? internalOpen;
|
|
142
|
+
const [internalOpen, setInternalOpen] = useControlledState(defaultPopupVisible || false, popupVisible);
|
|
143
|
+
const mergedOpen = internalOpen || false;
|
|
145
144
|
|
|
146
145
|
// ========================== Children ==========================
|
|
147
146
|
const child = React.useMemo(() => {
|
|
@@ -152,18 +151,8 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
152
151
|
}, [children, mergedOpen]);
|
|
153
152
|
const originChildProps = child?.props || {};
|
|
154
153
|
|
|
155
|
-
// We use effect sync here in case `popupVisible` back to `undefined`
|
|
156
|
-
const setMergedOpen = useEvent(nextOpen => {
|
|
157
|
-
if (openUncontrolled) {
|
|
158
|
-
setInternalOpen(nextOpen);
|
|
159
|
-
}
|
|
160
|
-
});
|
|
161
|
-
|
|
162
154
|
// Support ref
|
|
163
155
|
const isOpen = useEvent(() => mergedOpen);
|
|
164
|
-
useLayoutEffect(() => {
|
|
165
|
-
setInternalOpen(popupVisible || false);
|
|
166
|
-
}, [popupVisible]);
|
|
167
156
|
|
|
168
157
|
// Extract common options for UniqueProvider
|
|
169
158
|
const getUniqueOptions = useEvent((delay = 0) => ({
|
|
@@ -206,7 +195,7 @@ export function generateTrigger(PortalComponent = Portal) {
|
|
|
206
195
|
const lastTriggerRef = React.useRef([]);
|
|
207
196
|
lastTriggerRef.current = [];
|
|
208
197
|
const internalTriggerOpen = useEvent(nextOpen => {
|
|
209
|
-
|
|
198
|
+
setInternalOpen(nextOpen);
|
|
210
199
|
|
|
211
200
|
// Enter or Pointer will both trigger open state change
|
|
212
201
|
// We only need take one to avoid duplicated change event trigger
|
package/es/util.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
|
|
2
|
+
const getVal = (a, index) => a[index] || '';
|
|
2
3
|
if (isAlignPoint) {
|
|
3
|
-
return a1
|
|
4
|
+
return getVal(a1, 0) === getVal(a2, 0);
|
|
4
5
|
}
|
|
5
|
-
return a1
|
|
6
|
+
return getVal(a1, 0) === getVal(a2, 0) && getVal(a1, 1) === getVal(a2, 1);
|
|
6
7
|
}
|
|
7
8
|
export function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
|
|
8
9
|
const {
|
package/lib/hooks/useAlign.js
CHANGED
|
@@ -63,12 +63,12 @@ function reversePoints(points, index) {
|
|
|
63
63
|
l: 'r',
|
|
64
64
|
r: 'l'
|
|
65
65
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
66
|
+
const clone = [...points];
|
|
67
|
+
clone[index] = reverseMap[points[index]] || 'c';
|
|
68
|
+
return clone;
|
|
69
|
+
}
|
|
70
|
+
function flatPoints(points) {
|
|
71
|
+
return points.join('');
|
|
72
72
|
}
|
|
73
73
|
function useAlign(open, popupEle, target, placement, builtinPlacements, popupAlign, onPopupAlign, mobile) {
|
|
74
74
|
const [offsetInfo, setOffsetInfo] = React.useState({
|
|
@@ -254,6 +254,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
254
254
|
const nextAlignInfo = {
|
|
255
255
|
...placementInfo
|
|
256
256
|
};
|
|
257
|
+
let nextPoints = [popupPoints, targetPoints];
|
|
257
258
|
|
|
258
259
|
// Next Offset
|
|
259
260
|
let nextOffsetX = targetAlignPoint.x - popupAlignPoint.x + popupOffsetX;
|
|
@@ -331,7 +332,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
331
332
|
prevFlipRef.current.bt = true;
|
|
332
333
|
nextOffsetY = tmpNextOffsetY;
|
|
333
334
|
popupOffsetY = -popupOffsetY;
|
|
334
|
-
|
|
335
|
+
nextPoints = [reversePoints(nextPoints[0], 0), reversePoints(nextPoints[1], 0)];
|
|
335
336
|
} else {
|
|
336
337
|
prevFlipRef.current.bt = false;
|
|
337
338
|
}
|
|
@@ -355,7 +356,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
355
356
|
prevFlipRef.current.tb = true;
|
|
356
357
|
nextOffsetY = tmpNextOffsetY;
|
|
357
358
|
popupOffsetY = -popupOffsetY;
|
|
358
|
-
|
|
359
|
+
nextPoints = [reversePoints(nextPoints[0], 0), reversePoints(nextPoints[1], 0)];
|
|
359
360
|
} else {
|
|
360
361
|
prevFlipRef.current.tb = false;
|
|
361
362
|
}
|
|
@@ -385,7 +386,7 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
385
386
|
prevFlipRef.current.rl = true;
|
|
386
387
|
nextOffsetX = tmpNextOffsetX;
|
|
387
388
|
popupOffsetX = -popupOffsetX;
|
|
388
|
-
|
|
389
|
+
nextPoints = [reversePoints(nextPoints[0], 1), reversePoints(nextPoints[1], 1)];
|
|
389
390
|
} else {
|
|
390
391
|
prevFlipRef.current.rl = false;
|
|
391
392
|
}
|
|
@@ -409,11 +410,12 @@ function useAlign(open, popupEle, target, placement, builtinPlacements, popupAli
|
|
|
409
410
|
prevFlipRef.current.lr = true;
|
|
410
411
|
nextOffsetX = tmpNextOffsetX;
|
|
411
412
|
popupOffsetX = -popupOffsetX;
|
|
412
|
-
|
|
413
|
+
nextPoints = [reversePoints(nextPoints[0], 1), reversePoints(nextPoints[1], 1)];
|
|
413
414
|
} else {
|
|
414
415
|
prevFlipRef.current.lr = false;
|
|
415
416
|
}
|
|
416
417
|
}
|
|
418
|
+
nextAlignInfo.points = [flatPoints(nextPoints[0]), flatPoints(nextPoints[1])];
|
|
417
419
|
|
|
418
420
|
// ============================ Shift ============================
|
|
419
421
|
syncNextPopupPosition();
|
package/lib/index.js
CHANGED
|
@@ -29,6 +29,7 @@ var _useWatch = _interopRequireDefault(require("./hooks/useWatch"));
|
|
|
29
29
|
var _useWinClick = _interopRequireDefault(require("./hooks/useWinClick"));
|
|
30
30
|
var _util = require("./util");
|
|
31
31
|
var _UniqueProvider = _interopRequireDefault(require("./UniqueProvider"));
|
|
32
|
+
var _util2 = require("@rc-component/util");
|
|
32
33
|
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
33
34
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
34
35
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -152,10 +153,8 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
152
153
|
} : null;
|
|
153
154
|
|
|
154
155
|
// ============================ Open ============================
|
|
155
|
-
const [internalOpen, setInternalOpen] =
|
|
156
|
-
|
|
157
|
-
// Render still use props as first priority
|
|
158
|
-
const mergedOpen = popupVisible ?? internalOpen;
|
|
156
|
+
const [internalOpen, setInternalOpen] = (0, _util2.useControlledState)(defaultPopupVisible || false, popupVisible);
|
|
157
|
+
const mergedOpen = internalOpen || false;
|
|
159
158
|
|
|
160
159
|
// ========================== Children ==========================
|
|
161
160
|
const child = React.useMemo(() => {
|
|
@@ -166,18 +165,8 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
166
165
|
}, [children, mergedOpen]);
|
|
167
166
|
const originChildProps = child?.props || {};
|
|
168
167
|
|
|
169
|
-
// We use effect sync here in case `popupVisible` back to `undefined`
|
|
170
|
-
const setMergedOpen = (0, _useEvent.default)(nextOpen => {
|
|
171
|
-
if (openUncontrolled) {
|
|
172
|
-
setInternalOpen(nextOpen);
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
|
|
176
168
|
// Support ref
|
|
177
169
|
const isOpen = (0, _useEvent.default)(() => mergedOpen);
|
|
178
|
-
(0, _useLayoutEffect.default)(() => {
|
|
179
|
-
setInternalOpen(popupVisible || false);
|
|
180
|
-
}, [popupVisible]);
|
|
181
170
|
|
|
182
171
|
// Extract common options for UniqueProvider
|
|
183
172
|
const getUniqueOptions = (0, _useEvent.default)((delay = 0) => ({
|
|
@@ -220,7 +209,7 @@ function generateTrigger(PortalComponent = _portal.default) {
|
|
|
220
209
|
const lastTriggerRef = React.useRef([]);
|
|
221
210
|
lastTriggerRef.current = [];
|
|
222
211
|
const internalTriggerOpen = (0, _useEvent.default)(nextOpen => {
|
|
223
|
-
|
|
212
|
+
setInternalOpen(nextOpen);
|
|
224
213
|
|
|
225
214
|
// Enter or Pointer will both trigger open state change
|
|
226
215
|
// We only need take one to avoid duplicated change event trigger
|
package/lib/util.js
CHANGED
|
@@ -9,10 +9,11 @@ exports.getVisibleArea = getVisibleArea;
|
|
|
9
9
|
exports.getWin = getWin;
|
|
10
10
|
exports.toNum = toNum;
|
|
11
11
|
function isPointsEq(a1 = [], a2 = [], isAlignPoint) {
|
|
12
|
+
const getVal = (a, index) => a[index] || '';
|
|
12
13
|
if (isAlignPoint) {
|
|
13
|
-
return a1
|
|
14
|
+
return getVal(a1, 0) === getVal(a2, 0);
|
|
14
15
|
}
|
|
15
|
-
return a1
|
|
16
|
+
return getVal(a1, 0) === getVal(a2, 0) && getVal(a1, 1) === getVal(a2, 1);
|
|
16
17
|
}
|
|
17
18
|
function getAlignPopupClassName(builtinPlacements, prefixCls, align, isAlignPoint) {
|
|
18
19
|
const {
|