clxx 2.0.3 → 2.0.6
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/build/Ago/index.d.ts +3 -5
- package/build/Ago/index.js +6 -7
- package/build/Alert/Wrapper.d.ts +3 -4
- package/build/Alert/Wrapper.js +10 -17
- package/build/Alert/index.d.ts +2 -2
- package/build/Alert/index.js +9 -10
- package/build/Alert/style.js +1 -0
- package/build/AutoGrid/index.d.ts +4 -5
- package/build/AutoGrid/index.js +19 -21
- package/build/CarouselNotice/index.d.ts +4 -5
- package/build/CarouselNotice/index.js +20 -21
- package/build/Clickable/index.d.ts +1 -1
- package/build/Clickable/index.js +3 -2
- package/build/Container/index.d.ts +3 -4
- package/build/Container/index.js +37 -39
- package/build/Countdowner/index.d.ts +4 -5
- package/build/Countdowner/index.js +13 -14
- package/build/Dialog/Wrapper.d.ts +2 -2
- package/build/Dialog/Wrapper.js +6 -9
- package/build/Dialog/index.d.ts +3 -3
- package/build/Dialog/index.js +21 -12
- package/build/{effect → Effect}/useInterval.d.ts +0 -0
- package/build/{effect → Effect}/useInterval.js +0 -0
- package/build/{effect → Effect}/useTick.d.ts +0 -0
- package/build/{effect → Effect}/useTick.js +4 -2
- package/build/Effect/useUpdate.d.ts +5 -0
- package/build/Effect/useUpdate.js +10 -0
- package/build/{effect → Effect}/useViewport.d.ts +0 -0
- package/build/{effect → Effect}/useViewport.js +0 -0
- package/build/{effect → Effect}/useWindowResize.d.ts +0 -0
- package/build/{effect → Effect}/useWindowResize.js +0 -0
- package/build/Flex/Col.d.ts +7 -9
- package/build/Flex/Col.js +14 -15
- package/build/Flex/Row.d.ts +7 -9
- package/build/Flex/Row.js +14 -15
- package/build/Flex/index.d.ts +2 -4
- package/build/Flex/index.js +5 -6
- package/build/Indicator/index.d.ts +4 -5
- package/build/Indicator/index.js +14 -15
- package/build/Loading/Wrapper.d.ts +7 -8
- package/build/Loading/Wrapper.js +14 -18
- package/build/Loading/index.d.ts +1 -1
- package/build/Loading/index.js +10 -11
- package/build/Overlay/index.d.ts +2 -4
- package/build/Overlay/index.js +15 -17
- package/build/SafeArea/index.d.ts +2 -4
- package/build/SafeArea/index.js +7 -8
- package/build/ScrollView/index.d.ts +2 -2
- package/build/ScrollView/index.js +12 -11
- package/build/Toast/Toast.d.ts +2 -2
- package/build/Toast/Toast.js +4 -5
- package/build/Toast/index.d.ts +2 -2
- package/build/Toast/index.js +13 -11
- package/build/Toast/style.d.ts +1 -1
- package/build/Toast/style.js +1 -1
- package/build/index.d.ts +4 -5
- package/build/index.js +4 -5
- package/build/utils/Countdown.d.ts +1 -2
- package/build/utils/Countdown.js +4 -2
- package/build/utils/createApp.d.ts +8 -8
- package/build/utils/createApp.js +29 -23
- package/build/utils/dom.d.ts +5 -5
- package/build/utils/dom.js +14 -27
- package/build/utils/request.js +4 -3
- package/build/utils/tick.d.ts +11 -5
- package/build/utils/tick.js +28 -24
- package/build/utils/wait.js +5 -4
- package/package.json +15 -15
- package/build/Picker/Wrapper.d.ts +0 -20
- package/build/Picker/Wrapper.js +0 -92
- package/build/Picker/index.d.ts +0 -21
- package/build/Picker/index.js +0 -64
- package/build/Picker/style.d.ts +0 -3
- package/build/Picker/style.js +0 -122
- package/build/Picker/swiperStyle.d.ts +0 -1
- package/build/Picker/swiperStyle.js +0 -66
package/build/SafeArea/index.js
CHANGED
|
@@ -9,14 +9,13 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import { useViewport } from "../effect/useViewport";
|
|
12
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
13
|
+
import { useViewport } from '../Effect/useViewport';
|
|
15
14
|
export function SafeArea(props) {
|
|
16
|
-
const { children, type =
|
|
17
|
-
useViewport({ viewportFit:
|
|
15
|
+
const { children, type = 'bottom' } = props, extra = __rest(props, ["children", "type"]);
|
|
16
|
+
useViewport({ viewportFit: 'cover' });
|
|
18
17
|
let boxCss;
|
|
19
|
-
if (type ===
|
|
18
|
+
if (type === 'top') {
|
|
20
19
|
boxCss = {
|
|
21
20
|
height: [
|
|
22
21
|
`constant(safe-area-inset-top, 0)`,
|
|
@@ -24,7 +23,7 @@ export function SafeArea(props) {
|
|
|
24
23
|
],
|
|
25
24
|
};
|
|
26
25
|
}
|
|
27
|
-
else if (type ===
|
|
26
|
+
else if (type === 'bottom') {
|
|
28
27
|
boxCss = {
|
|
29
28
|
height: [
|
|
30
29
|
`constant(safe-area-inset-bottom, 0)`,
|
|
@@ -32,5 +31,5 @@ export function SafeArea(props) {
|
|
|
32
31
|
],
|
|
33
32
|
};
|
|
34
33
|
}
|
|
35
|
-
return (
|
|
34
|
+
return (_jsx("div", Object.assign({ css: boxCss }, extra, { children: children })));
|
|
36
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
/** @jsx jsx */
|
|
3
|
-
import {
|
|
3
|
+
import { SerializedStyles } from "@emotion/react";
|
|
4
4
|
import * as CSS from "csstype";
|
|
5
5
|
export interface ScrollEvent {
|
|
6
6
|
containerHeight: number;
|
|
@@ -24,4 +24,4 @@ export interface ScrollViewProps extends Omit<React.HTMLProps<HTMLDivElement>, "
|
|
|
24
24
|
wrapperStyle?: SerializedStyles;
|
|
25
25
|
loadingStyle?: SerializedStyles;
|
|
26
26
|
}
|
|
27
|
-
export declare function ScrollView(props: ScrollViewProps): jsx.JSX.Element;
|
|
27
|
+
export declare function ScrollView(props: ScrollViewProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -9,9 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import { useRef } from "react";
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
13
|
+
import { useEffect, useRef, useState } from "react";
|
|
15
14
|
import { Indicator } from "../Indicator";
|
|
16
15
|
import { RowCenter } from "../Flex/Row";
|
|
17
16
|
import { style } from "./style";
|
|
@@ -24,6 +23,7 @@ export function ScrollView(props) {
|
|
|
24
23
|
}
|
|
25
24
|
// 滚动容器
|
|
26
25
|
const container = useRef(null);
|
|
26
|
+
const child = useRef(null);
|
|
27
27
|
// 当前滚动到顶部的距离
|
|
28
28
|
const top = useRef(0);
|
|
29
29
|
const scrollCallback = (rawEvent) => {
|
|
@@ -54,8 +54,7 @@ export function ScrollView(props) {
|
|
|
54
54
|
onReachTop === null || onReachTop === void 0 ? void 0 : onReachTop(event);
|
|
55
55
|
}
|
|
56
56
|
// 判断是否触发触底事件
|
|
57
|
-
if (event.direction === "downward" &&
|
|
58
|
-
scrollTop > maxScroll - reachBottomThreshold - loadingHeight) {
|
|
57
|
+
if (event.direction === "downward" && scrollTop > maxScroll - reachBottomThreshold - loadingHeight) {
|
|
59
58
|
onReachBottom === null || onReachBottom === void 0 ? void 0 : onReachBottom(event);
|
|
60
59
|
}
|
|
61
60
|
// 更新scrollTop上次的值
|
|
@@ -65,15 +64,17 @@ export function ScrollView(props) {
|
|
|
65
64
|
let showLoadingContent = null;
|
|
66
65
|
if (showLoading) {
|
|
67
66
|
if (!loadingContent) {
|
|
68
|
-
showLoadingContent = (
|
|
69
|
-
jsx(Indicator, { barColor: "#333", barCount: 12 }),
|
|
70
|
-
jsx("p", null, "\u6570\u636E\u52A0\u8F7D\u4E2D...")));
|
|
67
|
+
showLoadingContent = (_jsxs(RowCenter, Object.assign({ css: [style.loading, loadingStyle] }, { children: [_jsx(Indicator, { barColor: "#333", barCount: 12 }), _jsx("p", { children: "\u6570\u636E\u52A0\u8F7D\u4E2D..." })] })));
|
|
71
68
|
}
|
|
72
69
|
else {
|
|
73
70
|
showLoadingContent = loadingContent;
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
// container是否有滚动条
|
|
74
|
+
const [hasScrollBar, setHasScrollBar] = useState(false);
|
|
75
|
+
useEffect(() => {
|
|
76
|
+
let hasScrollBar = container.current.scrollHeight > container.current.clientHeight;
|
|
77
|
+
setHasScrollBar(hasScrollBar);
|
|
78
|
+
});
|
|
79
|
+
return (_jsxs("div", Object.assign({ css: [style.container, heightStyle, containerStyle], onScroll: scrollCallback, ref: container }, attrs, { children: [_jsx("div", Object.assign({ css: wrapperStyle, ref: child }, { children: children })), hasScrollBar && showLoadingContent] })));
|
|
79
80
|
}
|
package/build/Toast/Toast.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
|
-
import { Interpolation,
|
|
2
|
+
import { Interpolation, Theme } from "@emotion/react";
|
|
3
3
|
import React from "react";
|
|
4
4
|
export interface ToastProps extends Omit<React.HTMLProps<HTMLDivElement>, "content"> {
|
|
5
5
|
onHide?: () => void;
|
|
@@ -12,4 +12,4 @@ export interface ToastProps extends Omit<React.HTMLProps<HTMLDivElement>, "conte
|
|
|
12
12
|
containerStyle?: Interpolation<Theme>;
|
|
13
13
|
contentStyle?: Interpolation<Theme>;
|
|
14
14
|
}
|
|
15
|
-
export declare function Toast(props: ToastProps): jsx.JSX.Element;
|
|
15
|
+
export declare function Toast(props: ToastProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
package/build/Toast/Toast.js
CHANGED
|
@@ -9,8 +9,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
|
|
13
|
-
import { jsx } from "@emotion/react";
|
|
12
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
14
13
|
import React, { useState, useEffect } from "react";
|
|
15
14
|
import { style, getAnimation } from "./style";
|
|
16
15
|
export function Toast(props) {
|
|
@@ -30,10 +29,10 @@ export function Toast(props) {
|
|
|
30
29
|
let showContent;
|
|
31
30
|
const middleStyle = position === "middle" ? style.contentMiddle : undefined;
|
|
32
31
|
if (React.isValidElement(content)) {
|
|
33
|
-
showContent =
|
|
32
|
+
showContent = _jsx("div", Object.assign({ css: [middleStyle, contentStyle] }, { children: content }));
|
|
34
33
|
}
|
|
35
34
|
else {
|
|
36
|
-
showContent = (
|
|
35
|
+
showContent = (_jsx("p", Object.assign({ css: [style.content(radius), middleStyle, contentStyle] }, { children: content })));
|
|
37
36
|
}
|
|
38
37
|
// toast消失动画结束触发
|
|
39
38
|
const animationEnd = (event) => {
|
|
@@ -52,5 +51,5 @@ export function Toast(props) {
|
|
|
52
51
|
else {
|
|
53
52
|
positionStyle = style.middle;
|
|
54
53
|
}
|
|
55
|
-
return (
|
|
54
|
+
return (_jsx("div", Object.assign({ css: [style.container(), positionStyle, animation, containerStyle], onAnimationEnd: animationEnd }, attributes, { children: showContent })));
|
|
56
55
|
}
|
package/build/Toast/index.d.ts
CHANGED
package/build/Toast/index.js
CHANGED
|
@@ -1,22 +1,24 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
1
|
+
import { createElement as _createElement } from "@emotion/react";
|
|
2
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { uniqKey } from '../utils/uniqKey';
|
|
5
|
+
import { createPortalDOM } from '../utils/dom';
|
|
6
|
+
import { Toast as ToastComponent } from './Toast';
|
|
5
7
|
/**
|
|
6
8
|
* 显示一个全局的轻提示,这个toast不是唯一的
|
|
7
9
|
* @param option 可以是一个字符串,也可以是一个React组件
|
|
8
10
|
*/
|
|
9
11
|
export function showToast(option) {
|
|
10
|
-
const { mount,
|
|
12
|
+
const { mount, unmount } = createPortalDOM();
|
|
11
13
|
let props = {};
|
|
12
|
-
if (React.isValidElement(option) || typeof option !==
|
|
14
|
+
if (React.isValidElement(option) || typeof option !== 'object') {
|
|
13
15
|
props.content = option;
|
|
14
16
|
}
|
|
15
17
|
else {
|
|
16
18
|
props = option;
|
|
17
19
|
}
|
|
18
|
-
props.onHide =
|
|
19
|
-
mount(
|
|
20
|
+
props.onHide = unmount;
|
|
21
|
+
mount(_jsx(ToastComponent, Object.assign({}, props)));
|
|
20
22
|
}
|
|
21
23
|
/**
|
|
22
24
|
* 生成一个全局唯一的Toast
|
|
@@ -29,16 +31,16 @@ export function showUniqToast(option) {
|
|
|
29
31
|
}
|
|
30
32
|
let props = {};
|
|
31
33
|
// 默认Toast是唯一的
|
|
32
|
-
if (React.isValidElement(option) || typeof option !==
|
|
34
|
+
if (React.isValidElement(option) || typeof option !== 'object') {
|
|
33
35
|
props.content = option;
|
|
34
36
|
}
|
|
35
37
|
else {
|
|
36
38
|
props = option;
|
|
37
39
|
}
|
|
38
40
|
const onHide = () => {
|
|
39
|
-
portalDOM === null || portalDOM === void 0 ? void 0 : portalDOM.
|
|
41
|
+
portalDOM === null || portalDOM === void 0 ? void 0 : portalDOM.unmount();
|
|
40
42
|
portalDOM = null;
|
|
41
43
|
};
|
|
42
44
|
props.onHide = onHide;
|
|
43
|
-
portalDOM.mount(
|
|
45
|
+
portalDOM.mount(_createElement(ToastComponent, Object.assign({}, props, { key: uniqKey() })));
|
|
44
46
|
}
|
package/build/Toast/style.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export declare const style: {
|
|
|
20
20
|
top(offset: number): import("@emotion/utils").SerializedStyles;
|
|
21
21
|
middle: import("@emotion/utils").SerializedStyles;
|
|
22
22
|
bottom(offset: number): import("@emotion/utils").SerializedStyles;
|
|
23
|
-
content: (radius?: number
|
|
23
|
+
content: (radius?: number) => import("@emotion/utils").SerializedStyles;
|
|
24
24
|
contentMiddle: {
|
|
25
25
|
transform: string;
|
|
26
26
|
};
|
package/build/Toast/style.js
CHANGED
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Tick } from "./utils/tick";
|
|
2
2
|
export { setContextValue, getContextValue } from "./context";
|
|
3
3
|
export { jsonp } from "./utils/jsonp";
|
|
4
4
|
export { uniqKey } from "./utils/uniqKey";
|
|
@@ -11,11 +11,11 @@ export { is } from "./utils/is";
|
|
|
11
11
|
export { waitFor, waitUntil } from "./utils/wait";
|
|
12
12
|
export { normalizeUnit, splitValue } from "./utils/cssUtil";
|
|
13
13
|
export { createApp, history, getHistory } from "./utils/createApp";
|
|
14
|
-
export { useInterval } from "./
|
|
15
|
-
export { useTick } from "./
|
|
14
|
+
export { useInterval } from "./Effect/useInterval";
|
|
15
|
+
export { useTick } from "./Effect/useTick";
|
|
16
16
|
export { Ago } from "./Ago";
|
|
17
17
|
export { Container } from "./Container";
|
|
18
|
-
export { Flex } from "./Flex";
|
|
18
|
+
export { Flex, FlexItem } from "./Flex";
|
|
19
19
|
export { Row, RowAround, RowBetween, RowCenter, RowEnd, RowEvenly, RowStart } from "./Flex/Row";
|
|
20
20
|
export { Col, ColAround, ColBetween, ColCenter, ColEnd, ColEvenly, ColStart } from "./Flex/Col";
|
|
21
21
|
export { Countdowner } from "./Countdowner";
|
|
@@ -30,4 +30,3 @@ export { AutoGrid } from "./AutoGrid";
|
|
|
30
30
|
export { showAlert } from "./Alert";
|
|
31
31
|
export { ScrollView } from "./ScrollView";
|
|
32
32
|
export { CarouselNotice } from "./CarouselNotice";
|
|
33
|
-
export { showPicker, Picker } from "./Picker";
|
package/build/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { Tick } from "./utils/tick";
|
|
2
2
|
export { setContextValue, getContextValue } from "./context";
|
|
3
3
|
export { jsonp } from "./utils/jsonp";
|
|
4
4
|
export { uniqKey } from "./utils/uniqKey";
|
|
@@ -11,11 +11,11 @@ export { is } from "./utils/is";
|
|
|
11
11
|
export { waitFor, waitUntil } from "./utils/wait";
|
|
12
12
|
export { normalizeUnit, splitValue } from "./utils/cssUtil";
|
|
13
13
|
export { createApp, history, getHistory } from "./utils/createApp";
|
|
14
|
-
export { useInterval } from "./
|
|
15
|
-
export { useTick } from "./
|
|
14
|
+
export { useInterval } from "./Effect/useInterval";
|
|
15
|
+
export { useTick } from "./Effect/useTick";
|
|
16
16
|
export { Ago } from "./Ago";
|
|
17
17
|
export { Container } from "./Container";
|
|
18
|
-
export { Flex } from "./Flex";
|
|
18
|
+
export { Flex, FlexItem } from "./Flex";
|
|
19
19
|
export { Row, RowAround, RowBetween, RowCenter, RowEnd, RowEvenly, RowStart } from "./Flex/Row";
|
|
20
20
|
export { Col, ColAround, ColBetween, ColCenter, ColEnd, ColEvenly, ColStart } from "./Flex/Col";
|
|
21
21
|
export { Countdowner } from "./Countdowner";
|
|
@@ -30,4 +30,3 @@ export { AutoGrid } from "./AutoGrid";
|
|
|
30
30
|
export { showAlert } from "./Alert";
|
|
31
31
|
export { ScrollView } from "./ScrollView";
|
|
32
32
|
export { CarouselNotice } from "./CarouselNotice";
|
|
33
|
-
export { showPicker, Picker } from "./Picker";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { StopTick } from "./tick";
|
|
2
1
|
export declare type CountdownValueIndex = "d" | "h" | "i" | "s";
|
|
3
2
|
export declare type CountdownValue = {
|
|
4
3
|
[key in CountdownValueIndex]?: number;
|
|
@@ -24,7 +23,7 @@ export declare class Countdown {
|
|
|
24
23
|
* s:秒
|
|
25
24
|
*/
|
|
26
25
|
format: string[];
|
|
27
|
-
_stopTick?:
|
|
26
|
+
_stopTick?: () => void;
|
|
28
27
|
_onUpdate?: UpdateCallback;
|
|
29
28
|
_onEnd?: () => void;
|
|
30
29
|
constructor(option: CountdownOption);
|
package/build/utils/Countdown.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Tick } from "./tick";
|
|
2
2
|
export class Countdown {
|
|
3
3
|
constructor(option) {
|
|
4
4
|
/**
|
|
@@ -54,7 +54,7 @@ export class Countdown {
|
|
|
54
54
|
(_d = this._onUpdate) === null || _d === void 0 ? void 0 : _d.call(this, this.formatValue());
|
|
55
55
|
// 记录倒计时开启时的时间
|
|
56
56
|
const start = Date.now();
|
|
57
|
-
|
|
57
|
+
const tickInstance = new Tick(() => {
|
|
58
58
|
var _a, _b, _c, _d;
|
|
59
59
|
// 获取倒计时已经持续的时间
|
|
60
60
|
const duration = Math.floor((Date.now() - start) / 1000);
|
|
@@ -73,6 +73,8 @@ export class Countdown {
|
|
|
73
73
|
(_d = this._onUpdate) === null || _d === void 0 ? void 0 : _d.call(this, this.formatValue());
|
|
74
74
|
}
|
|
75
75
|
});
|
|
76
|
+
tickInstance.start();
|
|
77
|
+
this._stopTick = () => tickInstance.destroy();
|
|
76
78
|
}
|
|
77
79
|
// 停止倒计时
|
|
78
80
|
stop() {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { History
|
|
3
|
-
import { ContainerProps } from
|
|
4
|
-
import { ContextValue } from
|
|
5
|
-
export declare type RouteMethod =
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { History } from 'history';
|
|
3
|
+
import { ContainerProps } from '../Container';
|
|
4
|
+
import { ContextValue } from '../context';
|
|
5
|
+
export declare type RouteMethod = 'browser' | 'hash' | 'memory';
|
|
6
6
|
export declare type AwaitValue<T> = T | Promise<T>;
|
|
7
|
-
export interface CreateAppOption extends Omit<ContainerProps,
|
|
7
|
+
export interface CreateAppOption extends Omit<ContainerProps, 'children'>, ContextValue {
|
|
8
8
|
onBeforeRenderPage?: (pathname?: string) => AwaitValue<void>;
|
|
9
9
|
onAfterRenderPage?: (pathname?: string) => AwaitValue<void>;
|
|
10
10
|
renderLoading?: (pathname?: string) => AwaitValue<React.ReactNode>;
|
|
@@ -13,8 +13,8 @@ export interface CreateAppOption extends Omit<ContainerProps, "children">, Conte
|
|
|
13
13
|
defaultRoute?: string;
|
|
14
14
|
target: string | HTMLElement;
|
|
15
15
|
}
|
|
16
|
-
export declare let history: null | History
|
|
17
|
-
export declare function getHistory(routeMethod?: RouteMethod): History
|
|
16
|
+
export declare let history: null | History;
|
|
17
|
+
export declare function getHistory(routeMethod?: RouteMethod): History;
|
|
18
18
|
/**
|
|
19
19
|
* 创建带路由的APP对象,全局对象,绝大部分情况下只需要调用一次
|
|
20
20
|
* @param option CreateAppOption
|
package/build/utils/createApp.js
CHANGED
|
@@ -7,16 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import
|
|
10
|
+
import { jsx as _jsx } from "@emotion/react/jsx-runtime";
|
|
11
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
12
|
+
import { createRoot } from 'react-dom/client';
|
|
13
|
+
import { createBrowserHistory, createHashHistory, createMemoryHistory, } from 'history';
|
|
14
|
+
import { Container } from '../Container';
|
|
15
|
+
import { setContextValue } from '../context';
|
|
16
|
+
import pick from 'lodash/pick';
|
|
16
17
|
// 存储历史记录对象
|
|
17
18
|
export let history = null;
|
|
18
19
|
// 获取历史记录对象
|
|
19
|
-
export function getHistory(routeMethod =
|
|
20
|
+
export function getHistory(routeMethod = 'browser') {
|
|
20
21
|
if (history === null) {
|
|
21
22
|
const createMap = {
|
|
22
23
|
browser: createBrowserHistory,
|
|
@@ -34,18 +35,22 @@ export function getHistory(routeMethod = "browser") {
|
|
|
34
35
|
export function createApp(option) {
|
|
35
36
|
return __awaiter(this, void 0, void 0, function* () {
|
|
36
37
|
// 设置默认的路由方式
|
|
37
|
-
if (!option.routeMethod ||
|
|
38
|
-
option.routeMethod
|
|
38
|
+
if (!option.routeMethod ||
|
|
39
|
+
['browser', 'hash', 'memory'].indexOf(option.routeMethod) === -1) {
|
|
40
|
+
option.routeMethod = 'browser';
|
|
39
41
|
}
|
|
40
42
|
// 设置默认路由路径
|
|
41
43
|
if (!option.defaultRoute) {
|
|
42
|
-
option.defaultRoute =
|
|
44
|
+
option.defaultRoute = '/index';
|
|
43
45
|
}
|
|
44
46
|
// 这里是为了确保历史记录对象在组件渲染之前一定存在
|
|
45
|
-
history = getHistory();
|
|
47
|
+
history = getHistory(option.routeMethod);
|
|
46
48
|
// 提取关键数据
|
|
47
|
-
const context = pick(option, [
|
|
48
|
-
const containerProps = pick(option, [
|
|
49
|
+
const context = pick(option, ['minDocWidth', 'maxDocWidth']);
|
|
50
|
+
const containerProps = pick(option, [
|
|
51
|
+
'designWidth',
|
|
52
|
+
'globalStyle',
|
|
53
|
+
]);
|
|
49
54
|
const { onBeforeRenderPage, onAfterRenderPage, renderLoading, renderPage } = option;
|
|
50
55
|
// 设置上下文属性
|
|
51
56
|
setContextValue(context);
|
|
@@ -60,13 +65,13 @@ export function createApp(option) {
|
|
|
60
65
|
*/
|
|
61
66
|
const showPage = useCallback((pathname) => __awaiter(this, void 0, void 0, function* () {
|
|
62
67
|
const pathReg = /^\/*|\/*$/g;
|
|
63
|
-
pathname = pathname.replace(pathReg,
|
|
68
|
+
pathname = pathname.replace(pathReg, '');
|
|
64
69
|
if (!pathname) {
|
|
65
|
-
pathname = option.defaultRoute.replace(pathReg,
|
|
70
|
+
pathname = option.defaultRoute.replace(pathReg, '');
|
|
66
71
|
}
|
|
67
72
|
// 如果有loading,要先显示loading
|
|
68
|
-
if (typeof renderLoading ===
|
|
69
|
-
setPage(renderLoading === null || renderLoading === void 0 ? void 0 : renderLoading(pathname));
|
|
73
|
+
if (typeof renderLoading === 'function') {
|
|
74
|
+
setPage(yield (renderLoading === null || renderLoading === void 0 ? void 0 : renderLoading(pathname)));
|
|
70
75
|
}
|
|
71
76
|
// 加载页面之前可能会存在的逻辑
|
|
72
77
|
yield (onBeforeRenderPage === null || onBeforeRenderPage === void 0 ? void 0 : onBeforeRenderPage(pathname));
|
|
@@ -88,19 +93,20 @@ export function createApp(option) {
|
|
|
88
93
|
// 卸载时,取消监听
|
|
89
94
|
return unlisten;
|
|
90
95
|
}, []);
|
|
91
|
-
return
|
|
96
|
+
return _jsx(Container, Object.assign({}, containerProps, { children: page }));
|
|
92
97
|
};
|
|
93
98
|
// 获取挂载对象
|
|
94
99
|
let mount = null;
|
|
95
|
-
if (typeof option.target ===
|
|
100
|
+
if (typeof option.target === 'string') {
|
|
96
101
|
mount = document.querySelector(option.target);
|
|
97
102
|
}
|
|
98
103
|
else if (option.target instanceof HTMLElement) {
|
|
99
104
|
mount = option.target;
|
|
100
105
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
106
|
+
else {
|
|
107
|
+
throw new Error('No mounted object is specified');
|
|
108
|
+
}
|
|
109
|
+
const root = createRoot(mount);
|
|
110
|
+
root.render(_jsx(App, {}));
|
|
105
111
|
});
|
|
106
112
|
}
|
package/build/utils/dom.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import React from
|
|
1
|
+
import React from 'react';
|
|
2
2
|
export interface PortalDOM {
|
|
3
3
|
element: HTMLDivElement;
|
|
4
|
-
mount: (component: React.ReactNode) =>
|
|
5
|
-
|
|
4
|
+
mount: (component: React.ReactNode) => void;
|
|
5
|
+
unmount: () => void;
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
*
|
|
9
9
|
* 组件可以通过函数的第一个参数传递进去
|
|
10
10
|
*
|
|
11
|
-
* @param point HTMLElement
|
|
11
|
+
* @param point HTMLElement 挂载点,如果未指定,则挂载点为body
|
|
12
12
|
* @returns CreatePortalDOMResult
|
|
13
13
|
*/
|
|
14
14
|
export declare function createPortalDOM(point?: HTMLElement): PortalDOM;
|
package/build/utils/dom.js
CHANGED
|
@@ -1,45 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import React from "react";
|
|
11
|
-
import ReactDOM from "react-dom";
|
|
1
|
+
import { createRoot } from 'react-dom/client';
|
|
12
2
|
/**
|
|
13
|
-
*
|
|
3
|
+
*
|
|
14
4
|
* 组件可以通过函数的第一个参数传递进去
|
|
15
5
|
*
|
|
16
|
-
* @param point HTMLElement
|
|
6
|
+
* @param point HTMLElement 挂载点,如果未指定,则挂载点为body
|
|
17
7
|
* @returns CreatePortalDOMResult
|
|
18
8
|
*/
|
|
19
9
|
export function createPortalDOM(point) {
|
|
20
|
-
const
|
|
10
|
+
const container = document.createElement('div');
|
|
21
11
|
let mountPoint = document.body;
|
|
22
12
|
if (point instanceof HTMLElement) {
|
|
23
13
|
mountPoint = point;
|
|
24
14
|
}
|
|
25
|
-
mountPoint.appendChild(
|
|
15
|
+
mountPoint.appendChild(container);
|
|
16
|
+
const root = createRoot(container);
|
|
26
17
|
return {
|
|
27
|
-
element,
|
|
18
|
+
element: container,
|
|
28
19
|
mount(component) {
|
|
29
|
-
|
|
30
|
-
return new Promise((resolve) => {
|
|
31
|
-
ReactDOM.render(React.createElement(React.Fragment, null, component), element, resolve);
|
|
32
|
-
});
|
|
33
|
-
});
|
|
20
|
+
root.render(component);
|
|
34
21
|
},
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (typeof
|
|
39
|
-
|
|
22
|
+
unmount() {
|
|
23
|
+
root.unmount();
|
|
24
|
+
if (container instanceof HTMLDivElement) {
|
|
25
|
+
if (typeof container.remove === 'function') {
|
|
26
|
+
container.remove();
|
|
40
27
|
}
|
|
41
28
|
else {
|
|
42
|
-
mountPoint.removeChild(
|
|
29
|
+
mountPoint.removeChild(container);
|
|
43
30
|
}
|
|
44
31
|
}
|
|
45
32
|
},
|
package/build/utils/request.js
CHANGED
|
@@ -106,7 +106,7 @@ export function buildUrlByOption(option) {
|
|
|
106
106
|
* @returns
|
|
107
107
|
*/
|
|
108
108
|
export function parseRequestOption(option) {
|
|
109
|
-
var _a;
|
|
109
|
+
var _a, _b;
|
|
110
110
|
let config = {
|
|
111
111
|
url: "",
|
|
112
112
|
sendType: "normal",
|
|
@@ -116,6 +116,7 @@ export function parseRequestOption(option) {
|
|
|
116
116
|
timeout: 30000,
|
|
117
117
|
};
|
|
118
118
|
config.sendType = config.sendType.toLowerCase();
|
|
119
|
+
config.method = (_a = config.method) === null || _a === void 0 ? void 0 : _a.toUpperCase();
|
|
119
120
|
// 传递过来的参数覆盖默认值
|
|
120
121
|
if (isPlainObject(option)) {
|
|
121
122
|
config = Object.assign(Object.assign({}, config), option);
|
|
@@ -125,7 +126,7 @@ export function parseRequestOption(option) {
|
|
|
125
126
|
* 1、调用方没有传递请求方法
|
|
126
127
|
* 2、请求类型不为normal
|
|
127
128
|
*/
|
|
128
|
-
if (!config.method && config.sendType !== "normal") {
|
|
129
|
+
if ((config.method === "GET" || !config.method) && config.sendType !== "normal") {
|
|
129
130
|
config.method = "POST";
|
|
130
131
|
}
|
|
131
132
|
// 如果没有设置headers,确保请求头为对象
|
|
@@ -198,7 +199,7 @@ export function parseRequestOption(option) {
|
|
|
198
199
|
"transmitPageParam",
|
|
199
200
|
"timeout",
|
|
200
201
|
]);
|
|
201
|
-
return { url, fetchOption, timeout: (
|
|
202
|
+
return { url, fetchOption, timeout: (_b = config.timeout) !== null && _b !== void 0 ? _b : 30000 };
|
|
202
203
|
}
|
|
203
204
|
/**
|
|
204
205
|
* 发送正常Ajax请求,这个函数带有超时逻辑
|
package/build/utils/tick.d.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
|
-
export declare type StopTick = () => void;
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* tick类,初始化后使用start开始tick,使用destroy终止tick
|
|
3
|
+
* @constructor
|
|
4
|
+
* @param {function} callback start后每一帧都会调用的回调函数
|
|
6
5
|
*/
|
|
7
|
-
export declare
|
|
6
|
+
export declare class Tick {
|
|
7
|
+
callback?: (() => void) | undefined;
|
|
8
|
+
frameId: number | undefined;
|
|
9
|
+
isRun: boolean;
|
|
10
|
+
constructor(callback?: (() => void) | undefined);
|
|
11
|
+
start(): void;
|
|
12
|
+
destroy(): void;
|
|
13
|
+
}
|
package/build/utils/tick.js
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
2
|
+
* tick类,初始化后使用start开始tick,使用destroy终止tick
|
|
3
|
+
* @constructor
|
|
4
|
+
* @param {function} callback start后每一帧都会调用的回调函数
|
|
5
5
|
*/
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
export class Tick {
|
|
7
|
+
constructor(callback) {
|
|
8
|
+
this.callback = callback;
|
|
9
|
+
this.frameId = undefined;
|
|
10
|
+
this.isRun = true;
|
|
11
|
+
}
|
|
12
|
+
start() {
|
|
13
|
+
// 每一帧执行的任务
|
|
14
|
+
const frame = () => {
|
|
15
|
+
var _a;
|
|
16
|
+
if (!this.isRun)
|
|
17
|
+
return;
|
|
18
|
+
// 在回调执行之前预约下一帧
|
|
19
|
+
this.frameId = requestAnimationFrame(frame);
|
|
20
|
+
// 执行回调
|
|
21
|
+
(_a = this.callback) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
22
|
+
};
|
|
23
|
+
// 执行起始帧
|
|
24
|
+
frame();
|
|
25
|
+
}
|
|
26
|
+
destroy() {
|
|
27
|
+
if (typeof this.frameId === "number") {
|
|
28
|
+
cancelAnimationFrame(this.frameId);
|
|
13
29
|
}
|
|
14
|
-
isRun = false;
|
|
15
|
-
}
|
|
16
|
-
// 每一帧执行的任务
|
|
17
|
-
const frame = () => {
|
|
18
|
-
if (!isRun)
|
|
19
|
-
return;
|
|
20
|
-
// 在回调执行之前预约下一帧
|
|
21
|
-
frameId = requestAnimationFrame(frame);
|
|
22
|
-
// 执行回调
|
|
23
|
-
callback === null || callback === void 0 ? void 0 : callback();
|
|
24
|
-
};
|
|
25
|
-
// 执行起始帧
|
|
26
|
-
frame();
|
|
27
|
-
return stop;
|
|
30
|
+
this.isRun = false;
|
|
31
|
+
}
|
|
28
32
|
}
|