@bifrostui/utils 1.4.7 → 1.5.0
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/dist/directionLocationUtil.d.ts +27 -12
- package/dist/directionLocationUtil.js +101 -55
- package/dist/domUtils/index.d.ts +12 -0
- package/dist/domUtils/index.js +46 -0
- package/dist/domUtils/index.miniapp.d.ts +2 -0
- package/dist/domUtils/index.miniapp.js +86 -0
- package/dist/getBoundingClientRect/index.miniapp.d.ts +1 -2
- package/dist/getBoundingClientRect/index.miniapp.js +34 -5
- package/dist/getRootContainer/index.d.ts +2 -0
- package/dist/{getRootElement → getRootContainer}/index.js +8 -8
- package/dist/getRootContainer/index.miniapp.d.ts +3 -0
- package/dist/{getRootElement → getRootContainer}/index.miniapp.js +4 -4
- package/dist/hooks/index.d.ts +2 -2
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useTouchEmulator.d.ts +7 -1
- package/dist/hooks/useTouchEmulator.js +36 -10
- package/dist/index.d.ts +4 -3
- package/dist/index.js +18 -3
- package/dist/isMini.d.ts +2 -1
- package/dist/isMini.js +3 -0
- package/es/directionLocationUtil.d.ts +27 -12
- package/es/directionLocationUtil.js +91 -55
- package/es/domUtils/index.d.ts +12 -0
- package/es/domUtils/index.js +22 -0
- package/es/domUtils/index.miniapp.d.ts +2 -0
- package/es/domUtils/index.miniapp.js +54 -0
- package/es/getBoundingClientRect/index.miniapp.d.ts +1 -2
- package/es/getBoundingClientRect/index.miniapp.js +34 -5
- package/es/getRootContainer/index.d.ts +2 -0
- package/es/getRootContainer/index.js +9 -0
- package/es/getRootContainer/index.miniapp.d.ts +3 -0
- package/es/{getRootElement → getRootContainer}/index.miniapp.js +4 -4
- package/es/hooks/index.d.ts +2 -2
- package/es/hooks/index.js +10 -1
- package/es/hooks/useTouchEmulator.d.ts +7 -1
- package/es/hooks/useTouchEmulator.js +29 -10
- package/es/index.d.ts +4 -3
- package/es/index.js +15 -2
- package/es/isMini.d.ts +2 -1
- package/es/isMini.js +2 -0
- package/package.json +1 -1
- package/dist/getRootElement/index.d.ts +0 -2
- package/dist/getRootElement/index.miniapp.d.ts +0 -3
- package/es/getRootElement/index.d.ts +0 -2
- package/es/getRootElement/index.js +0 -9
- package/es/getRootElement/index.miniapp.d.ts +0 -3
@@ -17,7 +17,11 @@ var __copyProps = (to, from, except, desc) => {
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
18
|
var useTouchEmulator_exports = {};
|
19
19
|
__export(useTouchEmulator_exports, {
|
20
|
-
default: () =>
|
20
|
+
default: () => useTouchEmulator_default,
|
21
|
+
emulateTouchEnd: () => emulateTouchEnd,
|
22
|
+
emulateTouchMove: () => emulateTouchMove,
|
23
|
+
emulateTouchStart: () => emulateTouchStart,
|
24
|
+
touchEmulator: () => touchEmulator
|
21
25
|
});
|
22
26
|
module.exports = __toCommonJS(useTouchEmulator_exports);
|
23
27
|
var import_react = require("react");
|
@@ -88,22 +92,44 @@ function getActiveTouches(mouseEv) {
|
|
88
92
|
}
|
89
93
|
return createTouchList(mouseEv);
|
90
94
|
}
|
95
|
+
const emulateTouchStart = onMouse("touchstart");
|
96
|
+
const emulateTouchMove = onMouse("touchmove");
|
97
|
+
const emulateTouchEnd = onMouse("touchend");
|
91
98
|
function useTouchEmulator(dom = window) {
|
92
|
-
const touchStart = onMouse("touchstart");
|
93
|
-
const touchMove = onMouse("touchmove");
|
94
|
-
const touchEnd = onMouse("touchend");
|
95
99
|
(0, import_react.useEffect)(() => {
|
96
100
|
if (dom) {
|
97
|
-
dom.addEventListener("mousedown",
|
98
|
-
dom.addEventListener("mousemove",
|
99
|
-
dom.addEventListener("mouseup",
|
101
|
+
dom.addEventListener("mousedown", emulateTouchStart, true);
|
102
|
+
dom.addEventListener("mousemove", emulateTouchMove, true);
|
103
|
+
dom.addEventListener("mouseup", emulateTouchEnd, true);
|
100
104
|
}
|
101
105
|
return () => {
|
102
106
|
if (dom) {
|
103
|
-
dom.removeEventListener("mousedown",
|
104
|
-
dom.removeEventListener("mousemove",
|
105
|
-
dom.removeEventListener("mouseup",
|
107
|
+
dom.removeEventListener("mousedown", emulateTouchStart, true);
|
108
|
+
dom.removeEventListener("mousemove", emulateTouchMove, true);
|
109
|
+
dom.removeEventListener("mouseup", emulateTouchEnd, true);
|
106
110
|
}
|
107
111
|
};
|
108
112
|
}, [dom]);
|
109
113
|
}
|
114
|
+
const touchEmulator = (dom = window) => {
|
115
|
+
if (dom) {
|
116
|
+
dom.addEventListener("mousedown", emulateTouchStart, true);
|
117
|
+
dom.addEventListener("mousemove", emulateTouchMove, true);
|
118
|
+
dom.addEventListener("mouseup", emulateTouchEnd, true);
|
119
|
+
}
|
120
|
+
return function() {
|
121
|
+
if (dom) {
|
122
|
+
dom.removeEventListener("mousedown", emulateTouchStart, true);
|
123
|
+
dom.removeEventListener("mousemove", emulateTouchMove, true);
|
124
|
+
dom.removeEventListener("mouseup", emulateTouchEnd, true);
|
125
|
+
}
|
126
|
+
};
|
127
|
+
};
|
128
|
+
var useTouchEmulator_default = useTouchEmulator;
|
129
|
+
// Annotate the CommonJS export names for ESM import in node:
|
130
|
+
0 && (module.exports = {
|
131
|
+
emulateTouchEnd,
|
132
|
+
emulateTouchMove,
|
133
|
+
emulateTouchStart,
|
134
|
+
touchEmulator
|
135
|
+
});
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
export { default as debounce } from './debounce';
|
2
|
-
export { getStylesAndLocation, triggerEventTransform, parsePlacement, } from './directionLocationUtil';
|
2
|
+
export { getStylesAndLocation, getNewDirectionLocation, triggerEventTransform, parsePlacement, } from './directionLocationUtil';
|
3
3
|
export { default as convertHexToRGBA } from './hex2rgba';
|
4
|
-
export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch, useUniqueId, } from './hooks';
|
4
|
+
export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd, useValue, useDomReady, useSize, useDomCss, useTouch, useUniqueId, } from './hooks';
|
5
5
|
export { default as isDev } from './isDev';
|
6
6
|
export { isMini, isWeapp, isAlipay, isMiniapp } from './isMini';
|
7
7
|
export { default as setRef } from './setRef';
|
@@ -9,7 +9,8 @@ export { default as throttle } from './throttle';
|
|
9
9
|
export { default as toArray } from './toArray';
|
10
10
|
export { default as blockTouch } from './touchBlocker';
|
11
11
|
export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
|
12
|
-
export { default as
|
12
|
+
export { default as getRootContainer } from './getRootContainer';
|
13
13
|
export { default as getBoundingClientRect } from './getBoundingClientRect';
|
14
|
+
export { getScrollRect, getClientRect } from './domUtils';
|
14
15
|
export * from './isType';
|
15
16
|
export * from './render';
|
package/dist/index.js
CHANGED
@@ -34,8 +34,14 @@ __export(src_exports, {
|
|
34
34
|
debounce: () => import_debounce.default,
|
35
35
|
duration: () => import_transitions.duration,
|
36
36
|
easing: () => import_transitions.easing,
|
37
|
+
emulateTouchEnd: () => import_hooks.emulateTouchEnd,
|
38
|
+
emulateTouchMove: () => import_hooks.emulateTouchMove,
|
39
|
+
emulateTouchStart: () => import_hooks.emulateTouchStart,
|
37
40
|
getBoundingClientRect: () => import_getBoundingClientRect.default,
|
38
|
-
|
41
|
+
getClientRect: () => import_domUtils.getClientRect,
|
42
|
+
getNewDirectionLocation: () => import_directionLocationUtil.getNewDirectionLocation,
|
43
|
+
getRootContainer: () => import_getRootContainer.default,
|
44
|
+
getScrollRect: () => import_domUtils.getScrollRect,
|
39
45
|
getStylesAndLocation: () => import_directionLocationUtil.getStylesAndLocation,
|
40
46
|
getTransitionProps: () => import_transitions.getTransitionProps,
|
41
47
|
isAlipay: () => import_isMini.isAlipay,
|
@@ -47,6 +53,7 @@ __export(src_exports, {
|
|
47
53
|
setRef: () => import_setRef.default,
|
48
54
|
throttle: () => import_throttle.default,
|
49
55
|
toArray: () => import_toArray.default,
|
56
|
+
touchEmulator: () => import_hooks.touchEmulator,
|
50
57
|
triggerEventTransform: () => import_directionLocationUtil.triggerEventTransform,
|
51
58
|
useDidMountEffect: () => import_hooks.useDidMountEffect,
|
52
59
|
useDomCss: () => import_hooks.useDomCss,
|
@@ -71,8 +78,9 @@ var import_throttle = __toESM(require("./throttle"));
|
|
71
78
|
var import_toArray = __toESM(require("./toArray"));
|
72
79
|
var import_touchBlocker = __toESM(require("./touchBlocker"));
|
73
80
|
var import_transitions = require("./transitions");
|
74
|
-
var
|
81
|
+
var import_getRootContainer = __toESM(require("./getRootContainer"));
|
75
82
|
var import_getBoundingClientRect = __toESM(require("./getBoundingClientRect"));
|
83
|
+
var import_domUtils = require("./domUtils");
|
76
84
|
__reExport(src_exports, require("./isType"), module.exports);
|
77
85
|
__reExport(src_exports, require("./render"), module.exports);
|
78
86
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -83,8 +91,14 @@ __reExport(src_exports, require("./render"), module.exports);
|
|
83
91
|
debounce,
|
84
92
|
duration,
|
85
93
|
easing,
|
94
|
+
emulateTouchEnd,
|
95
|
+
emulateTouchMove,
|
96
|
+
emulateTouchStart,
|
86
97
|
getBoundingClientRect,
|
87
|
-
|
98
|
+
getClientRect,
|
99
|
+
getNewDirectionLocation,
|
100
|
+
getRootContainer,
|
101
|
+
getScrollRect,
|
88
102
|
getStylesAndLocation,
|
89
103
|
getTransitionProps,
|
90
104
|
isAlipay,
|
@@ -96,6 +110,7 @@ __reExport(src_exports, require("./render"), module.exports);
|
|
96
110
|
setRef,
|
97
111
|
throttle,
|
98
112
|
toArray,
|
113
|
+
touchEmulator,
|
99
114
|
triggerEventTransform,
|
100
115
|
useDidMountEffect,
|
101
116
|
useDomCss,
|
package/dist/isMini.d.ts
CHANGED
package/dist/isMini.js
CHANGED
@@ -20,12 +20,14 @@ __export(isMini_exports, {
|
|
20
20
|
isAlipay: () => isAlipay,
|
21
21
|
isMini: () => isMini,
|
22
22
|
isMiniapp: () => isMiniapp,
|
23
|
+
isTt: () => isTt,
|
23
24
|
isWeapp: () => isWeapp
|
24
25
|
});
|
25
26
|
module.exports = __toCommonJS(isMini_exports);
|
26
27
|
const isMini = typeof process.env.TARO_ENV === "string";
|
27
28
|
const isWeapp = process.env.TARO_ENV === "weapp";
|
28
29
|
const isAlipay = process.env.TARO_ENV === "alipay";
|
30
|
+
const isTt = process.env.TARO_ENV === "tt";
|
29
31
|
const isMiniapp = () => {
|
30
32
|
return isMini;
|
31
33
|
};
|
@@ -34,5 +36,6 @@ const isMiniapp = () => {
|
|
34
36
|
isAlipay,
|
35
37
|
isMini,
|
36
38
|
isMiniapp,
|
39
|
+
isTt,
|
37
40
|
isWeapp
|
38
41
|
});
|
@@ -22,26 +22,41 @@ export declare const getDirectionLocationStyle: ({ childrenOffset, arrowDirectio
|
|
22
22
|
tipOffset: any;
|
23
23
|
arrowLocation: any;
|
24
24
|
offsetSpacing: any;
|
25
|
-
}) => {
|
26
|
-
styles:
|
25
|
+
}) => Promise<{
|
26
|
+
styles: {
|
27
|
+
top: number;
|
28
|
+
left: number;
|
29
|
+
transform: string;
|
30
|
+
visibility: string;
|
31
|
+
};
|
27
32
|
childrenStyle: any;
|
28
|
-
}
|
33
|
+
}>;
|
29
34
|
/**
|
30
35
|
* 获取气泡位置和箭头位置
|
31
36
|
*/
|
32
|
-
export declare const getStylesAndLocation: ({ scrollRoot, childrenRef, arrowDirection, arrowLocation, offsetSpacing,
|
37
|
+
export declare const getStylesAndLocation: ({ scrollRoot, childrenRef, tipRef, arrowDirection, arrowLocation, offsetSpacing, }: {
|
33
38
|
scrollRoot?: Element;
|
34
|
-
childrenRef
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}) => {
|
40
|
-
styles:
|
39
|
+
childrenRef?: React.RefObject<any>;
|
40
|
+
tipRef?: React.RefObject<any>;
|
41
|
+
arrowDirection: string;
|
42
|
+
arrowLocation: string;
|
43
|
+
offsetSpacing?: number;
|
44
|
+
}) => Promise<{
|
45
|
+
styles: {};
|
46
|
+
childrenStyle: {};
|
47
|
+
newArrowDirection: string;
|
48
|
+
newArrowLocation: string;
|
49
|
+
} | {
|
50
|
+
styles: {
|
51
|
+
top: number;
|
52
|
+
left: number;
|
53
|
+
transform: string;
|
54
|
+
visibility: string;
|
55
|
+
};
|
41
56
|
childrenStyle: any;
|
42
57
|
newArrowDirection: any;
|
43
58
|
newArrowLocation: any;
|
44
|
-
}
|
59
|
+
}>;
|
45
60
|
export declare const triggerEventTransform: ({ trigger, click, show, hide }: {
|
46
61
|
trigger: any;
|
47
62
|
click: any;
|
@@ -1,12 +1,31 @@
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
2
|
+
return new Promise((resolve, reject) => {
|
3
|
+
var fulfilled = (value) => {
|
4
|
+
try {
|
5
|
+
step(generator.next(value));
|
6
|
+
} catch (e) {
|
7
|
+
reject(e);
|
8
|
+
}
|
9
|
+
};
|
10
|
+
var rejected = (value) => {
|
11
|
+
try {
|
12
|
+
step(generator.throw(value));
|
13
|
+
} catch (e) {
|
14
|
+
reject(e);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
+
});
|
20
|
+
};
|
21
|
+
import { getScrollRect, getClientRect } from "./domUtils";
|
22
|
+
import getBoundingClientRect from "./getBoundingClientRect";
|
1
23
|
const directionCssMap = {
|
2
24
|
left: "right",
|
3
25
|
right: "left",
|
4
26
|
top: "bottom",
|
5
27
|
bottom: "top"
|
6
28
|
};
|
7
|
-
const isBodyScroll = (scrollRoot) => {
|
8
|
-
return scrollRoot === document.body;
|
9
|
-
};
|
10
29
|
const getNewDirectionLocation = ({
|
11
30
|
scrollRoot,
|
12
31
|
scrollRootOffset,
|
@@ -29,14 +48,15 @@ const getNewDirectionLocation = ({
|
|
29
48
|
top: sTop,
|
30
49
|
bottom: sBottom,
|
31
50
|
left: sLeft,
|
32
|
-
right: sRight
|
51
|
+
right: sRight,
|
52
|
+
width: pageWidth,
|
53
|
+
height: pageHeight
|
33
54
|
} = scrollRootOffset;
|
34
|
-
const
|
35
|
-
const
|
36
|
-
const
|
37
|
-
const
|
38
|
-
const
|
39
|
-
const maxRight = isBodyScroll(scrollRoot) ? pageWidth : sRight;
|
55
|
+
const isBodyRoot = !scrollRoot;
|
56
|
+
const maxTop = isBodyRoot ? 0 : sTop;
|
57
|
+
const maxBottom = isBodyRoot ? pageHeight : sBottom;
|
58
|
+
const maxLeft = isBodyRoot ? 0 : sLeft;
|
59
|
+
const maxRight = isBodyRoot ? pageWidth : sRight;
|
40
60
|
let newArrowDirection = arrowDirection;
|
41
61
|
let newArrowLocation = arrowLocation;
|
42
62
|
const isDirectionTop = arrowDirection === "top";
|
@@ -71,16 +91,14 @@ const getNewDirectionLocation = ({
|
|
71
91
|
newArrowLocation
|
72
92
|
};
|
73
93
|
};
|
74
|
-
const getDirectionLocationStyle = ({
|
94
|
+
const getDirectionLocationStyle = (_0) => __async(void 0, [_0], function* ({
|
75
95
|
childrenOffset,
|
76
96
|
arrowDirection,
|
77
97
|
tipOffset,
|
78
98
|
arrowLocation,
|
79
99
|
offsetSpacing
|
80
|
-
})
|
81
|
-
const
|
82
|
-
const scrollLeft = window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft;
|
83
|
-
const styles = {};
|
100
|
+
}) {
|
101
|
+
const { top: scrollTop, left: scrollLeft } = yield getScrollRect();
|
84
102
|
const {
|
85
103
|
width: cWidth,
|
86
104
|
height: cHeight,
|
@@ -94,107 +112,125 @@ const getDirectionLocationStyle = ({
|
|
94
112
|
childrenStyle = { width: `${cWidth}px`, height: `${cHeight}px` };
|
95
113
|
}
|
96
114
|
const { width, height } = tipOffset;
|
115
|
+
let styleTop;
|
116
|
+
let styleLeft;
|
97
117
|
if (arrowDirection === "top") {
|
98
|
-
|
118
|
+
styleTop = cTop - offsetSpacing - height;
|
99
119
|
switch (arrowLocation) {
|
100
120
|
case "left":
|
101
|
-
|
121
|
+
styleLeft = cLeft;
|
102
122
|
break;
|
103
123
|
case "center":
|
104
|
-
|
124
|
+
styleLeft = cLeft + (cWidth - width) / 2;
|
105
125
|
break;
|
106
126
|
case "right":
|
107
|
-
|
127
|
+
styleLeft = cRight - width;
|
108
128
|
break;
|
109
129
|
case "none":
|
110
|
-
|
130
|
+
styleLeft = cLeft;
|
111
131
|
break;
|
112
132
|
default:
|
113
133
|
break;
|
114
134
|
}
|
115
135
|
} else if (arrowDirection === "bottom") {
|
116
|
-
|
136
|
+
styleTop = cBottom + offsetSpacing;
|
117
137
|
switch (arrowLocation) {
|
118
138
|
case "left":
|
119
|
-
|
139
|
+
styleLeft = cLeft;
|
120
140
|
break;
|
121
141
|
case "center":
|
122
|
-
|
142
|
+
styleLeft = cLeft + (cWidth - width) / 2;
|
123
143
|
break;
|
124
144
|
case "right":
|
125
|
-
|
145
|
+
styleLeft = cRight - width;
|
126
146
|
break;
|
127
147
|
case "none":
|
128
|
-
|
148
|
+
styleLeft = cLeft;
|
129
149
|
break;
|
130
150
|
default:
|
131
151
|
break;
|
132
152
|
}
|
133
153
|
} else if (arrowDirection === "left") {
|
134
|
-
|
154
|
+
styleLeft = cLeft - offsetSpacing - width;
|
135
155
|
switch (arrowLocation) {
|
136
156
|
case "top":
|
137
|
-
|
157
|
+
styleTop = cTop;
|
138
158
|
break;
|
139
159
|
case "center":
|
140
|
-
|
160
|
+
styleTop = cTop + (cHeight - height) / 2;
|
141
161
|
break;
|
142
162
|
case "bottom":
|
143
|
-
|
163
|
+
styleTop = cBottom - height;
|
144
164
|
break;
|
145
165
|
case "none":
|
146
|
-
|
166
|
+
styleTop = cTop;
|
147
167
|
break;
|
148
168
|
default:
|
149
169
|
break;
|
150
170
|
}
|
151
171
|
} else if (arrowDirection === "right") {
|
152
|
-
|
172
|
+
styleLeft = cRight + offsetSpacing;
|
153
173
|
switch (arrowLocation) {
|
154
174
|
case "top":
|
155
|
-
|
175
|
+
styleTop = cTop;
|
156
176
|
break;
|
157
177
|
case "center":
|
158
|
-
|
178
|
+
styleTop = cTop + (cHeight - height) / 2;
|
159
179
|
break;
|
160
180
|
case "bottom":
|
161
|
-
|
181
|
+
styleTop = cBottom - height;
|
162
182
|
break;
|
163
183
|
case "none":
|
164
|
-
|
184
|
+
styleTop = cTop;
|
165
185
|
break;
|
166
186
|
default:
|
167
187
|
break;
|
168
188
|
}
|
169
189
|
}
|
170
|
-
if (
|
171
|
-
|
190
|
+
if (styleTop) {
|
191
|
+
styleTop = `${styleTop + scrollTop}px`;
|
172
192
|
}
|
173
|
-
if (
|
174
|
-
|
193
|
+
if (styleLeft) {
|
194
|
+
styleLeft = `${styleLeft + scrollLeft}px`;
|
175
195
|
}
|
196
|
+
const styles = {
|
197
|
+
top: 0,
|
198
|
+
left: 0,
|
199
|
+
transform: `translate3d(${styleLeft}, ${styleTop}, 0)`,
|
200
|
+
visibility: ""
|
201
|
+
};
|
176
202
|
return { styles, childrenStyle };
|
177
|
-
};
|
178
|
-
const getStylesAndLocation = ({
|
179
|
-
scrollRoot
|
203
|
+
});
|
204
|
+
const getStylesAndLocation = (_0) => __async(void 0, [_0], function* ({
|
205
|
+
scrollRoot,
|
180
206
|
childrenRef,
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
})
|
207
|
+
tipRef,
|
208
|
+
arrowDirection = "top",
|
209
|
+
arrowLocation = "center",
|
210
|
+
offsetSpacing = 0
|
211
|
+
}) {
|
186
212
|
if (!(childrenRef == null ? void 0 : childrenRef.current)) {
|
187
213
|
console.error(
|
188
214
|
"\u7EC4\u4EF6\u5305\u88F9\u7684children\u53EF\u80FD\u662F\u4E00\u4E2A\u7EC4\u4EF6\uFF0C\u60A8\u7684\u5F53\u524D\u5199\u6CD5\u53EF\u80FD\u5BFC\u81F4ref\u6CA1\u6709\u7ED1\u5B9A\u5230children\u4E0A\uFF0C\u8BF7\u5C1D\u8BD5\u5BF9children\u5BF9\u5E94\u7684\u7EC4\u4EF6\u4F7F\u7528/* @__PURE__ */ React.forwardRef\u6765\u89E3\u51B3"
|
189
215
|
);
|
190
216
|
return null;
|
191
217
|
}
|
192
|
-
const childrenOffset = childrenRef.current
|
193
|
-
const
|
194
|
-
if (
|
195
|
-
return
|
196
|
-
|
197
|
-
|
218
|
+
const childrenOffset = yield getBoundingClientRect(childrenRef.current);
|
219
|
+
const tipOffset = yield getBoundingClientRect(tipRef.current);
|
220
|
+
if (!tipOffset || !childrenOffset) {
|
221
|
+
return {
|
222
|
+
styles: {},
|
223
|
+
childrenStyle: {},
|
224
|
+
newArrowDirection: arrowDirection,
|
225
|
+
newArrowLocation: arrowLocation
|
226
|
+
};
|
227
|
+
}
|
228
|
+
let scrollRootOffset;
|
229
|
+
if (scrollRoot) {
|
230
|
+
scrollRootOffset = yield getBoundingClientRect(scrollRoot);
|
231
|
+
} else {
|
232
|
+
scrollRootOffset = yield getClientRect();
|
233
|
+
}
|
198
234
|
const { newArrowDirection, newArrowLocation } = getNewDirectionLocation({
|
199
235
|
scrollRoot,
|
200
236
|
scrollRootOffset,
|
@@ -204,7 +240,7 @@ const getStylesAndLocation = ({
|
|
204
240
|
arrowLocation,
|
205
241
|
offsetSpacing
|
206
242
|
});
|
207
|
-
const { styles, childrenStyle } = getDirectionLocationStyle({
|
243
|
+
const { styles, childrenStyle } = yield getDirectionLocationStyle({
|
208
244
|
childrenOffset,
|
209
245
|
arrowDirection: newArrowDirection,
|
210
246
|
tipOffset,
|
@@ -218,7 +254,7 @@ const getStylesAndLocation = ({
|
|
218
254
|
newArrowDirection,
|
219
255
|
newArrowLocation
|
220
256
|
};
|
221
|
-
};
|
257
|
+
});
|
222
258
|
const onMouseEnter = "onMouseEnter";
|
223
259
|
const onMouseLeave = "onMouseLeave";
|
224
260
|
const onClick = "onClick";
|
@@ -0,0 +1,22 @@
|
|
1
|
+
const getClientRect = () => {
|
2
|
+
const width = window.innerWidth || document.documentElement.clientWidth;
|
3
|
+
const height = window.innerHeight || document.documentElement.clientHeight;
|
4
|
+
return Promise.resolve({
|
5
|
+
width,
|
6
|
+
height,
|
7
|
+
left: 0,
|
8
|
+
top: 0,
|
9
|
+
right: width,
|
10
|
+
bottom: height
|
11
|
+
});
|
12
|
+
};
|
13
|
+
const getScrollRect = () => {
|
14
|
+
return Promise.resolve({
|
15
|
+
top: window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop,
|
16
|
+
left: window.scrollX >= 0 && window.scrollX || document.documentElement.scrollLeft
|
17
|
+
});
|
18
|
+
};
|
19
|
+
export {
|
20
|
+
getClientRect,
|
21
|
+
getScrollRect
|
22
|
+
};
|
@@ -0,0 +1,54 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __defProps = Object.defineProperties;
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
8
|
+
var __spreadValues = (a, b) => {
|
9
|
+
for (var prop in b || (b = {}))
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
12
|
+
if (__getOwnPropSymbols)
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
14
|
+
if (__propIsEnum.call(b, prop))
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
16
|
+
}
|
17
|
+
return a;
|
18
|
+
};
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
20
|
+
import Taro from "@tarojs/taro";
|
21
|
+
const getClientRect = () => {
|
22
|
+
return new Promise((resolve, reject) => {
|
23
|
+
try {
|
24
|
+
const res = Taro.getSystemInfoSync();
|
25
|
+
const width = res.windowWidth;
|
26
|
+
const height = res.windowHeight;
|
27
|
+
const clientInfo = __spreadProps(__spreadValues({}, res), {
|
28
|
+
width,
|
29
|
+
height,
|
30
|
+
left: 0,
|
31
|
+
top: 0,
|
32
|
+
right: width,
|
33
|
+
bottom: height
|
34
|
+
});
|
35
|
+
resolve(clientInfo);
|
36
|
+
} catch (error) {
|
37
|
+
reject(error);
|
38
|
+
}
|
39
|
+
});
|
40
|
+
};
|
41
|
+
const getScrollRect = () => {
|
42
|
+
return new Promise((resolve) => {
|
43
|
+
Taro.createSelectorQuery().selectViewport().scrollOffset().exec((res) => {
|
44
|
+
resolve({
|
45
|
+
top: res[0].scrollTop,
|
46
|
+
left: res[0].scrollLeft
|
47
|
+
});
|
48
|
+
});
|
49
|
+
});
|
50
|
+
};
|
51
|
+
export {
|
52
|
+
getClientRect,
|
53
|
+
getScrollRect
|
54
|
+
};
|
@@ -1,2 +1 @@
|
|
1
|
-
|
2
|
-
export default function getBoundingClientRect(ele: TaroElement): Promise<DOMRect>;
|
1
|
+
export default function getBoundingClientRect(ele: any): Promise<DOMRect>;
|
@@ -1,10 +1,39 @@
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
2
|
+
return new Promise((resolve, reject) => {
|
3
|
+
var fulfilled = (value) => {
|
4
|
+
try {
|
5
|
+
step(generator.next(value));
|
6
|
+
} catch (e) {
|
7
|
+
reject(e);
|
8
|
+
}
|
9
|
+
};
|
10
|
+
var rejected = (value) => {
|
11
|
+
try {
|
12
|
+
step(generator.throw(value));
|
13
|
+
} catch (e) {
|
14
|
+
reject(e);
|
15
|
+
}
|
16
|
+
};
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
19
|
+
});
|
20
|
+
};
|
1
21
|
import Taro from "@tarojs/taro";
|
22
|
+
import { isTt, isWeapp } from "../isMini";
|
2
23
|
function getBoundingClientRect(ele) {
|
3
|
-
return
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
}
|
24
|
+
return __async(this, null, function* () {
|
25
|
+
let result;
|
26
|
+
if (isWeapp || isTt) {
|
27
|
+
result = yield ele.getBoundingClientRect();
|
28
|
+
} else {
|
29
|
+
const query = Taro.createSelectorQuery();
|
30
|
+
result = yield new Promise((resolve) => {
|
31
|
+
query.select(`#${ele.uid}`).boundingClientRect().exec(([res]) => {
|
32
|
+
resolve(res);
|
33
|
+
});
|
34
|
+
});
|
35
|
+
}
|
36
|
+
return result;
|
8
37
|
});
|
9
38
|
}
|
10
39
|
export {
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const getRootContainer = (rootCon, defaultCon) => {
|
2
|
+
const rootElement = typeof rootCon === "function" ? rootCon() : rootCon;
|
3
|
+
const defaultRootElement = document.body;
|
4
|
+
return rootElement || defaultCon || defaultRootElement;
|
5
|
+
};
|
6
|
+
var getRootContainer_default = getRootContainer;
|
7
|
+
export {
|
8
|
+
getRootContainer_default as default
|
9
|
+
};
|