@ray-js/framework 0.6.21 → 0.6.22-beta-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.
@@ -1,10 +1,21 @@
1
+ import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
1
2
  import React from 'react';
2
3
  import ReactDOM from 'react-dom';
4
+ import set from 'lodash.set';
5
+ import { normalizeTabBar } from '@ray-js/framework-shared';
3
6
  import { Application } from '../components/Application';
7
+ import { normalizeBasename } from '../utils';
4
8
  export function createApp(options) {
9
+ var _cfg$globalConfig;
10
+
11
+ var cfg = _objectSpread({}, options);
12
+
5
13
  var root = document.createElement('div');
6
14
  root.id = 'root';
7
- document.body.appendChild(root); // 作为 web 构建的启动入口文件
15
+ document.body.appendChild(root); // 入口初始化 格式数据
16
+
17
+ 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)); // 作为 web 构建的启动入口文件
8
19
 
9
- ReactDOM.render( /*#__PURE__*/React.createElement(Application, options), root);
20
+ ReactDOM.render( /*#__PURE__*/React.createElement(Application, cfg), root);
10
21
  }
@@ -7,7 +7,6 @@ export declare type ApplicationProps = {
7
7
  tabBar: types.TabBar;
8
8
  pages: types.Pages;
9
9
  app: any;
10
- basename?: string;
11
10
  };
12
11
  export declare class Application extends React.Component<ApplicationProps, {
13
12
  component?: types.PageComponent;
@@ -9,7 +9,6 @@ import React from 'react';
9
9
  import { createRouter } from '@ray-js/router';
10
10
  import { createAppInstance } from '../../app/createAppInstance';
11
11
  import { get } from '../../utils';
12
- import { normalizeTabBar } from '../../utils/normalizeTabBar';
13
12
  import { AppWrapper } from '../AppWrapper';
14
13
  import { PageWrapper } from '../PageWrapper';
15
14
  import { TabBar } from '../TabBar';
@@ -53,10 +52,10 @@ export var Application = /*#__PURE__*/function (_React$Component) {
53
52
  var _this$props = this.props,
54
53
  routes = _this$props.routes,
55
54
  pages = _this$props.pages,
56
- tabBar = _this$props.tabBar,
57
- globalConfig = _this$props.globalConfig;
58
- var basename = globalConfig.basename;
59
- document.body.style.backgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
55
+ tabBar = _this$props.tabBar;
56
+ var basename = this.getGlobalConfig('basename', '/') || '/';
57
+ var bgColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
58
+ document.body.style.backgroundColor = bgColor;
60
59
  createRouter({
61
60
  basename: basename,
62
61
  routes: routes,
@@ -75,9 +74,8 @@ export var Application = /*#__PURE__*/function (_React$Component) {
75
74
  value: function render() {
76
75
  var _this$props2 = this.props,
77
76
  App = _this$props2.app,
78
- tabBar = _this$props2.tabBar,
79
- routes = _this$props2.routes,
80
- basename = _this$props2.basename;
77
+ tabBar = _this$props2.tabBar;
78
+ var basename = this.getGlobalConfig('basename', '/') || '/';
81
79
  var _this$state = this.state,
82
80
  PageComponent = _this$state.component,
83
81
  matchedPage = _this$state.matchedPage; // 空页面暂不渲染,否则 appEvent 无法应用到页面内部
@@ -98,7 +96,7 @@ export var Application = /*#__PURE__*/function (_React$Component) {
98
96
  getGlobalConfig: this.getGlobalConfig
99
97
  }, /*#__PURE__*/React.createElement(PageComponent, null)), matchedPage.isTabBar && /*#__PURE__*/React.createElement(TabBar, {
100
98
  basename: basename,
101
- config: normalizeTabBar(tabBar, routes)
99
+ config: tabBar
102
100
  })));
103
101
  }
104
102
  }]);
@@ -7,8 +7,7 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
7
  import "core-js/modules/es.object.to-string.js";
8
8
  import "core-js/modules/web.dom-collections.for-each.js";
9
9
  import "core-js/modules/es.object.keys.js";
10
- import React from 'react'; // import { normalizeTabBar } from '../../utils/normalizeTabBar';
11
-
10
+ import React from 'react';
12
11
  import { lifecycle, PageInstance, PageInstanceContext } from '@ray-js/runtime';
13
12
  import { pageLifecycles } from '@ray-js/types';
14
13
  import { get } from '../../utils';
@@ -10,7 +10,7 @@ import clsx from 'clsx';
10
10
  import React from 'react';
11
11
  import router from '@ray-js/router';
12
12
  import { events, appStoreEmitter, renderOptions } from '../../store/appStore';
13
- import { withPublicPath } from '../../utils/withPublicPath';
13
+ import { withPublicPath } from '../../utils';
14
14
  import styles from './index.module.less';
