@rsmax/web 1.0.1
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/CHANGELOG.md +8 -0
- package/LICENSE +22 -0
- package/README.md +11 -0
- package/assets/app.css +154 -0
- package/assets/normalize.css +450 -0
- package/cjs/LoadingIcon.d.ts +6 -0
- package/cjs/LoadingIcon.js +39 -0
- package/cjs/PullToRefresh.d.ts +3 -0
- package/cjs/PullToRefresh.js +42 -0
- package/cjs/TabBar.d.ts +7 -0
- package/cjs/TabBar.js +57 -0
- package/cjs/api.d.ts +16 -0
- package/cjs/api.js +30 -0
- package/cjs/bootstrap.d.ts +2 -0
- package/cjs/bootstrap.js +18 -0
- package/cjs/bootstrapMpa.d.ts +1 -0
- package/cjs/bootstrapMpa.js +80 -0
- package/cjs/createApp.d.ts +4 -0
- package/cjs/createApp.js +72 -0
- package/cjs/createAppConfig.d.ts +54 -0
- package/cjs/createAppConfig.js +89 -0
- package/cjs/createPageConfig.d.ts +49 -0
- package/cjs/createPageConfig.js +162 -0
- package/cjs/hooks/useNativeEffect.d.ts +2 -0
- package/cjs/hooks/useNativeEffect.js +4 -0
- package/cjs/hooks/usePageInstance.d.ts +1 -0
- package/cjs/hooks/usePageInstance.js +6 -0
- package/cjs/hooks/useQuery.d.ts +3 -0
- package/cjs/hooks/useQuery.js +13 -0
- package/cjs/index.d.ts +10 -0
- package/cjs/index.js +39 -0
- package/cjs/types/index.d.ts +89 -0
- package/cjs/types/index.js +2 -0
- package/esm/LoadingIcon.d.ts +6 -0
- package/esm/LoadingIcon.js +13 -0
- package/esm/PullToRefresh.d.ts +3 -0
- package/esm/PullToRefresh.js +14 -0
- package/esm/TabBar.d.ts +7 -0
- package/esm/TabBar.js +30 -0
- package/esm/api.d.ts +16 -0
- package/esm/api.js +22 -0
- package/esm/bootstrap.d.ts +2 -0
- package/esm/bootstrap.js +12 -0
- package/esm/bootstrapMpa.d.ts +1 -0
- package/esm/bootstrapMpa.js +51 -0
- package/esm/createApp.d.ts +4 -0
- package/esm/createApp.js +43 -0
- package/esm/createAppConfig.d.ts +54 -0
- package/esm/createAppConfig.js +63 -0
- package/esm/createPageConfig.d.ts +49 -0
- package/esm/createPageConfig.js +133 -0
- package/esm/hooks/useNativeEffect.d.ts +2 -0
- package/esm/hooks/useNativeEffect.js +2 -0
- package/esm/hooks/usePageInstance.d.ts +1 -0
- package/esm/hooks/usePageInstance.js +3 -0
- package/esm/hooks/useQuery.d.ts +3 -0
- package/esm/hooks/useQuery.js +7 -0
- package/esm/index.d.ts +10 -0
- package/esm/index.js +10 -0
- package/esm/types/index.d.ts +89 -0
- package/esm/types/index.js +1 -0
- package/package.json +52 -0
- package/typings/index.d.ts +1 -0
- package/vitest.config.js +9 -0
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const React = __importStar(require("react"));
|
|
30
|
+
const qs_1 = __importDefault(require("qs"));
|
|
31
|
+
const framework_shared_1 = require("@rsmax/framework-shared");
|
|
32
|
+
const PullToRefresh_1 = __importDefault(require("./PullToRefresh"));
|
|
33
|
+
const DEFAULT_REACH_BOTTOM_DISTANCE = 50;
|
|
34
|
+
function createPageConfig(Page, name) {
|
|
35
|
+
const page = {
|
|
36
|
+
lifeCycleCallback: {},
|
|
37
|
+
wrapperRef: React.createRef(),
|
|
38
|
+
registerLifecycle(lifeCycle, callback) {
|
|
39
|
+
this.lifeCycleCallback[lifeCycle] = this.lifeCycleCallback[lifeCycle] || [];
|
|
40
|
+
this.lifeCycleCallback[lifeCycle].push(callback);
|
|
41
|
+
return () => {
|
|
42
|
+
this.lifeCycleCallback[lifeCycle].splice(this.lifeCycleCallback[lifeCycle].indexOf(callback), 1);
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
callLifecycle(lifeCycle, ...args) {
|
|
46
|
+
const callbacks = this.lifeCycleCallback[lifeCycle] || [];
|
|
47
|
+
let result;
|
|
48
|
+
callbacks.forEach((callback) => {
|
|
49
|
+
result = callback(...args);
|
|
50
|
+
});
|
|
51
|
+
if (result) {
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
const callback = (0, framework_shared_1.callbackName)(lifeCycle);
|
|
55
|
+
if (this.wrapperRef.current && this.wrapperRef.current[callback]) {
|
|
56
|
+
return this.wrapperRef.current[callback](...args);
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
const PageWrapper = (0, framework_shared_1.createPageWrapper)(Page, name);
|
|
61
|
+
return class PageConfig extends React.Component {
|
|
62
|
+
constructor(props) {
|
|
63
|
+
super(props);
|
|
64
|
+
this.state = {
|
|
65
|
+
refreshing: true,
|
|
66
|
+
};
|
|
67
|
+
this.title = this.props.pageConfig.defaultTitle || document.title;
|
|
68
|
+
this.componentDidCache = () => {
|
|
69
|
+
this.title = document.title;
|
|
70
|
+
page.callLifecycle(framework_shared_1.Lifecycle.hide);
|
|
71
|
+
this.unregisterPageScroll();
|
|
72
|
+
};
|
|
73
|
+
this.componentDidRecover = () => {
|
|
74
|
+
this.setTitle();
|
|
75
|
+
page.callLifecycle(framework_shared_1.Lifecycle.show);
|
|
76
|
+
};
|
|
77
|
+
this.setTitle = () => {
|
|
78
|
+
document.title = this.title;
|
|
79
|
+
};
|
|
80
|
+
this.isPullDownRefreshEnabled = () => {
|
|
81
|
+
const { pageConfig } = this.props;
|
|
82
|
+
return pageConfig.pullRefresh;
|
|
83
|
+
};
|
|
84
|
+
this.getReachBottomDistance = () => {
|
|
85
|
+
var _a;
|
|
86
|
+
const { pageConfig } = this.props;
|
|
87
|
+
return (_a = pageConfig.onReachBottomDistance) !== null && _a !== void 0 ? _a : DEFAULT_REACH_BOTTOM_DISTANCE;
|
|
88
|
+
};
|
|
89
|
+
this.isReachBottom = false;
|
|
90
|
+
this.scrollEvent = () => {
|
|
91
|
+
this.checkReachBottom();
|
|
92
|
+
const event = { scrollTop: window.scrollY };
|
|
93
|
+
page.callLifecycle(framework_shared_1.Lifecycle.pageScroll, event);
|
|
94
|
+
};
|
|
95
|
+
this.registerPageScroll = () => {
|
|
96
|
+
window.addEventListener('scroll', this.scrollEvent);
|
|
97
|
+
};
|
|
98
|
+
this.unregisterPageScroll = () => {
|
|
99
|
+
window.removeEventListener('scroll', this.scrollEvent);
|
|
100
|
+
};
|
|
101
|
+
this.handleRefresh = async () => {
|
|
102
|
+
this.setState({
|
|
103
|
+
refreshing: true,
|
|
104
|
+
});
|
|
105
|
+
try {
|
|
106
|
+
await page.callLifecycle(framework_shared_1.Lifecycle.pullDownRefresh);
|
|
107
|
+
}
|
|
108
|
+
catch (error) {
|
|
109
|
+
this.setState({
|
|
110
|
+
refreshing: false,
|
|
111
|
+
});
|
|
112
|
+
throw error;
|
|
113
|
+
}
|
|
114
|
+
this.setState({
|
|
115
|
+
refreshing: false,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
this.checkReachBottom = () => {
|
|
119
|
+
const isCurrentReachBottom = document.body.scrollHeight - (window.innerHeight + window.scrollY) <= this.getReachBottomDistance();
|
|
120
|
+
if (!this.isReachBottom && isCurrentReachBottom) {
|
|
121
|
+
this.isReachBottom = true;
|
|
122
|
+
page.callLifecycle(framework_shared_1.Lifecycle.reachBottom);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.isReachBottom = isCurrentReachBottom;
|
|
126
|
+
};
|
|
127
|
+
props.cacheLifecycles.didCache(this.componentDidCache);
|
|
128
|
+
props.cacheLifecycles.didRecover(this.componentDidRecover);
|
|
129
|
+
}
|
|
130
|
+
componentDidMount() {
|
|
131
|
+
this.setTitle();
|
|
132
|
+
page.callLifecycle(framework_shared_1.Lifecycle.load);
|
|
133
|
+
page.callLifecycle(framework_shared_1.Lifecycle.show);
|
|
134
|
+
page.callLifecycle(framework_shared_1.Lifecycle.ready);
|
|
135
|
+
this.registerPageScroll();
|
|
136
|
+
}
|
|
137
|
+
componentWillUnmount() {
|
|
138
|
+
this.unregisterPageScroll();
|
|
139
|
+
}
|
|
140
|
+
render() {
|
|
141
|
+
const { tabBar, location } = this.props;
|
|
142
|
+
const { refreshing } = this.state;
|
|
143
|
+
const hasTabBar = !!tabBar;
|
|
144
|
+
const className = `remax-page ${hasTabBar ? 'with-tab-bar' : ''}`;
|
|
145
|
+
const query = qs_1.default.parse(location.search, { ignoreQueryPrefix: true });
|
|
146
|
+
if (this.isPullDownRefreshEnabled()) {
|
|
147
|
+
return (React.createElement(PullToRefresh_1.default, { onRefresh: this.handleRefresh, refreshing: refreshing, distanceToRefresh: 50 },
|
|
148
|
+
React.createElement("div", { className: className }, React.createElement(PageWrapper, {
|
|
149
|
+
page,
|
|
150
|
+
query,
|
|
151
|
+
ref: page.wrapperRef,
|
|
152
|
+
}))));
|
|
153
|
+
}
|
|
154
|
+
return (React.createElement("div", { className: className }, React.createElement(PageWrapper, {
|
|
155
|
+
page,
|
|
156
|
+
query,
|
|
157
|
+
ref: page.wrapperRef,
|
|
158
|
+
})));
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
exports.default = createPageConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function usePageInstance(): any;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
7
|
+
const qs_1 = __importDefault(require("qs"));
|
|
8
|
+
const framework_shared_1 = require("@rsmax/framework-shared");
|
|
9
|
+
function useQuery() {
|
|
10
|
+
const location = framework_shared_1.RuntimeOptions.get('mpa') ? window.location : (0, react_router_dom_1.useLocation)();
|
|
11
|
+
return qs_1.default.parse(location.search, { ignoreQueryPrefix: true });
|
|
12
|
+
}
|
|
13
|
+
exports.default = useQuery;
|
package/cjs/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { useAppEvent, usePageEvent } from '@rsmax/framework-shared';
|
|
2
|
+
export { default as createAppConfig } from './createAppConfig';
|
|
3
|
+
export { default as createPageConfig } from './createPageConfig';
|
|
4
|
+
export { default as useQuery } from './hooks/useQuery';
|
|
5
|
+
export { default as useNativeEffect } from './hooks/useNativeEffect';
|
|
6
|
+
export { default as usePageInstance } from './hooks/usePageInstance';
|
|
7
|
+
export { default as bootstrap } from './bootstrap';
|
|
8
|
+
export { default as bootstrapMpa } from './bootstrapMpa';
|
|
9
|
+
export * from './api';
|
|
10
|
+
export * from './types';
|
package/cjs/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.bootstrapMpa = exports.bootstrap = exports.usePageInstance = exports.useNativeEffect = exports.useQuery = exports.createPageConfig = exports.createAppConfig = exports.usePageEvent = exports.useAppEvent = void 0;
|
|
21
|
+
var framework_shared_1 = require("@rsmax/framework-shared");
|
|
22
|
+
Object.defineProperty(exports, "useAppEvent", { enumerable: true, get: function () { return framework_shared_1.useAppEvent; } });
|
|
23
|
+
Object.defineProperty(exports, "usePageEvent", { enumerable: true, get: function () { return framework_shared_1.usePageEvent; } });
|
|
24
|
+
var createAppConfig_1 = require("./createAppConfig");
|
|
25
|
+
Object.defineProperty(exports, "createAppConfig", { enumerable: true, get: function () { return __importDefault(createAppConfig_1).default; } });
|
|
26
|
+
var createPageConfig_1 = require("./createPageConfig");
|
|
27
|
+
Object.defineProperty(exports, "createPageConfig", { enumerable: true, get: function () { return __importDefault(createPageConfig_1).default; } });
|
|
28
|
+
var useQuery_1 = require("./hooks/useQuery");
|
|
29
|
+
Object.defineProperty(exports, "useQuery", { enumerable: true, get: function () { return __importDefault(useQuery_1).default; } });
|
|
30
|
+
var useNativeEffect_1 = require("./hooks/useNativeEffect");
|
|
31
|
+
Object.defineProperty(exports, "useNativeEffect", { enumerable: true, get: function () { return __importDefault(useNativeEffect_1).default; } });
|
|
32
|
+
var usePageInstance_1 = require("./hooks/usePageInstance");
|
|
33
|
+
Object.defineProperty(exports, "usePageInstance", { enumerable: true, get: function () { return __importDefault(usePageInstance_1).default; } });
|
|
34
|
+
var bootstrap_1 = require("./bootstrap");
|
|
35
|
+
Object.defineProperty(exports, "bootstrap", { enumerable: true, get: function () { return __importDefault(bootstrap_1).default; } });
|
|
36
|
+
var bootstrapMpa_1 = require("./bootstrapMpa");
|
|
37
|
+
Object.defineProperty(exports, "bootstrapMpa", { enumerable: true, get: function () { return __importDefault(bootstrapMpa_1).default; } });
|
|
38
|
+
__exportStar(require("./api"), exports);
|
|
39
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface Page {
|
|
3
|
+
route: string;
|
|
4
|
+
config: PageConfig;
|
|
5
|
+
}
|
|
6
|
+
export declare const enum RouterType {
|
|
7
|
+
hash = "hash",
|
|
8
|
+
browser = "browser"
|
|
9
|
+
}
|
|
10
|
+
export interface BootstrapOptions {
|
|
11
|
+
async?: boolean;
|
|
12
|
+
appComponent: React.ComponentType;
|
|
13
|
+
appConfig: AppConfig;
|
|
14
|
+
plugins?: any[];
|
|
15
|
+
pageComponents: Array<() => Promise<{
|
|
16
|
+
default: React.ComponentType;
|
|
17
|
+
}> | React.ComponentType>;
|
|
18
|
+
pages: Page[];
|
|
19
|
+
}
|
|
20
|
+
export interface TabItem {
|
|
21
|
+
/**
|
|
22
|
+
* 设置页面路径
|
|
23
|
+
*/
|
|
24
|
+
url: string;
|
|
25
|
+
/**
|
|
26
|
+
* 名称
|
|
27
|
+
*/
|
|
28
|
+
title: string;
|
|
29
|
+
/**
|
|
30
|
+
* 平常图标路径
|
|
31
|
+
*/
|
|
32
|
+
image: string;
|
|
33
|
+
/**
|
|
34
|
+
* 高亮图标路径
|
|
35
|
+
*/
|
|
36
|
+
activeImage?: string;
|
|
37
|
+
}
|
|
38
|
+
export interface TabBarConfig {
|
|
39
|
+
/**
|
|
40
|
+
* 标题颜色
|
|
41
|
+
*/
|
|
42
|
+
textColor?: string;
|
|
43
|
+
/**
|
|
44
|
+
* 选中标题颜色
|
|
45
|
+
*/
|
|
46
|
+
selectedColor?: string;
|
|
47
|
+
/**
|
|
48
|
+
* 背景色
|
|
49
|
+
*/
|
|
50
|
+
backgroundColor?: string;
|
|
51
|
+
/**
|
|
52
|
+
* 每个 tab 配置
|
|
53
|
+
*/
|
|
54
|
+
items: TabItem[];
|
|
55
|
+
}
|
|
56
|
+
interface WindowConfig {
|
|
57
|
+
/**
|
|
58
|
+
* 页面默认标题
|
|
59
|
+
*/
|
|
60
|
+
defaultTitle?: string;
|
|
61
|
+
/**
|
|
62
|
+
* 默认值:false
|
|
63
|
+
* 是否开启全局的下拉刷新。
|
|
64
|
+
*/
|
|
65
|
+
pullRefresh?: boolean;
|
|
66
|
+
/**
|
|
67
|
+
* 默认值:50
|
|
68
|
+
* 页面触底事件触发时距页面底部距离,单位为 px。
|
|
69
|
+
*/
|
|
70
|
+
onReachBottomDistance?: number;
|
|
71
|
+
}
|
|
72
|
+
/** 全局配置文件 */
|
|
73
|
+
export interface AppConfig {
|
|
74
|
+
/**
|
|
75
|
+
* 设置页面路径
|
|
76
|
+
*/
|
|
77
|
+
pages: string[];
|
|
78
|
+
window?: WindowConfig;
|
|
79
|
+
/**
|
|
80
|
+
* 设置底部 tab bar 的表现
|
|
81
|
+
*/
|
|
82
|
+
tabBar?: TabBarConfig;
|
|
83
|
+
router?: {
|
|
84
|
+
type: RouterType;
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
/** 页面配置文件 */
|
|
88
|
+
export type PageConfig = WindowConfig;
|
|
89
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
const values = '2; 2; 2; 2';
|
|
3
|
+
const animateValues = '0; 4; 0; 0';
|
|
4
|
+
export default function LoadingIcon(props) {
|
|
5
|
+
const animate = props.animate;
|
|
6
|
+
return (React.createElement("svg", { className: "remax-pull-to-refresh-loading", xmlns: "http://www.w3.org/2000/svg", viewBox: "0 0 32 32" },
|
|
7
|
+
React.createElement("circle", { transform: "translate(8 0)", cx: "0", cy: "16", r: "0" },
|
|
8
|
+
React.createElement("animate", { attributeName: "r", values: !animate ? values : animateValues, dur: "1.2s", repeatCount: "indefinite", begin: "0", keyTimes: "0;0.2;0.7;1", keySplines: "0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8", calcMode: "spline" })),
|
|
9
|
+
React.createElement("circle", { transform: "translate(16 0)", cx: "0", cy: "16", r: "0" },
|
|
10
|
+
React.createElement("animate", { attributeName: "r", values: !animate ? values : animateValues, dur: "1.2s", repeatCount: "indefinite", begin: "0.3", keyTimes: "0;0.2;0.7;1", keySplines: "0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8", calcMode: "spline" })),
|
|
11
|
+
React.createElement("circle", { transform: "translate(24 0)", cx: "0", cy: "16", r: "0" },
|
|
12
|
+
React.createElement("animate", { attributeName: "r", values: !animate ? values : animateValues, dur: "1.2s", repeatCount: "indefinite", begin: "0.6", keyTimes: "0;0.2;0.7;1", keySplines: "0.2 0.2 0.4 0.8;0.2 0.6 0.4 0.8;0.2 0.6 0.4 0.8", calcMode: "spline" }))));
|
|
13
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import PullToRefresh from 'rmc-pull-to-refresh';
|
|
3
|
+
import LoadingIcon from './LoadingIcon';
|
|
4
|
+
const RemaxPullToRefresh = props => {
|
|
5
|
+
return (React.createElement(PullToRefresh, Object.assign({}, props, { getScrollContainer: () => {
|
|
6
|
+
document.body;
|
|
7
|
+
}, indicator: {
|
|
8
|
+
activate: React.createElement(LoadingIcon, null),
|
|
9
|
+
deactivate: React.createElement(LoadingIcon, null),
|
|
10
|
+
release: React.createElement(LoadingIcon, { animate: true }),
|
|
11
|
+
finish: React.createElement(LoadingIcon, null),
|
|
12
|
+
} })));
|
|
13
|
+
};
|
|
14
|
+
export default RemaxPullToRefresh;
|
package/esm/TabBar.d.ts
ADDED
package/esm/TabBar.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Link } from 'react-router-dom';
|
|
3
|
+
export function TabBar({ config, history }) {
|
|
4
|
+
var _a;
|
|
5
|
+
const [currentPath, setCurrentPath] = React.useState(history.location.pathname);
|
|
6
|
+
React.useEffect(() => {
|
|
7
|
+
setCurrentPath(history.location.pathname);
|
|
8
|
+
return history.listen(() => {
|
|
9
|
+
setCurrentPath(history.location.pathname);
|
|
10
|
+
});
|
|
11
|
+
}, []);
|
|
12
|
+
const isActive = (url) => {
|
|
13
|
+
if (!url.startsWith('/')) {
|
|
14
|
+
url = '/' + url;
|
|
15
|
+
}
|
|
16
|
+
return currentPath === url;
|
|
17
|
+
};
|
|
18
|
+
return (React.createElement("div", { className: "remax-tab-bar", style: { backgroundColor: (_a = config.backgroundColor) !== null && _a !== void 0 ? _a : '' } }, config.items.map((item, index) => (React.createElement(TabBarItem, { key: index, config: config, isActive: isActive(item.url), item: item })))));
|
|
19
|
+
}
|
|
20
|
+
function TabBarItem({ config, isActive, item }) {
|
|
21
|
+
var _a, _b;
|
|
22
|
+
const icon = isActive ? item.activeImage || item.image : item.image;
|
|
23
|
+
const textColor = (_a = config.textColor) !== null && _a !== void 0 ? _a : '#333';
|
|
24
|
+
const selectedColor = (_b = config.selectedColor) !== null && _b !== void 0 ? _b : '#108ee9';
|
|
25
|
+
return (React.createElement(Link, { to: `/${item.url}`, className: "remax-tab-item" },
|
|
26
|
+
React.createElement("div", { className: "remax-tab-item-image", style: { backgroundImage: `url(${icon})` } }),
|
|
27
|
+
React.createElement("div", { className: "remax-tab-item-title", style: {
|
|
28
|
+
color: isActive ? selectedColor : textColor,
|
|
29
|
+
} }, item.title)));
|
|
30
|
+
}
|
package/esm/api.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
interface NavigateToParams {
|
|
2
|
+
url: string;
|
|
3
|
+
}
|
|
4
|
+
interface NavigateBackParams {
|
|
5
|
+
/** 返回的页面数 */
|
|
6
|
+
delta?: number;
|
|
7
|
+
}
|
|
8
|
+
type RedirectToParams = NavigateToParams;
|
|
9
|
+
type ReLaunchParams = NavigateToParams;
|
|
10
|
+
type SwitchTabParams = NavigateToParams;
|
|
11
|
+
export declare function navigateTo(params: NavigateToParams): Promise<void>;
|
|
12
|
+
export declare function navigateBack(params?: NavigateBackParams): Promise<void>;
|
|
13
|
+
export declare function redirectTo(params: RedirectToParams): Promise<void>;
|
|
14
|
+
export declare function reLaunch(params: ReLaunchParams): void;
|
|
15
|
+
export declare function switchTab(params: SwitchTabParams): void;
|
|
16
|
+
export {};
|
package/esm/api.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { RuntimeOptions } from '@rsmax/framework-shared';
|
|
2
|
+
export function navigateTo(params) {
|
|
3
|
+
const history = RuntimeOptions.get('history');
|
|
4
|
+
history.push(params.url);
|
|
5
|
+
return Promise.resolve();
|
|
6
|
+
}
|
|
7
|
+
export function navigateBack(params) {
|
|
8
|
+
const history = RuntimeOptions.get('history');
|
|
9
|
+
history.go(-((params === null || params === void 0 ? void 0 : params.delta) || 1));
|
|
10
|
+
return Promise.resolve();
|
|
11
|
+
}
|
|
12
|
+
export function redirectTo(params) {
|
|
13
|
+
const history = RuntimeOptions.get('history');
|
|
14
|
+
history.replace(params.url);
|
|
15
|
+
return Promise.resolve();
|
|
16
|
+
}
|
|
17
|
+
export function reLaunch(params) {
|
|
18
|
+
window.location.href = params.url;
|
|
19
|
+
}
|
|
20
|
+
export function switchTab(params) {
|
|
21
|
+
navigateTo(params);
|
|
22
|
+
}
|
package/esm/bootstrap.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { render } from 'react-dom';
|
|
2
|
+
import hd from 'umi-hd';
|
|
3
|
+
import { createHashHistory, createBrowserHistory } from 'history';
|
|
4
|
+
import { RuntimeOptions } from '@rsmax/framework-shared';
|
|
5
|
+
import createApp from './createApp';
|
|
6
|
+
export default function bootstrap(options) {
|
|
7
|
+
hd();
|
|
8
|
+
const { appConfig } = options;
|
|
9
|
+
const history = !appConfig.router || appConfig.router.type !== 'browser' ? createHashHistory() : createBrowserHistory();
|
|
10
|
+
RuntimeOptions.apply({ history, mpa: false });
|
|
11
|
+
render(createApp(options, history), document.getElementById('remax-app'));
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function bootstrap(options: any): void;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { render } from 'react-dom';
|
|
3
|
+
import hd from 'umi-hd';
|
|
4
|
+
import createAppConfig from './createAppConfig';
|
|
5
|
+
import { PluginDriver, RuntimeOptions } from '@rsmax/framework-shared';
|
|
6
|
+
import createPageConfig from './createPageConfig';
|
|
7
|
+
const noop = () => {
|
|
8
|
+
// ignore
|
|
9
|
+
};
|
|
10
|
+
function createApp(options) {
|
|
11
|
+
const { appComponent, pageComponent, page, appConfig } = options;
|
|
12
|
+
const AppConfig = createAppConfig(appComponent);
|
|
13
|
+
const PageConfig = createPageConfig(pageComponent, page.route);
|
|
14
|
+
return (React.createElement(AppConfig, null,
|
|
15
|
+
React.createElement(PageConfig, { pageConfig: Object.assign(Object.assign({}, appConfig.window), page.config), tabBar: appConfig.tabBar, location: window.location, cacheLifecycles: {
|
|
16
|
+
didCache: noop,
|
|
17
|
+
didRecover: noop,
|
|
18
|
+
} })));
|
|
19
|
+
}
|
|
20
|
+
export default function bootstrap(options) {
|
|
21
|
+
hd();
|
|
22
|
+
const { plugins = [], page } = options;
|
|
23
|
+
const pluginDriver = new PluginDriver(plugins.map((plugin) => plugin.default || plugin));
|
|
24
|
+
const history = {
|
|
25
|
+
push(url) {
|
|
26
|
+
url = history.transformUrl(url);
|
|
27
|
+
console.log('not implemented');
|
|
28
|
+
},
|
|
29
|
+
go() {
|
|
30
|
+
console.log('not implemented');
|
|
31
|
+
},
|
|
32
|
+
replace(url) {
|
|
33
|
+
url = history.transformUrl(url);
|
|
34
|
+
location.replace(url);
|
|
35
|
+
},
|
|
36
|
+
page: null,
|
|
37
|
+
transformUrl(url) {
|
|
38
|
+
if (!url)
|
|
39
|
+
return url;
|
|
40
|
+
let publicPath = '';
|
|
41
|
+
if (url.startsWith('/'))
|
|
42
|
+
publicPath = location.pathname.replace(`/${page.route}.html`, '');
|
|
43
|
+
const arr = url.split('?');
|
|
44
|
+
arr[0] = arr[0] + '.html';
|
|
45
|
+
return publicPath + arr.join('?');
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
RuntimeOptions.apply({ pluginDriver, history, mpa: true });
|
|
49
|
+
const App = createApp(options);
|
|
50
|
+
render(App, document.getElementById('remax-app'));
|
|
51
|
+
}
|
package/esm/createApp.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { RuntimeOptions, PluginDriver } from '@rsmax/framework-shared';
|
|
3
|
+
import { CacheRoute, CacheSwitch } from '@remax/react-router-cache-route';
|
|
4
|
+
import { Router, Route, Redirect, useLocation } from 'react-router-dom';
|
|
5
|
+
import loadable from '@loadable/component';
|
|
6
|
+
import createAppConfig from './createAppConfig';
|
|
7
|
+
import createPageConfig from './createPageConfig';
|
|
8
|
+
import { TabBar } from './TabBar';
|
|
9
|
+
export default function createApp(options, history) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
const { async = true, appComponent, appConfig, pageComponents, pages, plugins = [] } = options;
|
|
12
|
+
const AppConfig = createAppConfig(appComponent);
|
|
13
|
+
const pluginDriver = new PluginDriver(plugins.map(plugin => plugin.default || plugin));
|
|
14
|
+
RuntimeOptions.apply({ pluginDriver });
|
|
15
|
+
const pageComponentsHoc = pages.map((page, i) => {
|
|
16
|
+
const pageComponent = async
|
|
17
|
+
? loadable(() => pageComponents[i]().then(({ default: c }) => createPageConfig(c, page.route)))
|
|
18
|
+
: createPageConfig(pageComponents[i](), page.route);
|
|
19
|
+
return pageComponent;
|
|
20
|
+
});
|
|
21
|
+
return (React.createElement(Router, { history: history },
|
|
22
|
+
React.createElement(AppConfig, null,
|
|
23
|
+
React.createElement(CacheSwitch, null,
|
|
24
|
+
React.createElement(Route, { exact: true, path: "/" },
|
|
25
|
+
React.createElement(Redirect, { to: `/${(_a = pages[0]) === null || _a === void 0 ? void 0 : _a.route}` })),
|
|
26
|
+
pages.map((page, i) => {
|
|
27
|
+
return (React.createElement(CacheRoute, { key: page.route, className: "remax-cached-router-wrapper", path: `/${page.route}`, exact: true }, (props) => {
|
|
28
|
+
const pageComponent = pageComponentsHoc[i];
|
|
29
|
+
return React.createElement(pageComponent, Object.assign(Object.assign({}, props), { pageConfig: Object.assign(Object.assign({}, appConfig.window), page.config), tabBar: appConfig.tabBar }));
|
|
30
|
+
}));
|
|
31
|
+
}),
|
|
32
|
+
React.createElement(Route, null,
|
|
33
|
+
React.createElement(Redirect, { to: `/${(_b = pages[0]) === null || _b === void 0 ? void 0 : _b.route}` }))),
|
|
34
|
+
((_c = appConfig.tabBar) === null || _c === void 0 ? void 0 : _c.items) && appConfig.tabBar.items.length > 0 && (React.createElement(TabBar, { history: history, config: appConfig.tabBar })),
|
|
35
|
+
process.env.NODE_ENV === 'development' && React.createElement(LogLocation, null))));
|
|
36
|
+
}
|
|
37
|
+
function LogLocation() {
|
|
38
|
+
const location = useLocation();
|
|
39
|
+
React.useEffect(() => {
|
|
40
|
+
console.log('[remax][react-router]location change', location.pathname);
|
|
41
|
+
}, [location]);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export default function createAppConfig(this: any, App: any): {
|
|
3
|
+
new (props: any): {
|
|
4
|
+
componentDidMount(): void;
|
|
5
|
+
componentWillUnmount(): void;
|
|
6
|
+
visibilityChangeEvent: () => void;
|
|
7
|
+
handelVisibilityChange: () => void;
|
|
8
|
+
render(): React.JSX.Element;
|
|
9
|
+
context: unknown;
|
|
10
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<any>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
11
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
12
|
+
readonly props: Readonly<any>;
|
|
13
|
+
state: Readonly<{}>;
|
|
14
|
+
refs: {
|
|
15
|
+
[key: string]: React.ReactInstance;
|
|
16
|
+
};
|
|
17
|
+
shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
18
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
19
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>): any;
|
|
20
|
+
componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>, snapshot?: any): void;
|
|
21
|
+
componentWillMount?(): void;
|
|
22
|
+
UNSAFE_componentWillMount?(): void;
|
|
23
|
+
componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
24
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
25
|
+
componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
|
|
26
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
|
|
27
|
+
};
|
|
28
|
+
new (props: any, context: any): {
|
|
29
|
+
componentDidMount(): void;
|
|
30
|
+
componentWillUnmount(): void;
|
|
31
|
+
visibilityChangeEvent: () => void;
|
|
32
|
+
handelVisibilityChange: () => void;
|
|
33
|
+
render(): React.JSX.Element;
|
|
34
|
+
context: unknown;
|
|
35
|
+
setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<any>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
|
|
36
|
+
forceUpdate(callback?: (() => void) | undefined): void;
|
|
37
|
+
readonly props: Readonly<any>;
|
|
38
|
+
state: Readonly<{}>;
|
|
39
|
+
refs: {
|
|
40
|
+
[key: string]: React.ReactInstance;
|
|
41
|
+
};
|
|
42
|
+
shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): boolean;
|
|
43
|
+
componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
|
|
44
|
+
getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>): any;
|
|
45
|
+
componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>, snapshot?: any): void;
|
|
46
|
+
componentWillMount?(): void;
|
|
47
|
+
UNSAFE_componentWillMount?(): void;
|
|
48
|
+
componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
49
|
+
UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
|
|
50
|
+
componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
|
|
51
|
+
UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
|
|
52
|
+
};
|
|
53
|
+
contextType?: React.Context<any> | undefined;
|
|
54
|
+
};
|