@bifrostui/utils 2.0.0-alpha.0 → 2.0.0-alpha.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/dist/directionLocationUtil.d.ts +27 -12
- package/dist/directionLocationUtil.js +101 -55
- package/dist/domUtils/addClass.d.ts +1 -0
- package/dist/domUtils/addClass.js +46 -0
- package/dist/domUtils/index.d.ts +3 -0
- package/dist/domUtils/index.js +35 -0
- package/dist/domUtils/index.miniapp.d.ts +3 -0
- package/dist/domUtils/index.miniapp.js +35 -0
- package/dist/domUtils/rect.d.ts +12 -0
- package/dist/domUtils/rect.js +46 -0
- package/dist/domUtils/rect.miniapp.d.ts +2 -0
- package/dist/domUtils/rect.miniapp.js +86 -0
- package/dist/domUtils/removeClass.d.ts +1 -0
- package/dist/domUtils/removeClass.js +47 -0
- package/dist/getBoundingClientRect/index.d.ts +1 -1
- package/dist/getBoundingClientRect/index.js +13 -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 +15 -3
- package/dist/isMini.d.ts +2 -1
- package/dist/isMini.js +3 -0
- package/dist/render.d.ts +2 -2
- package/es/directionLocationUtil.d.ts +27 -12
- package/es/directionLocationUtil.js +91 -55
- package/es/domUtils/addClass.d.ts +1 -0
- package/es/domUtils/addClass.js +23 -0
- package/es/domUtils/index.d.ts +3 -0
- package/es/domUtils/index.js +9 -0
- package/es/domUtils/index.miniapp.d.ts +3 -0
- package/es/domUtils/index.miniapp.js +9 -0
- package/es/domUtils/rect.d.ts +12 -0
- package/es/domUtils/rect.js +22 -0
- package/es/domUtils/rect.miniapp.d.ts +2 -0
- package/es/domUtils/rect.miniapp.js +54 -0
- package/es/domUtils/removeClass.d.ts +1 -0
- package/es/domUtils/removeClass.js +24 -0
- package/es/getBoundingClientRect/index.d.ts +1 -1
- package/es/getBoundingClientRect/index.js +13 -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 +13 -2
- package/es/isMini.d.ts +2 -1
- package/es/isMini.js +2 -0
- package/es/render.d.ts +2 -2
- package/package.json +2 -2
- 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
@@ -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 @@
|
|
1
|
+
export declare const addClass: (element: Element | SVGElement, className: string) => void;
|
@@ -0,0 +1,23 @@
|
|
1
|
+
const hasClass = (element, className) => {
|
2
|
+
if (element.classList)
|
3
|
+
return !!className && element.classList.contains(className);
|
4
|
+
return ` ${element.className.baseVal || element.className} `.indexOf(
|
5
|
+
` ${className} `
|
6
|
+
) !== -1;
|
7
|
+
};
|
8
|
+
const addClass = (element, className) => {
|
9
|
+
if (element.classList) {
|
10
|
+
element.classList.add(className);
|
11
|
+
} else if (!hasClass(element, className))
|
12
|
+
if (typeof element.className === "string") {
|
13
|
+
element.className = `${element.className} ${className}`;
|
14
|
+
} else {
|
15
|
+
element.setAttribute(
|
16
|
+
"class",
|
17
|
+
`${element.className && element.className.baseVal || ""} ${className}`
|
18
|
+
);
|
19
|
+
}
|
20
|
+
};
|
21
|
+
export {
|
22
|
+
addClass
|
23
|
+
};
|
@@ -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
|
+
};
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare const removeClass: (element: Element | SVGElement, className: string) => void;
|
@@ -0,0 +1,24 @@
|
|
1
|
+
const replaceClassName = (origClass, classToRemove) => {
|
2
|
+
return origClass.replace(new RegExp(`(^|\\s)${classToRemove}(?:\\s|$)`, "g"), "$1").replace(/\s+/g, " ").replace(/^\s*|\s*$/g, "");
|
3
|
+
};
|
4
|
+
const removeClass = (element, className) => {
|
5
|
+
if (element.classList) {
|
6
|
+
element.classList.remove(className);
|
7
|
+
} else if (typeof element.className === "string") {
|
8
|
+
element.className = replaceClassName(
|
9
|
+
element.className,
|
10
|
+
className
|
11
|
+
);
|
12
|
+
} else {
|
13
|
+
element.setAttribute(
|
14
|
+
"class",
|
15
|
+
replaceClassName(
|
16
|
+
element.className && element.className.baseVal || "",
|
17
|
+
className
|
18
|
+
)
|
19
|
+
);
|
20
|
+
}
|
21
|
+
};
|
22
|
+
export {
|
23
|
+
removeClass
|
24
|
+
};
|
@@ -1 +1 @@
|
|
1
|
-
export default function getBoundingClientRect(ele: Element): Promise<DOMRect>;
|
1
|
+
export default function getBoundingClientRect(ele: Element | null): Promise<DOMRect>;
|
@@ -1,4 +1,17 @@
|
|
1
1
|
function getBoundingClientRect(ele) {
|
2
|
+
if (!ele) {
|
3
|
+
return Promise.resolve({
|
4
|
+
width: 0,
|
5
|
+
height: 0,
|
6
|
+
top: 0,
|
7
|
+
right: 0,
|
8
|
+
bottom: 0,
|
9
|
+
left: 0,
|
10
|
+
x: 0,
|
11
|
+
y: 0,
|
12
|
+
toJSON: () => ({})
|
13
|
+
});
|
14
|
+
}
|
2
15
|
return Promise.resolve(ele.getBoundingClientRect());
|
3
16
|
}
|
4
17
|
export {
|
@@ -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
|
+
};
|
@@ -1,13 +1,13 @@
|
|
1
1
|
import Taro from "@tarojs/taro";
|
2
|
-
const
|
2
|
+
const getRootContainer = (rootCon, defaultCon) => {
|
3
3
|
const currentPages = Taro.getCurrentPages() || [];
|
4
4
|
const currentPage = currentPages[currentPages.length - 1];
|
5
5
|
const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
|
6
6
|
const defaultRootElement = document.getElementById(pageElement);
|
7
|
-
const rootElement = typeof
|
8
|
-
return rootElement || defaultRootElement;
|
7
|
+
const rootElement = typeof rootCon === "function" ? rootCon() : rootCon;
|
8
|
+
return rootElement || defaultCon || defaultRootElement;
|
9
9
|
};
|
10
|
-
var index_miniapp_default =
|
10
|
+
var index_miniapp_default = getRootContainer;
|
11
11
|
export {
|
12
12
|
index_miniapp_default as default
|
13
13
|
};
|
package/es/hooks/index.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import useDidMountEffect from './useDidMountEffect';
|
2
2
|
import useEventCallback from './useEventCallback';
|
3
3
|
import useForkRef from './useForkRef';
|
4
|
-
import useTouchEmulator from './useTouchEmulator';
|
4
|
+
import useTouchEmulator, { touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd } from './useTouchEmulator';
|
5
5
|
import useValue from './useValue';
|
6
6
|
import useDomReady from './useDomReady';
|
7
7
|
import useSize from './useSize';
|
8
8
|
import useDomCss from './useDomCss';
|
9
9
|
import useTouch from './useTouch';
|
10
10
|
import useUniqueId from './useUniqueId';
|
11
|
-
export { useValue, useForkRef, useEventCallback, useDidMountEffect, useTouchEmulator, useDomReady, useSize, useDomCss, useTouch, useUniqueId, };
|
11
|
+
export { useValue, useForkRef, useEventCallback, useDidMountEffect, useTouchEmulator, touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd, useDomReady, useSize, useDomCss, useTouch, useUniqueId, };
|
package/es/hooks/index.js
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
import useDidMountEffect from "./useDidMountEffect";
|
2
2
|
import useEventCallback from "./useEventCallback";
|
3
3
|
import useForkRef from "./useForkRef";
|
4
|
-
import useTouchEmulator
|
4
|
+
import useTouchEmulator, {
|
5
|
+
touchEmulator,
|
6
|
+
emulateTouchStart,
|
7
|
+
emulateTouchMove,
|
8
|
+
emulateTouchEnd
|
9
|
+
} from "./useTouchEmulator";
|
5
10
|
import useValue from "./useValue";
|
6
11
|
import useDomReady from "./useDomReady";
|
7
12
|
import useSize from "./useSize";
|
@@ -9,6 +14,10 @@ import useDomCss from "./useDomCss";
|
|
9
14
|
import useTouch from "./useTouch";
|
10
15
|
import useUniqueId from "./useUniqueId";
|
11
16
|
export {
|
17
|
+
emulateTouchEnd,
|
18
|
+
emulateTouchMove,
|
19
|
+
emulateTouchStart,
|
20
|
+
touchEmulator,
|
12
21
|
useDidMountEffect,
|
13
22
|
useDomCss,
|
14
23
|
useDomReady,
|
@@ -1 +1,7 @@
|
|
1
|
-
|
1
|
+
declare const emulateTouchStart: (ev: any) => void;
|
2
|
+
declare const emulateTouchMove: (ev: any) => void;
|
3
|
+
declare const emulateTouchEnd: (ev: any) => void;
|
4
|
+
declare function useTouchEmulator(dom?: HTMLElement | Window): void;
|
5
|
+
declare const touchEmulator: (dom?: HTMLElement | Window) => () => void;
|
6
|
+
export default useTouchEmulator;
|
7
|
+
export { touchEmulator, emulateTouchStart, emulateTouchMove, emulateTouchEnd };
|
@@ -66,25 +66,44 @@ function getActiveTouches(mouseEv) {
|
|
66
66
|
}
|
67
67
|
return createTouchList(mouseEv);
|
68
68
|
}
|
69
|
+
const emulateTouchStart = onMouse("touchstart");
|
70
|
+
const emulateTouchMove = onMouse("touchmove");
|
71
|
+
const emulateTouchEnd = onMouse("touchend");
|
69
72
|
function useTouchEmulator(dom = window) {
|
70
|
-
const touchStart = onMouse("touchstart");
|
71
|
-
const touchMove = onMouse("touchmove");
|
72
|
-
const touchEnd = onMouse("touchend");
|
73
73
|
useEffect(() => {
|
74
74
|
if (dom) {
|
75
|
-
dom.addEventListener("mousedown",
|
76
|
-
dom.addEventListener("mousemove",
|
77
|
-
dom.addEventListener("mouseup",
|
75
|
+
dom.addEventListener("mousedown", emulateTouchStart, true);
|
76
|
+
dom.addEventListener("mousemove", emulateTouchMove, true);
|
77
|
+
dom.addEventListener("mouseup", emulateTouchEnd, true);
|
78
78
|
}
|
79
79
|
return () => {
|
80
80
|
if (dom) {
|
81
|
-
dom.removeEventListener("mousedown",
|
82
|
-
dom.removeEventListener("mousemove",
|
83
|
-
dom.removeEventListener("mouseup",
|
81
|
+
dom.removeEventListener("mousedown", emulateTouchStart, true);
|
82
|
+
dom.removeEventListener("mousemove", emulateTouchMove, true);
|
83
|
+
dom.removeEventListener("mouseup", emulateTouchEnd, true);
|
84
84
|
}
|
85
85
|
};
|
86
86
|
}, [dom]);
|
87
87
|
}
|
88
|
+
const touchEmulator = (dom = window) => {
|
89
|
+
if (dom) {
|
90
|
+
dom.addEventListener("mousedown", emulateTouchStart, true);
|
91
|
+
dom.addEventListener("mousemove", emulateTouchMove, true);
|
92
|
+
dom.addEventListener("mouseup", emulateTouchEnd, true);
|
93
|
+
}
|
94
|
+
return function() {
|
95
|
+
if (dom) {
|
96
|
+
dom.removeEventListener("mousedown", emulateTouchStart, true);
|
97
|
+
dom.removeEventListener("mousemove", emulateTouchMove, true);
|
98
|
+
dom.removeEventListener("mouseup", emulateTouchEnd, true);
|
99
|
+
}
|
100
|
+
};
|
101
|
+
};
|
102
|
+
var useTouchEmulator_default = useTouchEmulator;
|
88
103
|
export {
|
89
|
-
|
104
|
+
useTouchEmulator_default as default,
|
105
|
+
emulateTouchEnd,
|
106
|
+
emulateTouchMove,
|
107
|
+
emulateTouchStart,
|
108
|
+
touchEmulator
|
90
109
|
};
|