@bifrostui/utils 1.2.9-beta.0 → 1.3.1-beta.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/directionLocationUtil.d.ts +40 -0
- package/dist/directionLocationUtil.js +235 -0
- package/dist/getRootElement/index.d.ts +2 -0
- package/dist/getRootElement/index.js +28 -0
- package/dist/getRootElement/index.miniapp.d.ts +3 -0
- package/dist/getRootElement/index.miniapp.js +42 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +11 -1
- package/dist/render.d.ts +13 -0
- package/dist/render.js +138 -0
- package/es/directionLocationUtil.d.ts +40 -0
- package/es/directionLocationUtil.js +209 -0
- package/es/getRootElement/index.d.ts +2 -0
- package/es/getRootElement/index.js +9 -0
- package/es/getRootElement/index.miniapp.d.ts +3 -0
- package/es/getRootElement/index.miniapp.js +13 -0
- package/es/index.d.ts +3 -0
- package/es/index.js +11 -2
- package/es/render.d.ts +13 -0
- package/es/render.js +104 -0
- package/package.json +3 -2
@@ -0,0 +1,40 @@
|
|
1
|
+
/**
|
2
|
+
* 根据元素宽高判断是否超出边界,超出边界则重新定义方向
|
3
|
+
*/
|
4
|
+
export declare const getNewDirectionLocation: ({ rootOffset, arrowDirection, tipOffset, arrowLocation, }: {
|
5
|
+
rootOffset: any;
|
6
|
+
arrowDirection: any;
|
7
|
+
tipOffset: any;
|
8
|
+
arrowLocation: any;
|
9
|
+
}) => {
|
10
|
+
newArrowDirection: any;
|
11
|
+
newArrowLocation: any;
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* 根据新的气泡位置和箭头位置 计算气泡位置以及箭头位置
|
15
|
+
*/
|
16
|
+
export declare const getDirectionLocationStyle: ({ rootOffset, arrowDirection, tipOffset, arrowLocation, }: {
|
17
|
+
rootOffset: any;
|
18
|
+
arrowDirection: any;
|
19
|
+
tipOffset: any;
|
20
|
+
arrowLocation: any;
|
21
|
+
}) => any;
|
22
|
+
/**
|
23
|
+
* 获取气泡位置和箭头位置
|
24
|
+
*/
|
25
|
+
export declare const getStylesAndLocation: ({ childrenRef, arrowDirection, arrowLocation, selector, }: {
|
26
|
+
childrenRef: any;
|
27
|
+
arrowDirection: any;
|
28
|
+
arrowLocation: any;
|
29
|
+
selector: any;
|
30
|
+
}) => {
|
31
|
+
styles: any;
|
32
|
+
newArrowDirection: any;
|
33
|
+
newArrowLocation: any;
|
34
|
+
};
|
35
|
+
export declare const triggerEventTransform: ({ trigger, click, show, hide }: {
|
36
|
+
trigger: any;
|
37
|
+
click: any;
|
38
|
+
show: any;
|
39
|
+
hide: any;
|
40
|
+
}) => {};
|
@@ -0,0 +1,235 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var directionLocationUtil_exports = {};
|
19
|
+
__export(directionLocationUtil_exports, {
|
20
|
+
getDirectionLocationStyle: () => getDirectionLocationStyle,
|
21
|
+
getNewDirectionLocation: () => getNewDirectionLocation,
|
22
|
+
getStylesAndLocation: () => getStylesAndLocation,
|
23
|
+
triggerEventTransform: () => triggerEventTransform
|
24
|
+
});
|
25
|
+
module.exports = __toCommonJS(directionLocationUtil_exports);
|
26
|
+
const directionCssMap = {
|
27
|
+
left: "right",
|
28
|
+
right: "left",
|
29
|
+
top: "bottom",
|
30
|
+
bottom: "top"
|
31
|
+
};
|
32
|
+
const getNewDirectionLocation = ({
|
33
|
+
rootOffset,
|
34
|
+
arrowDirection,
|
35
|
+
tipOffset,
|
36
|
+
arrowLocation
|
37
|
+
}) => {
|
38
|
+
const { left: cLeft, right: cRight, top: cTop, bottom: cBottom } = rootOffset;
|
39
|
+
const { width, height } = tipOffset;
|
40
|
+
const pgegWidth = document.documentElement.clientWidth || document.body.clientWidth;
|
41
|
+
const pgegHeight = document.documentElement.clientHeight || document.body.clientHeight;
|
42
|
+
let newArrowDirection = arrowDirection;
|
43
|
+
let newArrowLocation = arrowLocation;
|
44
|
+
const isDirectionTop = arrowDirection === "top";
|
45
|
+
const isDirectionBottom = arrowDirection === "bottom";
|
46
|
+
const isDirectionLeft = arrowDirection === "left";
|
47
|
+
const isDirectionRight = arrowDirection === "right";
|
48
|
+
if (isDirectionTop && cTop - height < 0 || isDirectionBottom && cBottom + height > pgegHeight || isDirectionLeft && cLeft - width < 0 || isDirectionRight && cRight + width > pgegWidth) {
|
49
|
+
newArrowDirection = directionCssMap[arrowDirection];
|
50
|
+
}
|
51
|
+
if (arrowLocation === "top" && cTop + height > pgegHeight || arrowLocation === "bottom" && cBottom - height < 0 || arrowLocation === "left" && cLeft + width > pgegWidth || arrowLocation === "right" && cRight - width < 0) {
|
52
|
+
newArrowLocation = directionCssMap[arrowLocation];
|
53
|
+
}
|
54
|
+
const isCenter = arrowLocation === "center";
|
55
|
+
if (isCenter && (isDirectionTop || isDirectionBottom)) {
|
56
|
+
if (cLeft + width > pgegWidth) {
|
57
|
+
newArrowLocation = directionCssMap.left;
|
58
|
+
} else if (cRight - width < 0) {
|
59
|
+
newArrowLocation = directionCssMap.right;
|
60
|
+
}
|
61
|
+
} else if (isCenter && (isDirectionLeft || isDirectionRight)) {
|
62
|
+
if (cTop + height > pgegHeight) {
|
63
|
+
newArrowLocation = directionCssMap.top;
|
64
|
+
} else if (cBottom - height < 0) {
|
65
|
+
newArrowLocation = directionCssMap.bottom;
|
66
|
+
}
|
67
|
+
}
|
68
|
+
return {
|
69
|
+
newArrowDirection,
|
70
|
+
newArrowLocation
|
71
|
+
};
|
72
|
+
};
|
73
|
+
const getDirectionLocationStyle = ({
|
74
|
+
rootOffset,
|
75
|
+
arrowDirection,
|
76
|
+
tipOffset,
|
77
|
+
arrowLocation
|
78
|
+
}) => {
|
79
|
+
const scrollTop = window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop;
|
80
|
+
const scrollLeft = window.screenX >= 0 && window.screenX || document.documentElement.scrollLeft;
|
81
|
+
const styles = {};
|
82
|
+
const {
|
83
|
+
width: cWidth,
|
84
|
+
height: cHeight,
|
85
|
+
left: cLeft,
|
86
|
+
right: cRight,
|
87
|
+
top: cTop,
|
88
|
+
bottom: cBottom
|
89
|
+
} = rootOffset;
|
90
|
+
const { width, height } = tipOffset;
|
91
|
+
if (arrowDirection === "top") {
|
92
|
+
styles.top = cTop;
|
93
|
+
styles.transform = `translateY(-100%)`;
|
94
|
+
switch (arrowLocation) {
|
95
|
+
case "left":
|
96
|
+
styles.left = cLeft;
|
97
|
+
break;
|
98
|
+
case "center":
|
99
|
+
styles.left = cLeft + (cWidth - width) / 2;
|
100
|
+
break;
|
101
|
+
case "right":
|
102
|
+
styles.left = cRight;
|
103
|
+
styles.transform = `translate(-100%, -100%)`;
|
104
|
+
break;
|
105
|
+
default:
|
106
|
+
break;
|
107
|
+
}
|
108
|
+
} else if (arrowDirection === "bottom") {
|
109
|
+
styles.top = cBottom;
|
110
|
+
switch (arrowLocation) {
|
111
|
+
case "left":
|
112
|
+
styles.left = cLeft;
|
113
|
+
break;
|
114
|
+
case "center":
|
115
|
+
styles.left = cLeft + (cWidth - width) / 2;
|
116
|
+
break;
|
117
|
+
case "right":
|
118
|
+
styles.left = cRight;
|
119
|
+
styles.transform = `translateX(-100%)`;
|
120
|
+
break;
|
121
|
+
default:
|
122
|
+
break;
|
123
|
+
}
|
124
|
+
} else if (arrowDirection === "left") {
|
125
|
+
styles.left = cLeft;
|
126
|
+
styles.transform = `translateX(-100%)`;
|
127
|
+
switch (arrowLocation) {
|
128
|
+
case "top":
|
129
|
+
styles.top = cTop;
|
130
|
+
break;
|
131
|
+
case "center":
|
132
|
+
styles.top = cTop + (cHeight - height) / 2;
|
133
|
+
break;
|
134
|
+
case "bottom":
|
135
|
+
styles.top = cBottom;
|
136
|
+
styles.transform = `translate(-100%, -100%)`;
|
137
|
+
break;
|
138
|
+
default:
|
139
|
+
break;
|
140
|
+
}
|
141
|
+
} else if (arrowDirection === "right") {
|
142
|
+
styles.left = cRight;
|
143
|
+
switch (arrowLocation) {
|
144
|
+
case "top":
|
145
|
+
styles.top = cTop;
|
146
|
+
break;
|
147
|
+
case "center":
|
148
|
+
styles.top = cTop + (cHeight - height) / 2;
|
149
|
+
break;
|
150
|
+
case "bottom":
|
151
|
+
styles.top = cBottom;
|
152
|
+
styles.transform = `translateY(-100%)`;
|
153
|
+
break;
|
154
|
+
default:
|
155
|
+
break;
|
156
|
+
}
|
157
|
+
}
|
158
|
+
if (styles.top) {
|
159
|
+
styles.top = `${styles.top + scrollTop}px`;
|
160
|
+
}
|
161
|
+
if (styles.left) {
|
162
|
+
styles.left = `${styles.left + scrollLeft}px`;
|
163
|
+
}
|
164
|
+
return styles;
|
165
|
+
};
|
166
|
+
const getStylesAndLocation = ({
|
167
|
+
childrenRef,
|
168
|
+
arrowDirection,
|
169
|
+
arrowLocation,
|
170
|
+
selector
|
171
|
+
}) => {
|
172
|
+
const rootOffset = childrenRef.current.getBoundingClientRect();
|
173
|
+
const $rtDom = document.querySelector(selector);
|
174
|
+
if (!$rtDom)
|
175
|
+
return null;
|
176
|
+
const tipOffset = $rtDom.getBoundingClientRect();
|
177
|
+
const { newArrowDirection, newArrowLocation } = getNewDirectionLocation({
|
178
|
+
rootOffset,
|
179
|
+
arrowDirection,
|
180
|
+
tipOffset,
|
181
|
+
arrowLocation
|
182
|
+
});
|
183
|
+
const styles = getDirectionLocationStyle({
|
184
|
+
rootOffset,
|
185
|
+
arrowDirection: newArrowDirection,
|
186
|
+
tipOffset,
|
187
|
+
arrowLocation: newArrowLocation
|
188
|
+
});
|
189
|
+
styles.visibility = "visible";
|
190
|
+
return {
|
191
|
+
styles,
|
192
|
+
newArrowDirection,
|
193
|
+
newArrowLocation
|
194
|
+
};
|
195
|
+
};
|
196
|
+
const onMouseEnter = "onMouseEnter";
|
197
|
+
const onMouseLeave = "onMouseLeave";
|
198
|
+
const onClick = "onClick";
|
199
|
+
const TriggerEvent = {
|
200
|
+
hover: [onMouseEnter, onMouseLeave],
|
201
|
+
click: [onClick]
|
202
|
+
};
|
203
|
+
const triggerEventTransform = ({ trigger, click, show, hide }) => {
|
204
|
+
let triggers = [];
|
205
|
+
if (typeof trigger === "string") {
|
206
|
+
triggers = [trigger];
|
207
|
+
} else if (Array.isArray(trigger)) {
|
208
|
+
triggers = trigger;
|
209
|
+
} else {
|
210
|
+
triggers = ["click"];
|
211
|
+
}
|
212
|
+
const option = {};
|
213
|
+
triggers.forEach((item) => {
|
214
|
+
const eventNames = TriggerEvent[item];
|
215
|
+
eventNames.forEach((eventName) => {
|
216
|
+
let cbk;
|
217
|
+
if (eventName === onMouseEnter) {
|
218
|
+
cbk = show;
|
219
|
+
} else if (eventName === onMouseLeave) {
|
220
|
+
cbk = hide;
|
221
|
+
} else if (eventName === onClick) {
|
222
|
+
cbk = click;
|
223
|
+
}
|
224
|
+
option[eventName] = cbk;
|
225
|
+
});
|
226
|
+
});
|
227
|
+
return option;
|
228
|
+
};
|
229
|
+
// Annotate the CommonJS export names for ESM import in node:
|
230
|
+
0 && (module.exports = {
|
231
|
+
getDirectionLocationStyle,
|
232
|
+
getNewDirectionLocation,
|
233
|
+
getStylesAndLocation,
|
234
|
+
triggerEventTransform
|
235
|
+
});
|
@@ -0,0 +1,28 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
5
|
+
var __export = (target, all) => {
|
6
|
+
for (var name in all)
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
8
|
+
};
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
11
|
+
for (let key of __getOwnPropNames(from))
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
14
|
+
}
|
15
|
+
return to;
|
16
|
+
};
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
18
|
+
var getRootElement_exports = {};
|
19
|
+
__export(getRootElement_exports, {
|
20
|
+
default: () => getRootElement_default
|
21
|
+
});
|
22
|
+
module.exports = __toCommonJS(getRootElement_exports);
|
23
|
+
const getRootElement = (rootEle) => {
|
24
|
+
const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
|
25
|
+
const defaultRootElement = document.body;
|
26
|
+
return rootElement || defaultRootElement;
|
27
|
+
};
|
28
|
+
var getRootElement_default = getRootElement;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
7
|
+
var __export = (target, all) => {
|
8
|
+
for (var name in all)
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
10
|
+
};
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
13
|
+
for (let key of __getOwnPropNames(from))
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
16
|
+
}
|
17
|
+
return to;
|
18
|
+
};
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
25
|
+
mod
|
26
|
+
));
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
28
|
+
var index_miniapp_exports = {};
|
29
|
+
__export(index_miniapp_exports, {
|
30
|
+
default: () => index_miniapp_default
|
31
|
+
});
|
32
|
+
module.exports = __toCommonJS(index_miniapp_exports);
|
33
|
+
var import_taro = __toESM(require("@tarojs/taro"));
|
34
|
+
const getRootElement = (rootEle) => {
|
35
|
+
const currentPages = import_taro.default.getCurrentPages() || [];
|
36
|
+
const currentPage = currentPages[currentPages.length - 1];
|
37
|
+
const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
|
38
|
+
const defaultRootElement = document.getElementById(pageElement);
|
39
|
+
const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
|
40
|
+
return rootElement || defaultRootElement;
|
41
|
+
};
|
42
|
+
var index_miniapp_default = getRootElement;
|
package/dist/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export { default as debounce } from './debounce';
|
2
|
+
export { getStylesAndLocation, triggerEventTransform, } from './directionLocationUtil';
|
2
3
|
export { default as convertHexToRGBA } from './hex2rgba';
|
3
4
|
export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch, } from './hooks';
|
4
5
|
export { default as isDev } from './isDev';
|
@@ -8,5 +9,7 @@ export { default as throttle } from './throttle';
|
|
8
9
|
export { default as toArray } from './toArray';
|
9
10
|
export { default as blockTouch } from './touchBlocker';
|
10
11
|
export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
|
12
|
+
export { default as getRootElement } from './getRootElement';
|
11
13
|
export { default as getBoundingClientRect } from './getBoundingClientRect';
|
12
14
|
export * from './isType';
|
15
|
+
export * from './render';
|
package/dist/index.js
CHANGED
@@ -35,6 +35,8 @@ __export(src_exports, {
|
|
35
35
|
duration: () => import_transitions.duration,
|
36
36
|
easing: () => import_transitions.easing,
|
37
37
|
getBoundingClientRect: () => import_getBoundingClientRect.default,
|
38
|
+
getRootElement: () => import_getRootElement.default,
|
39
|
+
getStylesAndLocation: () => import_directionLocationUtil.getStylesAndLocation,
|
38
40
|
getTransitionProps: () => import_transitions.getTransitionProps,
|
39
41
|
isAlipay: () => import_isMini.isAlipay,
|
40
42
|
isDev: () => import_isDev.default,
|
@@ -44,6 +46,7 @@ __export(src_exports, {
|
|
44
46
|
setRef: () => import_setRef.default,
|
45
47
|
throttle: () => import_throttle.default,
|
46
48
|
toArray: () => import_toArray.default,
|
49
|
+
triggerEventTransform: () => import_directionLocationUtil.triggerEventTransform,
|
47
50
|
useDidMountEffect: () => import_hooks.useDidMountEffect,
|
48
51
|
useDomCss: () => import_hooks.useDomCss,
|
49
52
|
useDomReady: () => import_hooks.useDomReady,
|
@@ -56,6 +59,7 @@ __export(src_exports, {
|
|
56
59
|
});
|
57
60
|
module.exports = __toCommonJS(src_exports);
|
58
61
|
var import_debounce = __toESM(require("./debounce"));
|
62
|
+
var import_directionLocationUtil = require("./directionLocationUtil");
|
59
63
|
var import_hex2rgba = __toESM(require("./hex2rgba"));
|
60
64
|
var import_hooks = require("./hooks");
|
61
65
|
var import_isDev = __toESM(require("./isDev"));
|
@@ -65,8 +69,10 @@ var import_throttle = __toESM(require("./throttle"));
|
|
65
69
|
var import_toArray = __toESM(require("./toArray"));
|
66
70
|
var import_touchBlocker = __toESM(require("./touchBlocker"));
|
67
71
|
var import_transitions = require("./transitions");
|
72
|
+
var import_getRootElement = __toESM(require("./getRootElement"));
|
68
73
|
var import_getBoundingClientRect = __toESM(require("./getBoundingClientRect"));
|
69
74
|
__reExport(src_exports, require("./isType"), module.exports);
|
75
|
+
__reExport(src_exports, require("./render"), module.exports);
|
70
76
|
// Annotate the CommonJS export names for ESM import in node:
|
71
77
|
0 && (module.exports = {
|
72
78
|
blockTouch,
|
@@ -76,6 +82,8 @@ __reExport(src_exports, require("./isType"), module.exports);
|
|
76
82
|
duration,
|
77
83
|
easing,
|
78
84
|
getBoundingClientRect,
|
85
|
+
getRootElement,
|
86
|
+
getStylesAndLocation,
|
79
87
|
getTransitionProps,
|
80
88
|
isAlipay,
|
81
89
|
isDev,
|
@@ -85,6 +93,7 @@ __reExport(src_exports, require("./isType"), module.exports);
|
|
85
93
|
setRef,
|
86
94
|
throttle,
|
87
95
|
toArray,
|
96
|
+
triggerEventTransform,
|
88
97
|
useDidMountEffect,
|
89
98
|
useDomCss,
|
90
99
|
useDomReady,
|
@@ -94,5 +103,6 @@ __reExport(src_exports, require("./isType"), module.exports);
|
|
94
103
|
useTouch,
|
95
104
|
useTouchEmulator,
|
96
105
|
useValue,
|
97
|
-
...require("./isType")
|
106
|
+
...require("./isType"),
|
107
|
+
...require("./render")
|
98
108
|
});
|
package/dist/render.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ReactElement } from 'react';
|
2
|
+
import type { Root } from 'react-dom/client';
|
3
|
+
declare const MARK = "__bifrostui_react_root__";
|
4
|
+
type ContainerType = (Element | DocumentFragment) & {
|
5
|
+
[MARK]?: Root;
|
6
|
+
};
|
7
|
+
/** @private Test usage. Not work in prod */
|
8
|
+
export declare function testModernRender(node: ReactElement, container: ContainerType, isTest: boolean): void;
|
9
|
+
export declare function render(node: ReactElement, container: ContainerType): void;
|
10
|
+
/** @private Test usage. Not work in prod */
|
11
|
+
export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): boolean;
|
12
|
+
export declare function unmount(container: ContainerType): boolean | Promise<void>;
|
13
|
+
export {};
|
package/dist/render.js
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
var __create = Object.create;
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
10
|
+
var __spreadValues = (a, b) => {
|
11
|
+
for (var prop in b || (b = {}))
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
if (__getOwnPropSymbols)
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
16
|
+
if (__propIsEnum.call(b, prop))
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
18
|
+
}
|
19
|
+
return a;
|
20
|
+
};
|
21
|
+
var __export = (target, all) => {
|
22
|
+
for (var name in all)
|
23
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
24
|
+
};
|
25
|
+
var __copyProps = (to, from, except, desc) => {
|
26
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
27
|
+
for (let key of __getOwnPropNames(from))
|
28
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
29
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
30
|
+
}
|
31
|
+
return to;
|
32
|
+
};
|
33
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
34
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
35
|
+
// file that has been converted to a CommonJS file using a Babel-
|
36
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
37
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
38
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
39
|
+
mod
|
40
|
+
));
|
41
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
42
|
+
var __async = (__this, __arguments, generator) => {
|
43
|
+
return new Promise((resolve, reject) => {
|
44
|
+
var fulfilled = (value) => {
|
45
|
+
try {
|
46
|
+
step(generator.next(value));
|
47
|
+
} catch (e) {
|
48
|
+
reject(e);
|
49
|
+
}
|
50
|
+
};
|
51
|
+
var rejected = (value) => {
|
52
|
+
try {
|
53
|
+
step(generator.throw(value));
|
54
|
+
} catch (e) {
|
55
|
+
reject(e);
|
56
|
+
}
|
57
|
+
};
|
58
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
59
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
60
|
+
});
|
61
|
+
};
|
62
|
+
var render_exports = {};
|
63
|
+
__export(render_exports, {
|
64
|
+
render: () => render,
|
65
|
+
testLegacyUnmount: () => testLegacyUnmount,
|
66
|
+
testModernRender: () => testModernRender,
|
67
|
+
unmount: () => unmount
|
68
|
+
});
|
69
|
+
module.exports = __toCommonJS(render_exports);
|
70
|
+
var ReactDOM = __toESM(require("react-dom"));
|
71
|
+
const MARK = "__bifrostui_react_root__";
|
72
|
+
const fullClone = __spreadValues({}, ReactDOM);
|
73
|
+
const { version, render: reactRender, unmountComponentAtNode } = fullClone;
|
74
|
+
let createRoot;
|
75
|
+
try {
|
76
|
+
if (Number((version || "").split(".")[0]) >= 18 && fullClone.createRoot) {
|
77
|
+
createRoot = fullClone.createRoot;
|
78
|
+
}
|
79
|
+
} catch (e) {
|
80
|
+
}
|
81
|
+
function toggleWarning(skip) {
|
82
|
+
const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = fullClone;
|
83
|
+
if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === "object") {
|
84
|
+
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
function testModernRender(node, container, isTest) {
|
88
|
+
if (process.env.NODE_ENV !== "production" && isTest) {
|
89
|
+
return legacyRender(node, container);
|
90
|
+
}
|
91
|
+
}
|
92
|
+
function modernRender(node, container) {
|
93
|
+
toggleWarning(true);
|
94
|
+
const root = container[MARK] || createRoot(container);
|
95
|
+
toggleWarning(false);
|
96
|
+
root.render(node);
|
97
|
+
container[MARK] = root;
|
98
|
+
}
|
99
|
+
function legacyRender(node, container) {
|
100
|
+
reactRender(node, container);
|
101
|
+
}
|
102
|
+
function render(node, container) {
|
103
|
+
if (createRoot) {
|
104
|
+
modernRender(node, container);
|
105
|
+
return;
|
106
|
+
}
|
107
|
+
legacyRender(node, container);
|
108
|
+
}
|
109
|
+
function testLegacyUnmount(container, isTest) {
|
110
|
+
if (process.env.NODE_ENV !== "production" && isTest) {
|
111
|
+
return legacyUnmount(container);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
function modernUnmount(container) {
|
115
|
+
return __async(this, null, function* () {
|
116
|
+
return Promise.resolve().then(() => {
|
117
|
+
var _a;
|
118
|
+
(_a = container[MARK]) == null ? void 0 : _a.unmount();
|
119
|
+
delete container[MARK];
|
120
|
+
});
|
121
|
+
});
|
122
|
+
}
|
123
|
+
function legacyUnmount(container) {
|
124
|
+
return unmountComponentAtNode(container);
|
125
|
+
}
|
126
|
+
function unmount(container) {
|
127
|
+
if (createRoot) {
|
128
|
+
return modernUnmount(container);
|
129
|
+
}
|
130
|
+
return legacyUnmount(container);
|
131
|
+
}
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
133
|
+
0 && (module.exports = {
|
134
|
+
render,
|
135
|
+
testLegacyUnmount,
|
136
|
+
testModernRender,
|
137
|
+
unmount
|
138
|
+
});
|
@@ -0,0 +1,40 @@
|
|
1
|
+
/**
|
2
|
+
* 根据元素宽高判断是否超出边界,超出边界则重新定义方向
|
3
|
+
*/
|
4
|
+
export declare const getNewDirectionLocation: ({ rootOffset, arrowDirection, tipOffset, arrowLocation, }: {
|
5
|
+
rootOffset: any;
|
6
|
+
arrowDirection: any;
|
7
|
+
tipOffset: any;
|
8
|
+
arrowLocation: any;
|
9
|
+
}) => {
|
10
|
+
newArrowDirection: any;
|
11
|
+
newArrowLocation: any;
|
12
|
+
};
|
13
|
+
/**
|
14
|
+
* 根据新的气泡位置和箭头位置 计算气泡位置以及箭头位置
|
15
|
+
*/
|
16
|
+
export declare const getDirectionLocationStyle: ({ rootOffset, arrowDirection, tipOffset, arrowLocation, }: {
|
17
|
+
rootOffset: any;
|
18
|
+
arrowDirection: any;
|
19
|
+
tipOffset: any;
|
20
|
+
arrowLocation: any;
|
21
|
+
}) => any;
|
22
|
+
/**
|
23
|
+
* 获取气泡位置和箭头位置
|
24
|
+
*/
|
25
|
+
export declare const getStylesAndLocation: ({ childrenRef, arrowDirection, arrowLocation, selector, }: {
|
26
|
+
childrenRef: any;
|
27
|
+
arrowDirection: any;
|
28
|
+
arrowLocation: any;
|
29
|
+
selector: any;
|
30
|
+
}) => {
|
31
|
+
styles: any;
|
32
|
+
newArrowDirection: any;
|
33
|
+
newArrowLocation: any;
|
34
|
+
};
|
35
|
+
export declare const triggerEventTransform: ({ trigger, click, show, hide }: {
|
36
|
+
trigger: any;
|
37
|
+
click: any;
|
38
|
+
show: any;
|
39
|
+
hide: any;
|
40
|
+
}) => {};
|
@@ -0,0 +1,209 @@
|
|
1
|
+
const directionCssMap = {
|
2
|
+
left: "right",
|
3
|
+
right: "left",
|
4
|
+
top: "bottom",
|
5
|
+
bottom: "top"
|
6
|
+
};
|
7
|
+
const getNewDirectionLocation = ({
|
8
|
+
rootOffset,
|
9
|
+
arrowDirection,
|
10
|
+
tipOffset,
|
11
|
+
arrowLocation
|
12
|
+
}) => {
|
13
|
+
const { left: cLeft, right: cRight, top: cTop, bottom: cBottom } = rootOffset;
|
14
|
+
const { width, height } = tipOffset;
|
15
|
+
const pgegWidth = document.documentElement.clientWidth || document.body.clientWidth;
|
16
|
+
const pgegHeight = document.documentElement.clientHeight || document.body.clientHeight;
|
17
|
+
let newArrowDirection = arrowDirection;
|
18
|
+
let newArrowLocation = arrowLocation;
|
19
|
+
const isDirectionTop = arrowDirection === "top";
|
20
|
+
const isDirectionBottom = arrowDirection === "bottom";
|
21
|
+
const isDirectionLeft = arrowDirection === "left";
|
22
|
+
const isDirectionRight = arrowDirection === "right";
|
23
|
+
if (isDirectionTop && cTop - height < 0 || isDirectionBottom && cBottom + height > pgegHeight || isDirectionLeft && cLeft - width < 0 || isDirectionRight && cRight + width > pgegWidth) {
|
24
|
+
newArrowDirection = directionCssMap[arrowDirection];
|
25
|
+
}
|
26
|
+
if (arrowLocation === "top" && cTop + height > pgegHeight || arrowLocation === "bottom" && cBottom - height < 0 || arrowLocation === "left" && cLeft + width > pgegWidth || arrowLocation === "right" && cRight - width < 0) {
|
27
|
+
newArrowLocation = directionCssMap[arrowLocation];
|
28
|
+
}
|
29
|
+
const isCenter = arrowLocation === "center";
|
30
|
+
if (isCenter && (isDirectionTop || isDirectionBottom)) {
|
31
|
+
if (cLeft + width > pgegWidth) {
|
32
|
+
newArrowLocation = directionCssMap.left;
|
33
|
+
} else if (cRight - width < 0) {
|
34
|
+
newArrowLocation = directionCssMap.right;
|
35
|
+
}
|
36
|
+
} else if (isCenter && (isDirectionLeft || isDirectionRight)) {
|
37
|
+
if (cTop + height > pgegHeight) {
|
38
|
+
newArrowLocation = directionCssMap.top;
|
39
|
+
} else if (cBottom - height < 0) {
|
40
|
+
newArrowLocation = directionCssMap.bottom;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
return {
|
44
|
+
newArrowDirection,
|
45
|
+
newArrowLocation
|
46
|
+
};
|
47
|
+
};
|
48
|
+
const getDirectionLocationStyle = ({
|
49
|
+
rootOffset,
|
50
|
+
arrowDirection,
|
51
|
+
tipOffset,
|
52
|
+
arrowLocation
|
53
|
+
}) => {
|
54
|
+
const scrollTop = window.scrollY >= 0 && window.scrollY || document.documentElement.scrollTop;
|
55
|
+
const scrollLeft = window.screenX >= 0 && window.screenX || document.documentElement.scrollLeft;
|
56
|
+
const styles = {};
|
57
|
+
const {
|
58
|
+
width: cWidth,
|
59
|
+
height: cHeight,
|
60
|
+
left: cLeft,
|
61
|
+
right: cRight,
|
62
|
+
top: cTop,
|
63
|
+
bottom: cBottom
|
64
|
+
} = rootOffset;
|
65
|
+
const { width, height } = tipOffset;
|
66
|
+
if (arrowDirection === "top") {
|
67
|
+
styles.top = cTop;
|
68
|
+
styles.transform = `translateY(-100%)`;
|
69
|
+
switch (arrowLocation) {
|
70
|
+
case "left":
|
71
|
+
styles.left = cLeft;
|
72
|
+
break;
|
73
|
+
case "center":
|
74
|
+
styles.left = cLeft + (cWidth - width) / 2;
|
75
|
+
break;
|
76
|
+
case "right":
|
77
|
+
styles.left = cRight;
|
78
|
+
styles.transform = `translate(-100%, -100%)`;
|
79
|
+
break;
|
80
|
+
default:
|
81
|
+
break;
|
82
|
+
}
|
83
|
+
} else if (arrowDirection === "bottom") {
|
84
|
+
styles.top = cBottom;
|
85
|
+
switch (arrowLocation) {
|
86
|
+
case "left":
|
87
|
+
styles.left = cLeft;
|
88
|
+
break;
|
89
|
+
case "center":
|
90
|
+
styles.left = cLeft + (cWidth - width) / 2;
|
91
|
+
break;
|
92
|
+
case "right":
|
93
|
+
styles.left = cRight;
|
94
|
+
styles.transform = `translateX(-100%)`;
|
95
|
+
break;
|
96
|
+
default:
|
97
|
+
break;
|
98
|
+
}
|
99
|
+
} else if (arrowDirection === "left") {
|
100
|
+
styles.left = cLeft;
|
101
|
+
styles.transform = `translateX(-100%)`;
|
102
|
+
switch (arrowLocation) {
|
103
|
+
case "top":
|
104
|
+
styles.top = cTop;
|
105
|
+
break;
|
106
|
+
case "center":
|
107
|
+
styles.top = cTop + (cHeight - height) / 2;
|
108
|
+
break;
|
109
|
+
case "bottom":
|
110
|
+
styles.top = cBottom;
|
111
|
+
styles.transform = `translate(-100%, -100%)`;
|
112
|
+
break;
|
113
|
+
default:
|
114
|
+
break;
|
115
|
+
}
|
116
|
+
} else if (arrowDirection === "right") {
|
117
|
+
styles.left = cRight;
|
118
|
+
switch (arrowLocation) {
|
119
|
+
case "top":
|
120
|
+
styles.top = cTop;
|
121
|
+
break;
|
122
|
+
case "center":
|
123
|
+
styles.top = cTop + (cHeight - height) / 2;
|
124
|
+
break;
|
125
|
+
case "bottom":
|
126
|
+
styles.top = cBottom;
|
127
|
+
styles.transform = `translateY(-100%)`;
|
128
|
+
break;
|
129
|
+
default:
|
130
|
+
break;
|
131
|
+
}
|
132
|
+
}
|
133
|
+
if (styles.top) {
|
134
|
+
styles.top = `${styles.top + scrollTop}px`;
|
135
|
+
}
|
136
|
+
if (styles.left) {
|
137
|
+
styles.left = `${styles.left + scrollLeft}px`;
|
138
|
+
}
|
139
|
+
return styles;
|
140
|
+
};
|
141
|
+
const getStylesAndLocation = ({
|
142
|
+
childrenRef,
|
143
|
+
arrowDirection,
|
144
|
+
arrowLocation,
|
145
|
+
selector
|
146
|
+
}) => {
|
147
|
+
const rootOffset = childrenRef.current.getBoundingClientRect();
|
148
|
+
const $rtDom = document.querySelector(selector);
|
149
|
+
if (!$rtDom)
|
150
|
+
return null;
|
151
|
+
const tipOffset = $rtDom.getBoundingClientRect();
|
152
|
+
const { newArrowDirection, newArrowLocation } = getNewDirectionLocation({
|
153
|
+
rootOffset,
|
154
|
+
arrowDirection,
|
155
|
+
tipOffset,
|
156
|
+
arrowLocation
|
157
|
+
});
|
158
|
+
const styles = getDirectionLocationStyle({
|
159
|
+
rootOffset,
|
160
|
+
arrowDirection: newArrowDirection,
|
161
|
+
tipOffset,
|
162
|
+
arrowLocation: newArrowLocation
|
163
|
+
});
|
164
|
+
styles.visibility = "visible";
|
165
|
+
return {
|
166
|
+
styles,
|
167
|
+
newArrowDirection,
|
168
|
+
newArrowLocation
|
169
|
+
};
|
170
|
+
};
|
171
|
+
const onMouseEnter = "onMouseEnter";
|
172
|
+
const onMouseLeave = "onMouseLeave";
|
173
|
+
const onClick = "onClick";
|
174
|
+
const TriggerEvent = {
|
175
|
+
hover: [onMouseEnter, onMouseLeave],
|
176
|
+
click: [onClick]
|
177
|
+
};
|
178
|
+
const triggerEventTransform = ({ trigger, click, show, hide }) => {
|
179
|
+
let triggers = [];
|
180
|
+
if (typeof trigger === "string") {
|
181
|
+
triggers = [trigger];
|
182
|
+
} else if (Array.isArray(trigger)) {
|
183
|
+
triggers = trigger;
|
184
|
+
} else {
|
185
|
+
triggers = ["click"];
|
186
|
+
}
|
187
|
+
const option = {};
|
188
|
+
triggers.forEach((item) => {
|
189
|
+
const eventNames = TriggerEvent[item];
|
190
|
+
eventNames.forEach((eventName) => {
|
191
|
+
let cbk;
|
192
|
+
if (eventName === onMouseEnter) {
|
193
|
+
cbk = show;
|
194
|
+
} else if (eventName === onMouseLeave) {
|
195
|
+
cbk = hide;
|
196
|
+
} else if (eventName === onClick) {
|
197
|
+
cbk = click;
|
198
|
+
}
|
199
|
+
option[eventName] = cbk;
|
200
|
+
});
|
201
|
+
});
|
202
|
+
return option;
|
203
|
+
};
|
204
|
+
export {
|
205
|
+
getDirectionLocationStyle,
|
206
|
+
getNewDirectionLocation,
|
207
|
+
getStylesAndLocation,
|
208
|
+
triggerEventTransform
|
209
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
const getRootElement = (rootEle) => {
|
2
|
+
const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
|
3
|
+
const defaultRootElement = document.body;
|
4
|
+
return rootElement || defaultRootElement;
|
5
|
+
};
|
6
|
+
var getRootElement_default = getRootElement;
|
7
|
+
export {
|
8
|
+
getRootElement_default as default
|
9
|
+
};
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import Taro from "@tarojs/taro";
|
2
|
+
const getRootElement = (rootEle) => {
|
3
|
+
const currentPages = Taro.getCurrentPages() || [];
|
4
|
+
const currentPage = currentPages[currentPages.length - 1];
|
5
|
+
const pageElement = currentPage == null ? void 0 : currentPage.$taroPath;
|
6
|
+
const defaultRootElement = document.getElementById(pageElement);
|
7
|
+
const rootElement = typeof rootEle === "function" ? rootEle() : rootEle;
|
8
|
+
return rootElement || defaultRootElement;
|
9
|
+
};
|
10
|
+
var index_miniapp_default = getRootElement;
|
11
|
+
export {
|
12
|
+
index_miniapp_default as default
|
13
|
+
};
|
package/es/index.d.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
export { default as debounce } from './debounce';
|
2
|
+
export { getStylesAndLocation, triggerEventTransform, } from './directionLocationUtil';
|
2
3
|
export { default as convertHexToRGBA } from './hex2rgba';
|
3
4
|
export { useDidMountEffect, useEventCallback, useForkRef, useTouchEmulator, useValue, useDomReady, useSize, useDomCss, useTouch, } from './hooks';
|
4
5
|
export { default as isDev } from './isDev';
|
@@ -8,5 +9,7 @@ export { default as throttle } from './throttle';
|
|
8
9
|
export { default as toArray } from './toArray';
|
9
10
|
export { default as blockTouch } from './touchBlocker';
|
10
11
|
export { easing, duration, getTransitionProps, createTransitions, } from './transitions';
|
12
|
+
export { default as getRootElement } from './getRootElement';
|
11
13
|
export { default as getBoundingClientRect } from './getBoundingClientRect';
|
12
14
|
export * from './isType';
|
15
|
+
export * from './render';
|
package/es/index.js
CHANGED
@@ -1,4 +1,8 @@
|
|
1
1
|
import { default as default2 } from "./debounce";
|
2
|
+
import {
|
3
|
+
getStylesAndLocation,
|
4
|
+
triggerEventTransform
|
5
|
+
} from "./directionLocationUtil";
|
2
6
|
import { default as default3 } from "./hex2rgba";
|
3
7
|
import {
|
4
8
|
useDidMountEffect,
|
@@ -23,8 +27,10 @@ import {
|
|
23
27
|
getTransitionProps,
|
24
28
|
createTransitions
|
25
29
|
} from "./transitions";
|
26
|
-
import { default as default9 } from "./
|
30
|
+
import { default as default9 } from "./getRootElement";
|
31
|
+
import { default as default10 } from "./getBoundingClientRect";
|
27
32
|
export * from "./isType";
|
33
|
+
export * from "./render";
|
28
34
|
export {
|
29
35
|
default8 as blockTouch,
|
30
36
|
default3 as convertHexToRGBA,
|
@@ -32,7 +38,9 @@ export {
|
|
32
38
|
default2 as debounce,
|
33
39
|
duration,
|
34
40
|
easing,
|
35
|
-
|
41
|
+
default10 as getBoundingClientRect,
|
42
|
+
default9 as getRootElement,
|
43
|
+
getStylesAndLocation,
|
36
44
|
getTransitionProps,
|
37
45
|
isAlipay,
|
38
46
|
default4 as isDev,
|
@@ -42,6 +50,7 @@ export {
|
|
42
50
|
default5 as setRef,
|
43
51
|
default6 as throttle,
|
44
52
|
default7 as toArray,
|
53
|
+
triggerEventTransform,
|
45
54
|
useDidMountEffect,
|
46
55
|
useDomCss,
|
47
56
|
useDomReady,
|
package/es/render.d.ts
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
import { ReactElement } from 'react';
|
2
|
+
import type { Root } from 'react-dom/client';
|
3
|
+
declare const MARK = "__bifrostui_react_root__";
|
4
|
+
type ContainerType = (Element | DocumentFragment) & {
|
5
|
+
[MARK]?: Root;
|
6
|
+
};
|
7
|
+
/** @private Test usage. Not work in prod */
|
8
|
+
export declare function testModernRender(node: ReactElement, container: ContainerType, isTest: boolean): void;
|
9
|
+
export declare function render(node: ReactElement, container: ContainerType): void;
|
10
|
+
/** @private Test usage. Not work in prod */
|
11
|
+
export declare function testLegacyUnmount(container: ContainerType, isTest: boolean): boolean;
|
12
|
+
export declare function unmount(container: ContainerType): boolean | Promise<void>;
|
13
|
+
export {};
|
package/es/render.js
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
var __defProp = Object.defineProperty;
|
2
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
3
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
4
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
5
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
6
|
+
var __spreadValues = (a, b) => {
|
7
|
+
for (var prop in b || (b = {}))
|
8
|
+
if (__hasOwnProp.call(b, prop))
|
9
|
+
__defNormalProp(a, prop, b[prop]);
|
10
|
+
if (__getOwnPropSymbols)
|
11
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
12
|
+
if (__propIsEnum.call(b, prop))
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
14
|
+
}
|
15
|
+
return a;
|
16
|
+
};
|
17
|
+
var __async = (__this, __arguments, generator) => {
|
18
|
+
return new Promise((resolve, reject) => {
|
19
|
+
var fulfilled = (value) => {
|
20
|
+
try {
|
21
|
+
step(generator.next(value));
|
22
|
+
} catch (e) {
|
23
|
+
reject(e);
|
24
|
+
}
|
25
|
+
};
|
26
|
+
var rejected = (value) => {
|
27
|
+
try {
|
28
|
+
step(generator.throw(value));
|
29
|
+
} catch (e) {
|
30
|
+
reject(e);
|
31
|
+
}
|
32
|
+
};
|
33
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
34
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
35
|
+
});
|
36
|
+
};
|
37
|
+
import * as ReactDOM from "react-dom";
|
38
|
+
const MARK = "__bifrostui_react_root__";
|
39
|
+
const fullClone = __spreadValues({}, ReactDOM);
|
40
|
+
const { version, render: reactRender, unmountComponentAtNode } = fullClone;
|
41
|
+
let createRoot;
|
42
|
+
try {
|
43
|
+
if (Number((version || "").split(".")[0]) >= 18 && fullClone.createRoot) {
|
44
|
+
createRoot = fullClone.createRoot;
|
45
|
+
}
|
46
|
+
} catch (e) {
|
47
|
+
}
|
48
|
+
function toggleWarning(skip) {
|
49
|
+
const { __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED } = fullClone;
|
50
|
+
if (__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED && typeof __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED === "object") {
|
51
|
+
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.usingClientEntryPoint = skip;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
function testModernRender(node, container, isTest) {
|
55
|
+
if (process.env.NODE_ENV !== "production" && isTest) {
|
56
|
+
return legacyRender(node, container);
|
57
|
+
}
|
58
|
+
}
|
59
|
+
function modernRender(node, container) {
|
60
|
+
toggleWarning(true);
|
61
|
+
const root = container[MARK] || createRoot(container);
|
62
|
+
toggleWarning(false);
|
63
|
+
root.render(node);
|
64
|
+
container[MARK] = root;
|
65
|
+
}
|
66
|
+
function legacyRender(node, container) {
|
67
|
+
reactRender(node, container);
|
68
|
+
}
|
69
|
+
function render(node, container) {
|
70
|
+
if (createRoot) {
|
71
|
+
modernRender(node, container);
|
72
|
+
return;
|
73
|
+
}
|
74
|
+
legacyRender(node, container);
|
75
|
+
}
|
76
|
+
function testLegacyUnmount(container, isTest) {
|
77
|
+
if (process.env.NODE_ENV !== "production" && isTest) {
|
78
|
+
return legacyUnmount(container);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
function modernUnmount(container) {
|
82
|
+
return __async(this, null, function* () {
|
83
|
+
return Promise.resolve().then(() => {
|
84
|
+
var _a;
|
85
|
+
(_a = container[MARK]) == null ? void 0 : _a.unmount();
|
86
|
+
delete container[MARK];
|
87
|
+
});
|
88
|
+
});
|
89
|
+
}
|
90
|
+
function legacyUnmount(container) {
|
91
|
+
return unmountComponentAtNode(container);
|
92
|
+
}
|
93
|
+
function unmount(container) {
|
94
|
+
if (createRoot) {
|
95
|
+
return modernUnmount(container);
|
96
|
+
}
|
97
|
+
return legacyUnmount(container);
|
98
|
+
}
|
99
|
+
export {
|
100
|
+
render,
|
101
|
+
testLegacyUnmount,
|
102
|
+
testModernRender,
|
103
|
+
unmount
|
104
|
+
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@bifrostui/utils",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.3.1-beta.0",
|
4
4
|
"description": "BUI React utilities for building components.",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"module": "es/index.js",
|
@@ -21,7 +21,8 @@
|
|
21
21
|
"peerDependencies": {
|
22
22
|
"@tarojs/runtime": "^3.0.0",
|
23
23
|
"@tarojs/taro": "^3.0.0",
|
24
|
-
"react": "^17.0.0 || ^18.0.0"
|
24
|
+
"react": "^17.0.0 || ^18.0.0",
|
25
|
+
"react-dom": "^17.0.0 || ^18.0.0"
|
25
26
|
},
|
26
27
|
"license": "MIT",
|
27
28
|
"publishConfig": {
|