15
15
  export var TabBar = /*#__PURE__*/function (_React$Component) {
16
16
  _inherits(TabBar, _React$Component);
@@ -65,10 +65,7 @@ export var TabBar = /*#__PURE__*/function (_React$Component) {
65
65
  value: function render() {
66
66
  var _clsx;
67
67
 
68
- var _this$props = this.props,
69
- config = _this$props.config,
70
- _this$props$basename = _this$props.basename,
71
- basename = _this$props$basename === void 0 ? '' : _this$props$basename;
68
+ var config = this.props.config;
72
69
  var _this$state = this.state,
73
70
  currentRoute = _this$state.currentRoute,
74
71
  renderOptions = _this$state.renderOptions;
@@ -77,12 +74,13 @@ export var TabBar = /*#__PURE__*/function (_React$Component) {
77
74
  className: clsx(styles.wrapper, (_clsx = {}, _defineProperty(_clsx, styles.hidden, !renderOptions.tabBarVisible && !renderOptions.tabBarAnimation), _defineProperty(_clsx, styles.showIn, renderOptions.tabBarVisible && renderOptions.tabBarAnimation), _defineProperty(_clsx, styles.hideOut, !renderOptions.tabBarVisible && renderOptions.tabBarAnimation), _clsx))
78
75
  }, /*#__PURE__*/React.createElement("div", {
79
76
  className: styles.tabBar
80
- }, config.list.map(function (item) {
81
- var fullRoute = basename + item.route;
82
- var isActive = currentRoute === fullRoute;
77
+ }, config.list.map(function (item, index) {
78
+ var fullRoute = item.route;
79
+ var isActive = currentRoute === fullRoute; // console.log('>>>>>>>> currentRoute: %s, item: %s', currentRoute, item.route)
80
+
83
81
  return /*#__PURE__*/React.createElement("div", {
84
82
  "data-full-route": fullRoute,
85
- key: item.route || item.id,
83
+ key: item.pagePath + index,
86
84
  className: styles.item,
87
85
  onClick: function onClick() {
88
86
  router.push(item.route);
@@ -1,2 +1,3 @@
1
- import get from 'lodash.get';
2
- export { get };
1
+ export { default as get } from 'lodash.get';
2
+ export { withPublicPath } from './withPublicPath';
3
+ export { normalizeBasename } from './normalizeBasename';
@@ -1,2 +1,3 @@
1
- import get from 'lodash.get';
2
- export { get };
1
+ export { default as get } from 'lodash.get';
2
+ export { withPublicPath } from './withPublicPath';
3
+ export { normalizeBasename } from './normalizeBasename';
@@ -0,0 +1 @@
1
+ export declare function normalizeBasename(p: string | undefined | null): string;
@@ -0,0 +1,14 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.regexp.test.js";
3
+ import slash from 'slash';
4
+ export function normalizeBasename(p) {
5
+ var _p;
6
+
7
+ p = slash((_p = p) !== null && _p !== void 0 ? _p : '/');
8
+
9
+ if (!/^\//.test(p)) {
10
+ p = '/' + p;
11
+ }
12
+
13
+ return p;
14
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/framework",
3
- "version": "0.6.21",
3
+ "version": "0.6.22-beta-1",
4
4
  "description": "Ray Core",
5
5
  "keywords": [
6
6
  "ray"
@@ -20,20 +20,22 @@
20
20
  "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@ray-js/framework-mp": "^0.6.21",
24
- "@ray-js/framework-shared": "^0.6.21",
25
- "@ray-js/library": "^0.6.21",
26
- "@ray-js/location": "^0.6.21",
27
- "@ray-js/router": "^0.6.21",
28
- "@ray-js/runtime": "^0.6.21",
23
+ "@ray-js/framework-mp": "^0.6.22-beta-1",
24
+ "@ray-js/framework-shared": "^0.6.22-beta-1",
25
+ "@ray-js/library": "^0.6.22-beta-1",
26
+ "@ray-js/location": "^0.6.22-beta-1",
27
+ "@ray-js/router": "^0.6.22-beta-1",
28
+ "@ray-js/runtime": "^0.6.22-beta-1",
29
29
  "clsx": "^1.1.1",
30
30
  "hoist-non-react-statics": "^3.3.2",
31
31
  "lodash.get": "^4.4.2",
32
+ "lodash.set": "^4.3.2",
33
+ "slash": "^5.0.0",
32
34
  "tiny-invariant": "^1.1.0"
33
35
  },
34
36
  "devDependencies": {
35
- "@ray-js/cli": "^0.6.21",
36
- "@ray-js/types": "^0.6.21"
37
+ "@ray-js/cli": "^0.6.22-beta-1",
38
+ "@ray-js/types": "^0.6.22-beta-1"
37
39
  },
38
40
  "maintainers": [
39
41
  {
@@ -41,6 +43,6 @@
41
43
  "email": "tuyafe@tuya.com"
42
44
  }
43
45
  ],
44
- "gitHead": "cbb81571d068e6997e9b1fe95198c1b0275112e7",
46
+ "gitHead": "2e905a1820d0adfc0a6ca8cf3ecf1f3a584a0d44",
45
47
  "repository": {}
46
48
  }
@@ -1,2 +0,0 @@
1
- import { ApplicationProps } from './components/Application';
2
- export declare function createApp(options: ApplicationProps): void;
package/lib/createApp.js DELETED
@@ -1,10 +0,0 @@
1
- import React from 'react';
2
- import ReactDOM from 'react-dom';
3
- import { Application } from './components/Application';
4
- export function createApp(options) {
5
- var root = document.createElement('div');
6
- root.id = 'root';
7
- document.body.appendChild(root); // 作为 web 构建的启动入口文件
8
-
9
- ReactDOM.render( /*#__PURE__*/React.createElement(Application, options), root);
10
- }
@@ -1,2 +0,0 @@
1
- import { Routes, TabBar } from '@ray-js/types';
2
- export declare function normalizeTabBar(tabBar: TabBar, routes: Routes): TabBar;
@@ -1,18 +0,0 @@
1
- import "core-js/modules/es.array.map.js";
2
- import "core-js/modules/es.array.find.js";
3
- import "core-js/modules/es.object.to-string.js";
4
- export function normalizeTabBar(tabBar, routes) {
5
- if (tabBar.list) {
6
- tabBar.list = tabBar.list.map(function (item) {
7
- if (item.id) {
8
- item.route = routes.find(function (i) {
9
- return i.id === item.id;
10
- }).route;
11
- }
12
-
13
- return item;
14
- });
15
- }
16
-
17
- return tabBar;
18
- }