@ray-js/framework 1.4.0-alpha.1 → 1.4.0-alpha.11
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/lib/api/tabBar.js +0 -2
- package/lib/app/createApp.js +6 -7
- package/lib/app/createAppInstance.js +3 -3
- package/lib/app/index.js +1 -1
- package/lib/components/AppWrapper/index.d.ts +1 -1
- package/lib/components/AppWrapper/index.js +24 -47
- package/lib/components/Application/index.d.ts +2 -2
- package/lib/components/Application/index.js +61 -87
- package/lib/components/PageWrapper/index.d.ts +2 -2
- package/lib/components/PageWrapper/index.js +100 -130
- package/lib/components/TabBar/index.d.ts +2 -2
- package/lib/components/TabBar/index.js +59 -88
- package/lib/runtime/index.js +2 -1
- package/lib/runtime/responsive.js +5 -7
- package/lib/store/appStore.js +5 -8
- package/lib/utils/normalizeBasename.js +0 -5
- package/lib/utils/withPublicPath.js +0 -1
- package/package.json +25 -25
package/lib/api/tabBar.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { appStoreEmitter, actions } from '../store/appStore';
|
|
2
2
|
export function showTabBar(options) {
|
|
3
3
|
var _options$success, _options$complete;
|
|
4
|
-
|
|
5
4
|
appStoreEmitter.emit(actions.toggleTabBar, {
|
|
6
5
|
visible: true,
|
|
7
6
|
animation: options.animation
|
|
@@ -11,7 +10,6 @@ export function showTabBar(options) {
|
|
|
11
10
|
}
|
|
12
11
|
export function hideTabBar(options) {
|
|
13
12
|
var _options$success2, _options$complete2;
|
|
14
|
-
|
|
15
13
|
appStoreEmitter.emit(actions.toggleTabBar, {
|
|
16
14
|
visible: false,
|
|
17
15
|
animation: options.animation
|
package/lib/app/createApp.js
CHANGED
|
@@ -7,15 +7,14 @@ import { Application } from '../components/Application';
|
|
|
7
7
|
import { normalizeBasename } from '../utils';
|
|
8
8
|
export function createApp(options) {
|
|
9
9
|
var _cfg$globalConfig;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var root = document.createElement('div');
|
|
10
|
+
const cfg = _objectSpread({}, options);
|
|
11
|
+
const root = document.createElement('div');
|
|
14
12
|
root.id = 'root';
|
|
15
|
-
document.body.appendChild(root);
|
|
16
|
-
|
|
13
|
+
document.body.appendChild(root);
|
|
14
|
+
// 入口初始化 格式数据
|
|
17
15
|
set(cfg, 'globalConfig.basename', normalizeBasename((_cfg$globalConfig = cfg.globalConfig) === null || _cfg$globalConfig === void 0 ? void 0 : _cfg$globalConfig.basename));
|
|
18
|
-
set(cfg, 'tabBar', normalizeTabBar(cfg.tabBar, cfg.routes));
|
|
16
|
+
set(cfg, 'tabBar', normalizeTabBar(cfg.tabBar, cfg.routes));
|
|
19
17
|
|
|
18
|
+
// 作为 web 构建的启动入口文件
|
|
20
19
|
ReactDOM.render( /*#__PURE__*/React.createElement(Application, cfg), root);
|
|
21
20
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getCurrent } from '@ray-js/runtime';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* 创建抽象的 App Instance 对标到小程序,提供给 getApp() 进行使用
|
|
4
5
|
* @param appThis
|
|
5
6
|
*/
|
|
6
|
-
|
|
7
7
|
export function createAppInstance(appThis) {
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
const current = getCurrent();
|
|
9
|
+
// App 实例仅且注册一次
|
|
10
10
|
if (!current.app) {
|
|
11
11
|
current.app = appThis;
|
|
12
12
|
}
|
package/lib/app/index.js
CHANGED
|
@@ -1,53 +1,30 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
4
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
5
1
|
import React from 'react';
|
|
6
2
|
import styles from './index.module.less';
|
|
7
3
|
import { getApp } from '../../app';
|
|
8
4
|
import location from '@ray-js/location';
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
_createClass(AppWrapper, [{
|
|
21
|
-
key: "componentDidMount",
|
|
22
|
-
value: function componentDidMount() {
|
|
23
|
-
var app = getApp();
|
|
24
|
-
|
|
25
|
-
if (typeof app.onLaunch === 'function') {
|
|
26
|
-
app.onLaunch({
|
|
27
|
-
path: location.pathname,
|
|
28
|
-
query: location.query,
|
|
29
|
-
params: location.params
|
|
30
|
-
});
|
|
31
|
-
} // 初次展现
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (typeof app.onShow === 'function') {
|
|
35
|
-
app.onShow({
|
|
36
|
-
path: location.pathname,
|
|
37
|
-
query: location.query,
|
|
38
|
-
params: location.params
|
|
39
|
-
});
|
|
40
|
-
}
|
|
5
|
+
export class AppWrapper extends React.Component {
|
|
6
|
+
componentDidMount() {
|
|
7
|
+
const app = getApp();
|
|
8
|
+
if (typeof app.onLaunch === 'function') {
|
|
9
|
+
app.onLaunch({
|
|
10
|
+
path: location.pathname,
|
|
11
|
+
query: location.query,
|
|
12
|
+
params: location.params
|
|
13
|
+
});
|
|
41
14
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
15
|
+
// 初次展现
|
|
16
|
+
if (typeof app.onShow === 'function') {
|
|
17
|
+
app.onShow({
|
|
18
|
+
path: location.pathname,
|
|
19
|
+
query: location.query,
|
|
20
|
+
params: location.params
|
|
21
|
+
});
|
|
49
22
|
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
23
|
+
}
|
|
24
|
+
render() {
|
|
25
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
+
id: "Application",
|
|
27
|
+
className: styles.application
|
|
28
|
+
}, this.props.children);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import '../../runtime';
|
|
2
2
|
import React from 'react';
|
|
3
3
|
import * as types from '@ray-js/types';
|
|
4
|
-
export
|
|
4
|
+
export type ApplicationProps = {
|
|
5
5
|
globalConfig: types.GlobalConfig & types.WebGlobalConfig;
|
|
6
6
|
routes: types.Routes;
|
|
7
7
|
tabBar: types.TabBar;
|
|
@@ -15,5 +15,5 @@ export declare class Application extends React.Component<ApplicationProps, {
|
|
|
15
15
|
constructor(props: Readonly<ApplicationProps>);
|
|
16
16
|
componentDidMount(): void;
|
|
17
17
|
getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
|
|
18
|
-
render(): JSX.Element | null;
|
|
18
|
+
render(): React.JSX.Element | null;
|
|
19
19
|
}
|
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
2
|
import '../../runtime';
|
|
8
3
|
import React from 'react';
|
|
@@ -12,94 +7,73 @@ import { get } from '../../utils';
|
|
|
12
7
|
import { AppWrapper } from '../AppWrapper';
|
|
13
8
|
import { PageWrapper } from '../PageWrapper';
|
|
14
9
|
import { TabBar } from '../TabBar';
|
|
15
|
-
|
|
16
|
-
var isClassComponent = function (Component) {
|
|
10
|
+
const isClassComponent = Component => {
|
|
17
11
|
return Component.prototype && typeof Component.prototype.render === 'function';
|
|
18
12
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_classCallCheck(this, Application);
|
|
29
|
-
|
|
30
|
-
_this = _super.call(this, props);
|
|
31
|
-
|
|
32
|
-
_defineProperty(_assertThisInitialized(_this), "getGlobalConfig", function (path, defaultValue) {
|
|
33
|
-
var _this$props$globalCon = _this.props.globalConfig,
|
|
34
|
-
globalConfig = _this$props$globalCon === void 0 ? {} : _this$props$globalCon;
|
|
35
|
-
var value = get(globalConfig, path, defaultValue);
|
|
13
|
+
export class Application extends React.Component {
|
|
14
|
+
constructor(props) {
|
|
15
|
+
super(props);
|
|
16
|
+
_defineProperty(this, "getGlobalConfig", (path, defaultValue) => {
|
|
17
|
+
const {
|
|
18
|
+
globalConfig = {}
|
|
19
|
+
} = this.props;
|
|
20
|
+
const value = get(globalConfig, path, defaultValue);
|
|
36
21
|
return value;
|
|
37
22
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
var title = _this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
|
|
42
|
-
|
|
23
|
+
this.state = {};
|
|
24
|
+
const title = this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
|
|
43
25
|
document.title = title;
|
|
44
|
-
return _this;
|
|
45
26
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
_this2.setState({
|
|
66
|
-
component: component,
|
|
67
|
-
matchedPage: props.page
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}, {
|
|
73
|
-
key: "render",
|
|
74
|
-
value: function render() {
|
|
75
|
-
var _this$props2 = this.props,
|
|
76
|
-
App = _this$props2.app,
|
|
77
|
-
tabBar = _this$props2.tabBar;
|
|
78
|
-
var basename = this.getGlobalConfig('basename', '/') || '/';
|
|
79
|
-
var _this$state = this.state,
|
|
80
|
-
PageComponent = _this$state.component,
|
|
81
|
-
matchedPage = _this$state.matchedPage; // 空页面暂不渲染,否则 appEvent 无法应用到页面内部
|
|
82
|
-
|
|
83
|
-
if (!matchedPage) {
|
|
84
|
-
return null;
|
|
27
|
+
componentDidMount() {
|
|
28
|
+
const {
|
|
29
|
+
routes,
|
|
30
|
+
pages,
|
|
31
|
+
tabBar
|
|
32
|
+
} = this.props;
|
|
33
|
+
const basename = this.getGlobalConfig('basename', '/') || '/';
|
|
34
|
+
const bgColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
|
|
35
|
+
document.body.style.backgroundColor = bgColor;
|
|
36
|
+
createRouter({
|
|
37
|
+
basename,
|
|
38
|
+
routes,
|
|
39
|
+
pages,
|
|
40
|
+
tabBar,
|
|
41
|
+
onChange: (component, props) => {
|
|
42
|
+
this.setState({
|
|
43
|
+
component,
|
|
44
|
+
matchedPage: props.page
|
|
45
|
+
});
|
|
85
46
|
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
render() {
|
|
50
|
+
const {
|
|
51
|
+
app: App,
|
|
52
|
+
tabBar
|
|
53
|
+
} = this.props;
|
|
54
|
+
const basename = this.getGlobalConfig('basename', '/') || '/';
|
|
55
|
+
const {
|
|
56
|
+
component: PageComponent,
|
|
57
|
+
matchedPage
|
|
58
|
+
} = this.state;
|
|
86
59
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
createAppInstance(appThis);
|
|
91
|
-
}
|
|
92
|
-
}, /*#__PURE__*/React.createElement(PageWrapper, {
|
|
93
|
-
isClassType: isClassType,
|
|
94
|
-
page: matchedPage,
|
|
95
|
-
key: matchedPage.route,
|
|
96
|
-
getGlobalConfig: this.getGlobalConfig
|
|
97
|
-
}, /*#__PURE__*/React.createElement(PageComponent, null)), matchedPage.isTabBar && /*#__PURE__*/React.createElement(TabBar, {
|
|
98
|
-
basename: basename,
|
|
99
|
-
config: tabBar
|
|
100
|
-
})));
|
|
60
|
+
// 空页面暂不渲染,否则 appEvent 无法应用到页面内部
|
|
61
|
+
if (!matchedPage) {
|
|
62
|
+
return null;
|
|
101
63
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
64
|
+
const isClassType = isClassComponent(PageComponent);
|
|
65
|
+
return /*#__PURE__*/React.createElement(AppWrapper, null, /*#__PURE__*/React.createElement(App, {
|
|
66
|
+
ref: appThis => {
|
|
67
|
+
createAppInstance(appThis);
|
|
68
|
+
}
|
|
69
|
+
}, /*#__PURE__*/React.createElement(PageWrapper, {
|
|
70
|
+
isClassType: isClassType,
|
|
71
|
+
page: matchedPage,
|
|
72
|
+
key: matchedPage.route,
|
|
73
|
+
getGlobalConfig: this.getGlobalConfig
|
|
74
|
+
}, /*#__PURE__*/React.createElement(PageComponent, null)), matchedPage.isTabBar && /*#__PURE__*/React.createElement(TabBar, {
|
|
75
|
+
basename: basename,
|
|
76
|
+
config: tabBar
|
|
77
|
+
})));
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { PageInstance } from '@ray-js/runtime';
|
|
3
3
|
import { Page, PageConfig } from '@ray-js/types';
|
|
4
4
|
import './index.module.less';
|
|
5
|
-
|
|
5
|
+
type PageWrapperProps = {
|
|
6
6
|
isClassType: boolean;
|
|
7
7
|
page: Page;
|
|
8
8
|
getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
|
|
@@ -20,6 +20,6 @@ export declare class PageWrapper extends React.Component<PageWrapperProps, any>
|
|
|
20
20
|
handlePageScroll: () => void;
|
|
21
21
|
checkReachBottom: () => void;
|
|
22
22
|
getPageConfig: (field: keyof PageConfig | string[], defaultValue?: any) => any;
|
|
23
|
-
render(): JSX.Element;
|
|
23
|
+
render(): React.JSX.Element;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -1,162 +1,132 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
-
import "core-js/modules/es.object.to-string.js";
|
|
8
|
-
import "core-js/modules/web.dom-collections.for-each.js";
|
|
9
|
-
import "core-js/modules/es.object.keys.js";
|
|
10
2
|
import React from 'react';
|
|
11
3
|
import { lifecycle, PageInstance, PageInstanceContext } from '@ray-js/runtime';
|
|
12
4
|
import { pageLifecycles } from '@ray-js/types';
|
|
13
5
|
import { get } from '../../utils';
|
|
14
6
|
import './index.module.less';
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
_classCallCheck(this, PageWrapper);
|
|
24
|
-
|
|
25
|
-
_this = _super.call(this, props);
|
|
26
|
-
|
|
27
|
-
_defineProperty(_assertThisInitialized(_this), "$reachBottomDistance", 50);
|
|
28
|
-
|
|
29
|
-
_defineProperty(_assertThisInitialized(_this), "handlePageResize", function () {
|
|
30
|
-
var windowWidth = document.documentElement.clientWidth;
|
|
31
|
-
var windowHeight = document.documentElement.clientHeight;
|
|
7
|
+
export class PageWrapper extends React.Component {
|
|
8
|
+
constructor(props) {
|
|
9
|
+
super(props);
|
|
10
|
+
_defineProperty(this, "$reachBottomDistance", 50);
|
|
11
|
+
_defineProperty(this, "handlePageResize", () => {
|
|
12
|
+
const windowWidth = document.documentElement.clientWidth;
|
|
13
|
+
const windowHeight = document.documentElement.clientHeight;
|
|
32
14
|
lifecycle.emit({
|
|
33
|
-
uniqueId:
|
|
15
|
+
uniqueId: this.$instance.uniqueId,
|
|
34
16
|
name: pageLifecycles.onResize,
|
|
35
17
|
args: {
|
|
36
|
-
windowWidth
|
|
37
|
-
windowHeight
|
|
18
|
+
windowWidth,
|
|
19
|
+
windowHeight
|
|
38
20
|
}
|
|
39
21
|
});
|
|
40
22
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
var event = {
|
|
23
|
+
_defineProperty(this, "handlePageScroll", () => {
|
|
24
|
+
const event = {
|
|
44
25
|
scrollTop: window.scrollY
|
|
45
26
|
};
|
|
46
27
|
lifecycle.emit({
|
|
47
|
-
uniqueId:
|
|
28
|
+
uniqueId: this.$instance.uniqueId,
|
|
48
29
|
name: pageLifecycles.onPageScroll,
|
|
49
30
|
args: event
|
|
50
31
|
});
|
|
51
|
-
|
|
52
|
-
_this.checkReachBottom();
|
|
32
|
+
this.checkReachBottom();
|
|
53
33
|
});
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
if (!_this.$isReachBottom && isCurrentReachBottom) {
|
|
59
|
-
_this.$isReachBottom = true;
|
|
34
|
+
_defineProperty(this, "checkReachBottom", () => {
|
|
35
|
+
const isCurrentReachBottom = document.body.scrollHeight - (window.innerHeight + window.scrollY) <= this.$reachBottomDistance;
|
|
36
|
+
if (!this.$isReachBottom && isCurrentReachBottom) {
|
|
37
|
+
this.$isReachBottom = true;
|
|
60
38
|
lifecycle.emit({
|
|
61
|
-
uniqueId:
|
|
39
|
+
uniqueId: this.$instance.uniqueId,
|
|
62
40
|
name: pageLifecycles.onReachBottom
|
|
63
41
|
});
|
|
64
42
|
return;
|
|
65
43
|
}
|
|
66
|
-
|
|
67
|
-
_this.$isReachBottom = isCurrentReachBottom;
|
|
44
|
+
this.$isReachBottom = isCurrentReachBottom;
|
|
68
45
|
});
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
46
|
+
_defineProperty(this, "getPageConfig", (field, defaultValue) => {
|
|
47
|
+
const {
|
|
48
|
+
page
|
|
49
|
+
} = this.props;
|
|
50
|
+
const pageConfig = page.config;
|
|
73
51
|
return get(pageConfig, field, defaultValue);
|
|
74
52
|
});
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_this.getGlobalConfig = _this.props.getGlobalConfig;
|
|
79
|
-
return _this;
|
|
53
|
+
this.$instance = new PageInstance();
|
|
54
|
+
lifecycle.addInstance(this.$instance);
|
|
55
|
+
this.getGlobalConfig = this.props.getGlobalConfig;
|
|
80
56
|
}
|
|
57
|
+
componentDidMount() {
|
|
58
|
+
const title = this.getPageConfig('navigationBarTitleText', '');
|
|
59
|
+
document.title = title;
|
|
60
|
+
window.addEventListener('scroll', this.handlePageScroll);
|
|
61
|
+
window.addEventListener('resize', this.handlePageResize);
|
|
62
|
+
const backgroundColor = this.getPageConfig('backgroundColor');
|
|
63
|
+
if (backgroundColor) {
|
|
64
|
+
document.body.style.backgroundColor = backgroundColor;
|
|
65
|
+
}
|
|
81
66
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var title = this.getPageConfig('navigationBarTitleText', '');
|
|
86
|
-
document.title = title;
|
|
87
|
-
window.addEventListener('scroll', this.handlePageScroll);
|
|
88
|
-
window.addEventListener('resize', this.handlePageResize);
|
|
89
|
-
var backgroundColor = this.getPageConfig('backgroundColor');
|
|
90
|
-
|
|
91
|
-
if (backgroundColor) {
|
|
92
|
-
document.body.style.backgroundColor = backgroundColor;
|
|
93
|
-
} // 获取页面触底的距离
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
this.$reachBottomDistance = this.getPageConfig('onReachBottomDistance', this.getGlobalConfig(['window', 'onReachBottomDistance'], 50) // 全局配置
|
|
97
|
-
); // FIXME: 应用实例化未完成,didMount 从内至外执行
|
|
98
|
-
// 此时触发 onShow onReady 获取不到 getApp 实例,组件内也存在这样的情况
|
|
67
|
+
// 获取页面触底的距离
|
|
68
|
+
this.$reachBottomDistance = this.getPageConfig('onReachBottomDistance', this.getGlobalConfig(['window', 'onReachBottomDistance'], 50) // 全局配置
|
|
69
|
+
);
|
|
99
70
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
71
|
+
// FIXME: 应用实例化未完成,didMount 从内至外执行
|
|
72
|
+
// 此时触发 onShow onReady 获取不到 getApp 实例,组件内也存在这样的情况
|
|
73
|
+
lifecycle.emit({
|
|
74
|
+
uniqueId: this.$instance.uniqueId,
|
|
75
|
+
name: pageLifecycles.onShow
|
|
76
|
+
});
|
|
77
|
+
lifecycle.emit({
|
|
78
|
+
uniqueId: this.$instance.uniqueId,
|
|
79
|
+
name: pageLifecycles.onReady
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
componentWillUnmount() {
|
|
83
|
+
window.removeEventListener('scroll', this.handlePageScroll);
|
|
84
|
+
window.removeEventListener('resize', this.handlePageResize);
|
|
85
|
+
|
|
86
|
+
// FIXME: 目前是 SPA 的页面直接切换,卸载前直接调用事件
|
|
87
|
+
lifecycle.emit({
|
|
88
|
+
uniqueId: this.$instance.uniqueId,
|
|
89
|
+
name: pageLifecycles.onHide
|
|
90
|
+
});
|
|
91
|
+
lifecycle.emit({
|
|
92
|
+
uniqueId: this.$instance.uniqueId,
|
|
93
|
+
name: pageLifecycles.onUnload
|
|
94
|
+
});
|
|
95
|
+
lifecycle.removeInstance(this.$instance);
|
|
96
|
+
// TODO: 实现 onPullDownRefresh 生命周期
|
|
97
|
+
}
|
|
114
98
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
/*#__PURE__*/
|
|
145
|
-
// @ts-ignore
|
|
146
|
-
React.cloneElement(children, {
|
|
147
|
-
ref: function ref(ins) {
|
|
148
|
-
if (ins) {
|
|
149
|
-
// 实现 class 生命周期用法的挂载
|
|
150
|
-
Object.keys(pageLifecycles).forEach(function (event) {
|
|
151
|
-
if (typeof ins[event] === 'function') {
|
|
152
|
-
$instance.registerLifecycle(event, ins, ins[event]);
|
|
153
|
-
}
|
|
154
|
-
});
|
|
155
|
-
}
|
|
99
|
+
render() {
|
|
100
|
+
const {
|
|
101
|
+
page,
|
|
102
|
+
children,
|
|
103
|
+
isClassType
|
|
104
|
+
} = this.props;
|
|
105
|
+
const $instance = this.$instance;
|
|
106
|
+
const globalBackgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
|
|
107
|
+
const backgroundColor = this.getPageConfig('backgroundColor', globalBackgroundColor);
|
|
108
|
+
document.body.style.backgroundColor = backgroundColor;
|
|
109
|
+
return /*#__PURE__*/React.createElement(PageInstanceContext.Provider, {
|
|
110
|
+
value: {
|
|
111
|
+
$instance,
|
|
112
|
+
pageConfig: page.config
|
|
113
|
+
}
|
|
114
|
+
}, /*#__PURE__*/React.createElement("v-page", {
|
|
115
|
+
"data-route": page.route
|
|
116
|
+
}, isClassType ?
|
|
117
|
+
/*#__PURE__*/
|
|
118
|
+
// @ts-ignore
|
|
119
|
+
React.cloneElement(children, {
|
|
120
|
+
ref(ins) {
|
|
121
|
+
if (ins) {
|
|
122
|
+
// 实现 class 生命周期用法的挂载
|
|
123
|
+
Object.keys(pageLifecycles).forEach(event => {
|
|
124
|
+
if (typeof ins[event] === 'function') {
|
|
125
|
+
$instance.registerLifecycle(event, ins, ins[event]);
|
|
126
|
+
}
|
|
127
|
+
});
|
|
156
128
|
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
return PageWrapper;
|
|
162
|
-
}(React.Component);
|
|
129
|
+
}
|
|
130
|
+
}) : children));
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { TabBar as ITabBar } from '@ray-js/types';
|
|
3
3
|
import { renderOptions } from '../../store/appStore';
|
|
4
|
-
|
|
4
|
+
type TabBarProps = {
|
|
5
5
|
config: ITabBar;
|
|
6
6
|
basename?: string;
|
|
7
7
|
};
|
|
@@ -20,6 +20,6 @@ export declare class TabBar extends React.Component<TabBarProps, {
|
|
|
20
20
|
};
|
|
21
21
|
componentDidMount(): void;
|
|
22
22
|
componentWillUnmount(): void;
|
|
23
|
-
render(): JSX.Element;
|
|
23
|
+
render(): React.JSX.Element;
|
|
24
24
|
}
|
|
25
25
|
export {};
|
|
@@ -1,102 +1,73 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
-
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
4
|
-
import _inherits from "@babel/runtime/helpers/esm/inherits";
|
|
5
|
-
import _createSuper from "@babel/runtime/helpers/esm/createSuper";
|
|
6
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
7
|
-
import "core-js/modules/
|
|
8
|
-
import "core-js/modules/es.array.map.js";
|
|
2
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
9
3
|
import clsx from 'clsx';
|
|
10
4
|
import React from 'react';
|
|
11
5
|
import router from '@ray-js/router';
|
|
12
6
|
import { events, appStoreEmitter, renderOptions } from '../../store/appStore';
|
|
13
7
|
import { withPublicPath } from '../../utils';
|
|
14
8
|
import styles from './index.module.less';
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function TabBar() {
|
|
21
|
-
var _this;
|
|
22
|
-
|
|
23
|
-
_classCallCheck(this, TabBar);
|
|
24
|
-
|
|
25
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
26
|
-
args[_key] = arguments[_key];
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
_this = _super.call.apply(_super, [this].concat(args));
|
|
30
|
-
|
|
31
|
-
_defineProperty(_assertThisInitialized(_this), "state", {
|
|
9
|
+
export class TabBar extends React.Component {
|
|
10
|
+
constructor() {
|
|
11
|
+
super(...arguments);
|
|
12
|
+
_defineProperty(this, "state", {
|
|
32
13
|
currentRoute: router.scheduler.currentRoute,
|
|
33
14
|
renderOptions: renderOptions
|
|
34
15
|
});
|
|
35
|
-
|
|
36
|
-
return _this;
|
|
37
16
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var _this2 = this;
|
|
43
|
-
|
|
44
|
-
this.unChangeHandle = router.scheduler.on('routeChange', function (route) {
|
|
45
|
-
_this2.setState({
|
|
46
|
-
currentRoute: route
|
|
47
|
-
});
|
|
17
|
+
componentDidMount() {
|
|
18
|
+
this.unChangeHandle = router.scheduler.on('routeChange', route => {
|
|
19
|
+
this.setState({
|
|
20
|
+
currentRoute: route
|
|
48
21
|
});
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
22
|
+
});
|
|
23
|
+
this.unAppStoreChange = appStoreEmitter.on(events.tabBarChange, state => {
|
|
24
|
+
this.setState({
|
|
25
|
+
renderOptions: state
|
|
53
26
|
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
componentWillUnmount() {
|
|
30
|
+
var _this$unChangeHandle, _this$unAppStoreChang;
|
|
31
|
+
(_this$unChangeHandle = this.unChangeHandle) === null || _this$unChangeHandle === void 0 ? void 0 : _this$unChangeHandle.call(this);
|
|
32
|
+
(_this$unAppStoreChang = this.unAppStoreChange) === null || _this$unAppStoreChang === void 0 ? void 0 : _this$unAppStoreChang.call(this);
|
|
33
|
+
}
|
|
34
|
+
render() {
|
|
35
|
+
const {
|
|
36
|
+
config
|
|
37
|
+
} = this.props;
|
|
38
|
+
const {
|
|
39
|
+
currentRoute,
|
|
40
|
+
renderOptions
|
|
41
|
+
} = this.state;
|
|
42
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
43
|
+
"data-route": currentRoute,
|
|
44
|
+
className: clsx(styles.wrapper, {
|
|
45
|
+
[styles.hidden]: !renderOptions.tabBarVisible && !renderOptions.tabBarAnimation,
|
|
46
|
+
[styles.showIn]: renderOptions.tabBarVisible && renderOptions.tabBarAnimation,
|
|
47
|
+
[styles.hideOut]: !renderOptions.tabBarVisible && renderOptions.tabBarAnimation
|
|
48
|
+
})
|
|
49
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
50
|
+
className: styles.tabBar
|
|
51
|
+
}, config.list.map((item, index) => {
|
|
52
|
+
const fullRoute = item.route;
|
|
53
|
+
const isActive = currentRoute === fullRoute;
|
|
54
|
+
// console.log('>>>>>>>> currentRoute: %s, item: %s', currentRoute, item.route)
|
|
72
55
|
return /*#__PURE__*/React.createElement("div", {
|
|
73
|
-
"data-route":
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
}), /*#__PURE__*/React.createElement("span", {
|
|
92
|
-
className: styles.text,
|
|
93
|
-
style: {
|
|
94
|
-
color: isActive ? config.selectedColor : config.textColor
|
|
95
|
-
}
|
|
96
|
-
}, item.text));
|
|
97
|
-
})));
|
|
98
|
-
}
|
|
99
|
-
}]);
|
|
100
|
-
|
|
101
|
-
return TabBar;
|
|
102
|
-
}(React.Component);
|
|
56
|
+
"data-full-route": fullRoute,
|
|
57
|
+
key: item.pagePath + index,
|
|
58
|
+
className: styles.item,
|
|
59
|
+
onClick: () => {
|
|
60
|
+
router.push(item.route);
|
|
61
|
+
}
|
|
62
|
+
}, item.icon && /*#__PURE__*/React.createElement("img", {
|
|
63
|
+
className: styles.icon,
|
|
64
|
+
src: "".concat(withPublicPath(isActive ? item.activeIcon : item.icon))
|
|
65
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
66
|
+
className: styles.text,
|
|
67
|
+
style: {
|
|
68
|
+
color: isActive ? config.selectedColor : config.textColor
|
|
69
|
+
}
|
|
70
|
+
}, item.text));
|
|
71
|
+
})));
|
|
72
|
+
}
|
|
73
|
+
}
|
package/lib/runtime/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
var htmlRoot = document.querySelector('html');
|
|
1
|
+
const htmlRoot = document.querySelector('html');
|
|
3
2
|
export function responsive() {
|
|
4
3
|
function setRem() {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
let clientWidth = htmlRoot.clientWidth;
|
|
5
|
+
// clientWidth = Math.min(clientWidth, 640); // PC 模式下限定最大值
|
|
7
6
|
htmlRoot.style.fontSize = "".concat(clientWidth / 7.5, "px");
|
|
8
|
-
|
|
7
|
+
const div = document.createElement('div');
|
|
9
8
|
div.style.width = '7.5rem';
|
|
10
9
|
document.body.appendChild(div);
|
|
11
10
|
htmlRoot.style.fontSize = "".concat(parseFloat(htmlRoot.style.fontSize) * clientWidth / div.clientWidth, "px");
|
|
12
11
|
document.body.removeChild(div);
|
|
13
12
|
document.body.style.fontSize = "16px";
|
|
14
13
|
}
|
|
15
|
-
|
|
16
|
-
var b = null;
|
|
14
|
+
let b = null;
|
|
17
15
|
window.addEventListener('resize', function () {
|
|
18
16
|
clearTimeout(b);
|
|
19
17
|
b = setTimeout(setRem, 100);
|
package/lib/store/appStore.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
import "core-js/modules/es.object.assign.js";
|
|
2
1
|
import { Emitter } from '@ray-js/framework-shared';
|
|
3
|
-
export
|
|
4
|
-
export
|
|
2
|
+
export const appStoreEmitter = new Emitter();
|
|
3
|
+
export const renderOptions = {
|
|
5
4
|
tabBarVisible: true,
|
|
6
5
|
tabBarAnimation: false
|
|
7
6
|
};
|
|
8
|
-
export
|
|
7
|
+
export const actions = {
|
|
9
8
|
toggleTabBar: 'toggleTabBar',
|
|
10
9
|
onChange: 'onChange'
|
|
11
10
|
};
|
|
12
|
-
export
|
|
11
|
+
export const events = {
|
|
13
12
|
tabBarChange: 'tabBarChange'
|
|
14
13
|
};
|
|
15
|
-
|
|
16
|
-
var update = function (eventName, nextState) {
|
|
14
|
+
const update = (eventName, nextState) => {
|
|
17
15
|
Object.assign(renderOptions, nextState);
|
|
18
16
|
appStoreEmitter.emit(eventName, renderOptions);
|
|
19
17
|
};
|
|
20
|
-
|
|
21
18
|
appStoreEmitter.on(actions.toggleTabBar, function (next) {
|
|
22
19
|
if (next.visible !== renderOptions.tabBarVisible) update(events.tabBarChange, {
|
|
23
20
|
tabBarVisible: next.visible,
|
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
2
|
-
import "core-js/modules/es.regexp.test.js";
|
|
3
1
|
import slash from 'slash';
|
|
4
2
|
export function normalizeBasename(p) {
|
|
5
3
|
var _p;
|
|
6
|
-
|
|
7
4
|
p = slash((_p = p) !== null && _p !== void 0 ? _p : '/');
|
|
8
|
-
|
|
9
5
|
if (!/^\//.test(p)) {
|
|
10
6
|
p = '/' + p;
|
|
11
7
|
}
|
|
12
|
-
|
|
13
8
|
return p;
|
|
14
9
|
}
|
package/package.json
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ray-js/framework",
|
|
3
|
-
"version": "1.4.0-alpha.
|
|
3
|
+
"version": "1.4.0-alpha.11",
|
|
4
4
|
"description": "Ray Core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ray"
|
|
7
7
|
],
|
|
8
|
+
"repository": {},
|
|
8
9
|
"license": "MIT",
|
|
10
|
+
"maintainers": [
|
|
11
|
+
{
|
|
12
|
+
"name": "tuyafe",
|
|
13
|
+
"email": "tuyafe@tuya.com"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
9
16
|
"main": "lib/index.js",
|
|
10
17
|
"files": [
|
|
11
18
|
"lib"
|
|
12
19
|
],
|
|
13
|
-
"publishConfig": {
|
|
14
|
-
"access": "public",
|
|
15
|
-
"registry": "https://registry.npmjs.org"
|
|
16
|
-
},
|
|
17
20
|
"scripts": {
|
|
18
|
-
"clean": "rm -rf lib",
|
|
19
21
|
"build": "ray build --type=component --transform-mode=pure",
|
|
22
|
+
"clean": "rm -rf lib",
|
|
20
23
|
"watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
|
-
"@ray-js/framework-mp": "^1.4.0-alpha.
|
|
24
|
-
"@ray-js/framework-shared": "^1.4.0-alpha.
|
|
25
|
-
"@ray-js/library": "^1.4.0-alpha.
|
|
26
|
-
"@ray-js/location": "^1.4.0-alpha.
|
|
27
|
-
"@ray-js/router": "^1.4.0-alpha.
|
|
28
|
-
"@ray-js/runtime": "^1.4.0-alpha.
|
|
29
|
-
"clsx": "^1.
|
|
26
|
+
"@ray-js/framework-mp": "^1.4.0-alpha.11",
|
|
27
|
+
"@ray-js/framework-shared": "^1.4.0-alpha.11",
|
|
28
|
+
"@ray-js/library": "^1.4.0-alpha.11",
|
|
29
|
+
"@ray-js/location": "^1.4.0-alpha.11",
|
|
30
|
+
"@ray-js/router": "^1.4.0-alpha.11",
|
|
31
|
+
"@ray-js/runtime": "^1.4.0-alpha.11",
|
|
32
|
+
"clsx": "^1.2.1",
|
|
30
33
|
"hoist-non-react-statics": "^3.3.2",
|
|
31
34
|
"lodash.get": "^4.4.2",
|
|
32
35
|
"lodash.set": "^4.3.2",
|
|
33
|
-
"slash": "^5.
|
|
34
|
-
"tiny-invariant": "^1.1
|
|
36
|
+
"slash": "^5.1.0",
|
|
37
|
+
"tiny-invariant": "^1.3.1"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
|
-
"@ray-js/cli": "^1.4.0-alpha.
|
|
38
|
-
"@ray-js/types": "^1.4.0-alpha.
|
|
40
|
+
"@ray-js/cli": "^1.4.0-alpha.11",
|
|
41
|
+
"@ray-js/types": "^1.4.0-alpha.11"
|
|
39
42
|
},
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
],
|
|
46
|
-
"gitHead": "4340240aafe16c03853241e2356134610e65443e",
|
|
47
|
-
"repository": {}
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public",
|
|
45
|
+
"registry": "https://registry.npmjs.org"
|
|
46
|
+
},
|
|
47
|
+
"gitHead": "5e9c8e1d288eeaf707d34515399784d98ec13a1e"
|
|
48
48
|
}
|