@ray-js/framework 0.3.0-beta.1c347991

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.
Files changed (41) hide show
  1. package/README.md +18 -0
  2. package/lib/api/index.d.ts +1 -0
  3. package/lib/api/index.js +1 -0
  4. package/lib/api/tabBar.d.ts +7 -0
  5. package/lib/api/tabBar.js +21 -0
  6. package/lib/app/createApp.d.ts +2 -0
  7. package/lib/app/createApp.js +10 -0
  8. package/lib/app/createAppInstance.d.ts +5 -0
  9. package/lib/app/createAppInstance.js +13 -0
  10. package/lib/app/index.d.ts +3 -0
  11. package/lib/app/index.js +7 -0
  12. package/lib/components/AppWrapper/index.d.ts +5 -0
  13. package/lib/components/AppWrapper/index.js +53 -0
  14. package/lib/components/AppWrapper/index.module.less +3 -0
  15. package/lib/components/Application/index.d.ts +20 -0
  16. package/lib/components/Application/index.js +107 -0
  17. package/lib/components/PageWrapper/index.d.ts +24 -0
  18. package/lib/components/PageWrapper/index.js +163 -0
  19. package/lib/components/PageWrapper/index.module.less +6 -0
  20. package/lib/components/TabBar/index.d.ts +25 -0
  21. package/lib/components/TabBar/index.js +104 -0
  22. package/lib/components/TabBar/index.module.less +73 -0
  23. package/lib/createApp.d.ts +2 -0
  24. package/lib/createApp.js +10 -0
  25. package/lib/index.d.ts +3 -0
  26. package/lib/index.js +3 -0
  27. package/lib/index.native.d.ts +1 -0
  28. package/lib/index.native.js +1 -0
  29. package/lib/runtime/index.d.ts +1 -0
  30. package/lib/runtime/index.js +3 -0
  31. package/lib/runtime/responsive.d.ts +1 -0
  32. package/lib/runtime/responsive.js +22 -0
  33. package/lib/store/appStore.d.ts +13 -0
  34. package/lib/store/appStore.js +26 -0
  35. package/lib/utils/index.d.ts +2 -0
  36. package/lib/utils/index.js +2 -0
  37. package/lib/utils/normalizeTabBar.d.ts +2 -0
  38. package/lib/utils/normalizeTabBar.js +18 -0
  39. package/lib/utils/withPublicPath.d.ts +1 -0
  40. package/lib/utils/withPublicPath.js +5 -0
  41. package/package.json +48 -0
package/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # @ray-js/framework
2
+
3
+ 实现跨端框架运行时统一,面向开发者提供统一的开发体验。
4
+
5
+ ## 框架 API
6
+
7
+ ```js
8
+ import { router, location, usePageEvent, withPageLifecycle } from 'ray';
9
+ ```
10
+
11
+ ### Hooks
12
+
13
+ - `usePageEvent(event, fn)` - 页面事件
14
+ - `useAppEvent(event, fn)` - App 事件
15
+
16
+ ### Hoc
17
+
18
+ - `withPageLifecycle` - 非页面组件使用页面事件
@@ -0,0 +1 @@
1
+ export { showTabBar, hideTabBar } from './tabBar';
@@ -0,0 +1 @@
1
+ export { showTabBar, hideTabBar } from './tabBar';
@@ -0,0 +1,7 @@
1
+ import { WithApiCallback } from '@ray-js/types';
2
+ export declare function showTabBar(options?: WithApiCallback<{
3
+ animation?: boolean;
4
+ }>): void;
5
+ export declare function hideTabBar(options?: WithApiCallback<{
6
+ animation?: boolean;
7
+ }>): void;
@@ -0,0 +1,21 @@
1
+ import { appStoreEmitter, actions } from '../store/appStore';
2
+ export function showTabBar(options) {
3
+ var _options$success, _options$complete;
4
+
5
+ appStoreEmitter.emit(actions.toggleTabBar, {
6
+ visible: true,
7
+ animation: options.animation
8
+ });
9
+ options === null || options === void 0 ? void 0 : (_options$success = options.success) === null || _options$success === void 0 ? void 0 : _options$success.call(options);
10
+ options === null || options === void 0 ? void 0 : (_options$complete = options.complete) === null || _options$complete === void 0 ? void 0 : _options$complete.call(options);
11
+ }
12
+ export function hideTabBar(options) {
13
+ var _options$success2, _options$complete2;
14
+
15
+ appStoreEmitter.emit(actions.toggleTabBar, {
16
+ visible: false,
17
+ animation: options.animation
18
+ });
19
+ options === null || options === void 0 ? void 0 : (_options$success2 = options.success) === null || _options$success2 === void 0 ? void 0 : _options$success2.call(options);
20
+ options === null || options === void 0 ? void 0 : (_options$complete2 = options.complete) === null || _options$complete2 === void 0 ? void 0 : _options$complete2.call(options);
21
+ }
@@ -0,0 +1,2 @@
1
+ import { ApplicationProps } from '../components/Application';
2
+ export declare function createApp(options: ApplicationProps): void;
@@ -0,0 +1,10 @@
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
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * 创建抽象的 App Instance 对标到小程序,提供给 getApp() 进行使用
3
+ * @param appThis
4
+ */
5
+ export declare function createAppInstance(appThis: any): void;
@@ -0,0 +1,13 @@
1
+ import { getCurrent } from '@ray-js/runtime';
2
+ /**
3
+ * 创建抽象的 App Instance 对标到小程序,提供给 getApp() 进行使用
4
+ * @param appThis
5
+ */
6
+
7
+ export function createAppInstance(appThis) {
8
+ var current = getCurrent(); // App 实例仅且注册一次
9
+
10
+ if (!current.app) {
11
+ current.app = appThis;
12
+ }
13
+ }
@@ -0,0 +1,3 @@
1
+ export * from './createApp';
2
+ export * from './createAppInstance';
3
+ export declare function getApp(): import("@ray-js/runtime/lib/instance").AppInstance | null;
@@ -0,0 +1,7 @@
1
+ import { getCurrent } from '@ray-js/runtime';
2
+ export * from './createApp';
3
+ export * from './createAppInstance';
4
+ export function getApp() {
5
+ var current = getCurrent();
6
+ return current.app;
7
+ }
@@ -0,0 +1,5 @@
1
+ import React from 'react';
2
+ export declare class AppWrapper extends React.Component {
3
+ componentDidMount(): void;
4
+ render(): JSX.Element;
5
+ }
@@ -0,0 +1,53 @@
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
+ import React from 'react';
6
+ import styles from './index.module.less';
7
+ import { getApp } from '../../app';
8
+ import location from '@ray-js/location';
9
+ export var AppWrapper = /*#__PURE__*/function (_React$Component) {
10
+ _inherits(AppWrapper, _React$Component);
11
+
12
+ var _super = _createSuper(AppWrapper);
13
+
14
+ function AppWrapper() {
15
+ _classCallCheck(this, AppWrapper);
16
+
17
+ return _super.apply(this, arguments);
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
+ }
41
+ }
42
+ }, {
43
+ key: "render",
44
+ value: function render() {
45
+ return /*#__PURE__*/React.createElement("div", {
46
+ id: "Application",
47
+ className: styles.application
48
+ }, this.props.children);
49
+ }
50
+ }]);
51
+
52
+ return AppWrapper;
53
+ }(React.Component);
@@ -0,0 +1,3 @@
1
+ .application {
2
+ min-height: 100vh;
3
+ }
@@ -0,0 +1,20 @@
1
+ import '../../runtime';
2
+ import React from 'react';
3
+ import * as types from '@ray-js/types';
4
+ export declare type ApplicationProps = {
5
+ globalConfig: types.GlobalConfig & types.WebGlobalConfig;
6
+ routes: types.Routes;
7
+ tabBar: types.TabBar;
8
+ pages: types.Pages;
9
+ app: any;
10
+ basename?: string;
11
+ };
12
+ export declare class Application extends React.Component<ApplicationProps, {
13
+ component?: types.PageComponent;
14
+ matchedPage?: types.MatchedPage;
15
+ }> {
16
+ constructor(props: Readonly<ApplicationProps>);
17
+ componentDidMount(): void;
18
+ getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
19
+ render(): JSX.Element | null;
20
+ }
@@ -0,0 +1,107 @@
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
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
+ import '../../runtime';
8
+ import React from 'react';
9
+ import { createRouter } from '@ray-js/router';
10
+ import { createAppInstance } from '../../app/createAppInstance';
11
+ import { get } from '../../utils';
12
+ import { normalizeTabBar } from '../../utils/normalizeTabBar';
13
+ import { AppWrapper } from '../AppWrapper';
14
+ import { PageWrapper } from '../PageWrapper';
15
+ import { TabBar } from '../TabBar';
16
+
17
+ var isClassComponent = function (Component) {
18
+ return Component.prototype && typeof Component.prototype.render === 'function';
19
+ };
20
+
21
+ export var Application = /*#__PURE__*/function (_React$Component) {
22
+ _inherits(Application, _React$Component);
23
+
24
+ var _super = _createSuper(Application);
25
+
26
+ function Application(props) {
27
+ var _this;
28
+
29
+ _classCallCheck(this, Application);
30
+
31
+ _this = _super.call(this, props);
32
+
33
+ _defineProperty(_assertThisInitialized(_this), "getGlobalConfig", function (path, defaultValue) {
34
+ var _this$props$globalCon = _this.props.globalConfig,
35
+ globalConfig = _this$props$globalCon === void 0 ? {} : _this$props$globalCon;
36
+ var value = get(globalConfig, path, defaultValue);
37
+ return value;
38
+ });
39
+
40
+ _this.state = {};
41
+
42
+ var title = _this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
43
+
44
+ document.title = title;
45
+ return _this;
46
+ }
47
+
48
+ _createClass(Application, [{
49
+ key: "componentDidMount",
50
+ value: function componentDidMount() {
51
+ var _this2 = this;
52
+
53
+ var _this$props = this.props,
54
+ routes = _this$props.routes,
55
+ 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');
60
+ createRouter({
61
+ basename: basename,
62
+ routes: routes,
63
+ pages: pages,
64
+ tabBar: tabBar,
65
+ onChange: function onChange(component, props) {
66
+ _this2.setState({
67
+ component: component,
68
+ matchedPage: props.page
69
+ });
70
+ }
71
+ });
72
+ }
73
+ }, {
74
+ key: "render",
75
+ value: function render() {
76
+ var _this$props2 = this.props,
77
+ App = _this$props2.app,
78
+ tabBar = _this$props2.tabBar,
79
+ routes = _this$props2.routes,
80
+ basename = _this$props2.basename;
81
+ var _this$state = this.state,
82
+ PageComponent = _this$state.component,
83
+ matchedPage = _this$state.matchedPage; // 空页面暂不渲染,否则 appEvent 无法应用到页面内部
84
+
85
+ if (!matchedPage) {
86
+ return null;
87
+ }
88
+
89
+ var isClassType = isClassComponent(PageComponent);
90
+ return /*#__PURE__*/React.createElement(AppWrapper, null, /*#__PURE__*/React.createElement(App, {
91
+ ref: function ref(appThis) {
92
+ createAppInstance(appThis);
93
+ }
94
+ }, /*#__PURE__*/React.createElement(PageWrapper, {
95
+ isClassType: isClassType,
96
+ page: matchedPage,
97
+ key: matchedPage.route,
98
+ getGlobalConfig: this.getGlobalConfig
99
+ }, /*#__PURE__*/React.createElement(PageComponent, null)), matchedPage.isTabBar && /*#__PURE__*/React.createElement(TabBar, {
100
+ basename: basename,
101
+ config: normalizeTabBar(tabBar, routes)
102
+ })));
103
+ }
104
+ }]);
105
+
106
+ return Application;
107
+ }(React.Component);
@@ -0,0 +1,24 @@
1
+ import React from 'react';
2
+ import { PageInstance } from '@ray-js/runtime';
3
+ import { Page, PageConfig } from '@ray-js/types';
4
+ import './index.module.less';
5
+ declare type PageWrapperProps = {
6
+ isClassType: boolean;
7
+ page: Page;
8
+ getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
9
+ };
10
+ export declare class PageWrapper extends React.Component<PageWrapperProps, any> {
11
+ $instance: PageInstance;
12
+ $isReachBottom: boolean;
13
+ $reachBottomDistance: number;
14
+ getGlobalConfig: PageWrapperProps['getGlobalConfig'];
15
+ constructor(props: Readonly<PageWrapperProps>);
16
+ componentDidMount(): void;
17
+ componentWillUnmount(): void;
18
+ handlePageResize: () => void;
19
+ handlePageScroll: () => void;
20
+ checkReachBottom: () => void;
21
+ getPageConfig: (field: keyof PageConfig | string[], defaultValue?: any) => any;
22
+ render(): JSX.Element;
23
+ }
24
+ export {};
@@ -0,0 +1,163 @@
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
+ 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
+ import React from 'react'; // import { normalizeTabBar } from '../../utils/normalizeTabBar';
11
+
12
+ import { lifecycle, PageInstance, PageInstanceContext } from '@ray-js/runtime';
13
+ import { pageLifecycles } from '@ray-js/types';
14
+ import { get } from '../../utils';
15
+ import './index.module.less';
16
+ export var PageWrapper = /*#__PURE__*/function (_React$Component) {
17
+ _inherits(PageWrapper, _React$Component);
18
+
19
+ var _super = _createSuper(PageWrapper);
20
+
21
+ function PageWrapper(props) {
22
+ var _this;
23
+
24
+ _classCallCheck(this, PageWrapper);
25
+
26
+ _this = _super.call(this, props);
27
+
28
+ _defineProperty(_assertThisInitialized(_this), "$reachBottomDistance", 50);
29
+
30
+ _defineProperty(_assertThisInitialized(_this), "handlePageResize", function () {
31
+ var windowWidth = document.documentElement.clientWidth;
32
+ var windowHeight = document.documentElement.clientHeight;
33
+ lifecycle.emit({
34
+ uniqueId: _this.$instance.uniqueId,
35
+ name: pageLifecycles.onResize,
36
+ args: {
37
+ windowWidth: windowWidth,
38
+ windowHeight: windowHeight
39
+ }
40
+ });
41
+ });
42
+
43
+ _defineProperty(_assertThisInitialized(_this), "handlePageScroll", function () {
44
+ var event = {
45
+ scrollTop: window.scrollY
46
+ };
47
+ lifecycle.emit({
48
+ uniqueId: _this.$instance.uniqueId,
49
+ name: pageLifecycles.onPageScroll,
50
+ args: event
51
+ });
52
+
53
+ _this.checkReachBottom();
54
+ });
55
+
56
+ _defineProperty(_assertThisInitialized(_this), "checkReachBottom", function () {
57
+ var isCurrentReachBottom = document.body.scrollHeight - (window.innerHeight + window.scrollY) <= _this.$reachBottomDistance;
58
+
59
+ if (!_this.$isReachBottom && isCurrentReachBottom) {
60
+ _this.$isReachBottom = true;
61
+ lifecycle.emit({
62
+ uniqueId: _this.$instance.uniqueId,
63
+ name: pageLifecycles.onReachBottom
64
+ });
65
+ return;
66
+ }
67
+
68
+ _this.$isReachBottom = isCurrentReachBottom;
69
+ });
70
+
71
+ _defineProperty(_assertThisInitialized(_this), "getPageConfig", function (field, defaultValue) {
72
+ var page = _this.props.page;
73
+ var pageConfig = page.config;
74
+ return get(pageConfig, field, defaultValue);
75
+ });
76
+
77
+ _this.$instance = new PageInstance();
78
+ lifecycle.addInstance(_this.$instance);
79
+ _this.getGlobalConfig = _this.props.getGlobalConfig;
80
+ return _this;
81
+ }
82
+
83
+ _createClass(PageWrapper, [{
84
+ key: "componentDidMount",
85
+ value: function componentDidMount() {
86
+ var title = this.getPageConfig('navigationBarTitleText', '');
87
+ document.title = title;
88
+ window.addEventListener('scroll', this.handlePageScroll);
89
+ window.addEventListener('resize', this.handlePageResize);
90
+ var backgroundColor = this.getPageConfig('backgroundColor');
91
+
92
+ if (backgroundColor) {
93
+ document.body.style.backgroundColor = backgroundColor;
94
+ } // 获取页面触底的距离
95
+
96
+
97
+ this.$reachBottomDistance = this.getPageConfig('onReachBottomDistance', this.getGlobalConfig(['window', 'onReachBottomDistance'], 50) // 全局配置
98
+ ); // FIXME: 应用实例化未完成,didMount 从内至外执行
99
+ // 此时触发 onShow onReady 获取不到 getApp 实例,组件内也存在这样的情况
100
+
101
+ lifecycle.emit({
102
+ uniqueId: this.$instance.uniqueId,
103
+ name: pageLifecycles.onShow
104
+ });
105
+ lifecycle.emit({
106
+ uniqueId: this.$instance.uniqueId,
107
+ name: pageLifecycles.onReady
108
+ });
109
+ }
110
+ }, {
111
+ key: "componentWillUnmount",
112
+ value: function componentWillUnmount() {
113
+ window.removeEventListener('scroll', this.handlePageScroll);
114
+ window.removeEventListener('resize', this.handlePageResize); // FIXME: 目前是 SPA 的页面直接切换,卸载前直接调用事件
115
+
116
+ lifecycle.emit({
117
+ uniqueId: this.$instance.uniqueId,
118
+ name: pageLifecycles.onHide
119
+ });
120
+ lifecycle.emit({
121
+ uniqueId: this.$instance.uniqueId,
122
+ name: pageLifecycles.onUnload
123
+ });
124
+ lifecycle.removeInstance(this.$instance); // TODO: 实现 onPullDownRefresh 生命周期
125
+ }
126
+ }, {
127
+ key: "render",
128
+ value: function render() {
129
+ var _this$props = this.props,
130
+ page = _this$props.page,
131
+ children = _this$props.children,
132
+ isClassType = _this$props.isClassType;
133
+ var $instance = this.$instance;
134
+ var globalBackgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
135
+ var backgroundColor = this.getPageConfig('backgroundColor', globalBackgroundColor);
136
+ document.body.style.backgroundColor = backgroundColor;
137
+ return /*#__PURE__*/React.createElement(PageInstanceContext.Provider, {
138
+ value: {
139
+ $instance: $instance,
140
+ pageConfig: page.config
141
+ }
142
+ }, /*#__PURE__*/React.createElement("ty-page", {
143
+ "data-route": page.route
144
+ }, isClassType ?
145
+ /*#__PURE__*/
146
+ // @ts-ignore
147
+ React.cloneElement(children, {
148
+ ref: function ref(ins) {
149
+ if (ins) {
150
+ // 实现 class 生命周期用法的挂载
151
+ Object.keys(pageLifecycles).forEach(function (event) {
152
+ if (typeof ins[event] === 'function') {
153
+ $instance.registerLifecycle(event, ins, ins[event]);
154
+ }
155
+ });
156
+ }
157
+ }
158
+ }) : children));
159
+ }
160
+ }]);
161
+
162
+ return PageWrapper;
163
+ }(React.Component);
@@ -0,0 +1,6 @@
1
+ page {
2
+ min-height: 100vh;
3
+ transform: translate(0);
4
+ background-color: #fff;
5
+ display: block;
6
+ }
@@ -0,0 +1,25 @@
1
+ import React from 'react';
2
+ import { TabBar as ITabBar } from '@ray-js/types';
3
+ import { renderOptions } from '../../store/appStore';
4
+ declare type TabBarProps = {
5
+ config: ITabBar;
6
+ basename?: string;
7
+ };
8
+ export declare class TabBar extends React.Component<TabBarProps, {
9
+ currentRoute: string;
10
+ renderOptions: typeof renderOptions;
11
+ }> {
12
+ unChangeHandle: () => void;
13
+ unAppStoreChange: () => void;
14
+ state: {
15
+ currentRoute: string;
16
+ renderOptions: {
17
+ tabBarVisible: boolean;
18
+ tabBarAnimation: boolean;
19
+ };
20
+ };
21
+ componentDidMount(): void;
22
+ componentWillUnmount(): void;
23
+ render(): JSX.Element;
24
+ }
25
+ export {};
@@ -0,0 +1,104 @@
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
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
7
+ import "core-js/modules/es.array.concat.js";
8
+ import "core-js/modules/es.array.map.js";
9
+ import clsx from 'clsx';
10
+ import React from 'react';
11
+ import router from '@ray-js/router';
12
+ import { events, appStoreEmitter, renderOptions } from '../../store/appStore';
13
+ import { withPublicPath } from '../../utils/withPublicPath';
14
+ import styles from './index.module.less';
15
+ export var TabBar = /*#__PURE__*/function (_React$Component) {
16
+ _inherits(TabBar, _React$Component);
17
+
18
+ var _super = _createSuper(TabBar);
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", {
32
+ currentRoute: router.scheduler.currentRoute,
33
+ renderOptions: renderOptions
34
+ });
35
+
36
+ return _this;
37
+ }
38
+
39
+ _createClass(TabBar, [{
40
+ key: "componentDidMount",
41
+ value: function componentDidMount() {
42
+ var _this2 = this;
43
+
44
+ this.unChangeHandle = router.scheduler.on('routeChange', function (route) {
45
+ _this2.setState({
46
+ currentRoute: route
47
+ });
48
+ });
49
+ this.unAppStoreChange = appStoreEmitter.on(events.tabBarChange, function (state) {
50
+ _this2.setState({
51
+ renderOptions: state
52
+ });
53
+ });
54
+ }
55
+ }, {
56
+ key: "componentWillUnmount",
57
+ value: function componentWillUnmount() {
58
+ var _this$unChangeHandle, _this$unAppStoreChang;
59
+
60
+ (_this$unChangeHandle = this.unChangeHandle) === null || _this$unChangeHandle === void 0 ? void 0 : _this$unChangeHandle.call(this);
61
+ (_this$unAppStoreChang = this.unAppStoreChange) === null || _this$unAppStoreChang === void 0 ? void 0 : _this$unAppStoreChang.call(this);
62
+ }
63
+ }, {
64
+ key: "render",
65
+ value: function render() {
66
+ var _clsx;
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;
72
+ var _this$state = this.state,
73
+ currentRoute = _this$state.currentRoute,
74
+ renderOptions = _this$state.renderOptions;
75
+ return /*#__PURE__*/React.createElement("div", {
76
+ "data-route": currentRoute,
77
+ 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
+ }, /*#__PURE__*/React.createElement("div", {
79
+ className: styles.tabBar
80
+ }, config.list.map(function (item) {
81
+ var fullRoute = basename + item.route;
82
+ var isActive = currentRoute === fullRoute;
83
+ return /*#__PURE__*/React.createElement("div", {
84
+ "data-full-route": fullRoute,
85
+ key: item.route || item.id,
86
+ className: styles.item,
87
+ onClick: function onClick() {
88
+ router.push(item.route);
89
+ }
90
+ }, item.icon && /*#__PURE__*/React.createElement("img", {
91
+ className: styles.icon,
92
+ src: "".concat(withPublicPath(isActive ? item.activeIcon : item.icon))
93
+ }), /*#__PURE__*/React.createElement("span", {
94
+ className: styles.text,
95
+ style: {
96
+ color: isActive ? config.selectedColor : config.textColor
97
+ }
98
+ }, item.text));
99
+ })));
100
+ }
101
+ }]);
102
+
103
+ return TabBar;
104
+ }(React.Component);
@@ -0,0 +1,73 @@
1
+ .wrapper {
2
+ overflow: hidden;
3
+ position: fixed;
4
+ bottom: 0;
5
+ }
6
+
7
+ @keyframes slideInUp {
8
+ 0% {
9
+ visibility: visible;
10
+ transform: translate3d(0, 100%, 0);
11
+ }
12
+
13
+ 100% {
14
+ transform: translate3d(0, 0, 0);
15
+ }
16
+ }
17
+ @keyframes slideOutDown {
18
+ 0% {
19
+ transform: translate3d(0, 0, 0);
20
+ }
21
+
22
+ 100% {
23
+ visibility: visible;
24
+ transform: translate3d(0, 100%, 0);
25
+ }
26
+ }
27
+
28
+ .hidden {
29
+ display: none;
30
+ }
31
+ .showIn {
32
+ animation-name: slideInUp;
33
+ animation-duration: 0.2s;
34
+ animation-fill-mode: both;
35
+ animation-timing-function: ease-in;
36
+ animation-iteration-count: initial;
37
+ }
38
+ .hideOut {
39
+ animation-name: slideOutDown;
40
+ animation-duration: 0.2s;
41
+ animation-fill-mode: both;
42
+ animation-timing-function: ease-out;
43
+ animation-iteration-count: initial;
44
+ }
45
+
46
+ .tabBar {
47
+ height: 50px;
48
+ background-color: #fff;
49
+ border-top: 1px solid #eee;
50
+ width: 750rpx;
51
+ display: flex;
52
+ padding-bottom: 0;
53
+ padding-bottom: constant(safe-area-inset-bottom);
54
+ padding-bottom: env(safe-area-inset-bottom);
55
+ z-index: 999;
56
+ }
57
+
58
+ .item {
59
+ flex: 1;
60
+ display: flex;
61
+ flex-direction: column;
62
+ align-items: center;
63
+ justify-content: center;
64
+ }
65
+
66
+ .text {
67
+ font-size: 12px;
68
+ padding-top: 2px;
69
+ }
70
+ .icon {
71
+ width: 24px;
72
+ height: 24px;
73
+ }
@@ -0,0 +1,2 @@
1
+ import { ApplicationProps } from './components/Application';
2
+ export declare function createApp(options: ApplicationProps): void;
@@ -0,0 +1,10 @@
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
+ }
package/lib/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { createApp, getApp } from './app';
2
+ export { lifecycle, PageInstance, PageInstanceContext, useAppEvent, usePageEvent, withPageLifecycle, } from '@ray-js/runtime';
3
+ export * from './api';
package/lib/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export { createApp, getApp } from './app';
2
+ export { lifecycle, PageInstance, PageInstanceContext, useAppEvent, usePageEvent, withPageLifecycle } from '@ray-js/runtime';
3
+ export * from './api';
@@ -0,0 +1 @@
1
+ export * from '@ray-js/framework-native';
@@ -0,0 +1 @@
1
+ export * from '@ray-js/framework-native';
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,3 @@
1
+ import { responsive } from './responsive'; // 响应式设计 rem 单位
2
+
3
+ responsive();
@@ -0,0 +1 @@
1
+ export declare function responsive(): void;
@@ -0,0 +1,22 @@
1
+ import "core-js/modules/es.parse-float.js";
2
+ var htmlRoot = document.querySelector('html');
3
+ export function responsive() {
4
+ function setRem() {
5
+ var clientWidth = htmlRoot.clientWidth; // clientWidth = Math.min(clientWidth, 640); // PC 模式下限定最大值
6
+
7
+ htmlRoot.style.fontSize = "".concat(clientWidth / 7.5, "px");
8
+ var div = document.createElement('div');
9
+ div.style.width = '7.5rem';
10
+ document.body.appendChild(div);
11
+ htmlRoot.style.fontSize = "".concat(parseFloat(htmlRoot.style.fontSize) * clientWidth / div.clientWidth, "px");
12
+ document.body.removeChild(div);
13
+ document.body.style.fontSize = "16px";
14
+ }
15
+
16
+ var b = null;
17
+ window.addEventListener('resize', function () {
18
+ clearTimeout(b);
19
+ b = setTimeout(setRem, 100);
20
+ }, !1);
21
+ setRem();
22
+ }
@@ -0,0 +1,13 @@
1
+ import { Emitter } from '@ray-js/framework-shared';
2
+ export declare const appStoreEmitter: Emitter;
3
+ export declare const renderOptions: {
4
+ tabBarVisible: boolean;
5
+ tabBarAnimation: boolean;
6
+ };
7
+ export declare const actions: {
8
+ toggleTabBar: string;
9
+ onChange: string;
10
+ };
11
+ export declare const events: {
12
+ tabBarChange: string;
13
+ };
@@ -0,0 +1,26 @@
1
+ import "core-js/modules/es.object.assign.js";
2
+ import { Emitter } from '@ray-js/framework-shared';
3
+ export var appStoreEmitter = new Emitter();
4
+ export var renderOptions = {
5
+ tabBarVisible: true,
6
+ tabBarAnimation: false
7
+ };
8
+ export var actions = {
9
+ toggleTabBar: 'toggleTabBar',
10
+ onChange: 'onChange'
11
+ };
12
+ export var events = {
13
+ tabBarChange: 'tabBarChange'
14
+ };
15
+
16
+ var update = function (eventName, nextState) {
17
+ Object.assign(renderOptions, nextState);
18
+ appStoreEmitter.emit(eventName, renderOptions);
19
+ };
20
+
21
+ appStoreEmitter.on(actions.toggleTabBar, function (next) {
22
+ if (next.visible !== renderOptions.tabBarVisible) update(events.tabBarChange, {
23
+ tabBarVisible: next.visible,
24
+ tabBarAnimation: next.animation
25
+ });
26
+ });
@@ -0,0 +1,2 @@
1
+ import get from 'lodash.get';
2
+ export { get };
@@ -0,0 +1,2 @@
1
+ import get from 'lodash.get';
2
+ export { get };
@@ -0,0 +1,2 @@
1
+ import { Routes, TabBar } from '@ray-js/types';
2
+ export declare function normalizeTabBar(tabBar: TabBar, routes: Routes): TabBar;
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1 @@
1
+ export declare function withPublicPath(basePath: string): string;
@@ -0,0 +1,5 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
3
+ export function withPublicPath(basePath) {
4
+ return PUBLIC_PATH + basePath.replace(/^\//, '');
5
+ }
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@ray-js/framework",
3
+ "version": "0.3.0-beta.1c347991",
4
+ "description": "Ray Core",
5
+ "keywords": [
6
+ "ray"
7
+ ],
8
+ "author": "子长 <zichang.nong@tuya.com>",
9
+ "license": "MIT",
10
+ "main": "lib/index.js",
11
+ "files": [
12
+ "lib"
13
+ ],
14
+ "publishConfig": {
15
+ "access": "public",
16
+ "registry": "https://registry.npmjs.org"
17
+ },
18
+ "scripts": {
19
+ "clean": "rm -rf lib",
20
+ "build": "ray build --type=component --transform-mode=pure",
21
+ "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
22
+ },
23
+ "dependencies": {
24
+ "@ray-js/framework-mp": "^0.3.0-beta.1c347991",
25
+ "@ray-js/framework-native": "^0.3.0-beta.1c347991",
26
+ "@ray-js/framework-shared": "^0.3.0-beta.1c347991",
27
+ "@ray-js/library": "^0.3.0-beta.1c347991",
28
+ "@ray-js/location": "^0.3.0-beta.1c347991",
29
+ "@ray-js/router": "^0.3.0-beta.1c347991",
30
+ "@ray-js/runtime": "^0.3.0-beta.1c347991",
31
+ "clsx": "^1.1.1",
32
+ "hoist-non-react-statics": "^3.3.2",
33
+ "lodash.get": "^4.4.2",
34
+ "tiny-invariant": "^1.1.0"
35
+ },
36
+ "devDependencies": {
37
+ "@ray-js/cli": "^0.3.0-beta.1c347991",
38
+ "@ray-js/types": "^0.3.0-beta.1c347991"
39
+ },
40
+ "maintainers": [
41
+ {
42
+ "name": "tuyafe",
43
+ "email": "tuyafe@tuya.com"
44
+ }
45
+ ],
46
+ "gitHead": "e0bd013022ddda63380d3c9e20fd8cadb46cd61f",
47
+ "repository": {}
48
+ }