@ray-js/framework 0.4.15-beta-0 → 0.5.0

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/index.js CHANGED
@@ -1 +1 @@
1
- export { showTabBar, hideTabBar } from './tabBar';
1
+ export { showTabBar, hideTabBar } from './tabBar';
package/lib/api/tabBar.js CHANGED
@@ -1,13 +1,21 @@
1
1
  import { appStoreEmitter, actions } from '../store/appStore';
2
2
  export function showTabBar(options) {
3
- var _a, _b;
4
- appStoreEmitter.emit(actions.toggleTabBar, { visible: true, animation: options.animation });
5
- (_a = options === null || options === void 0 ? void 0 : options.success) === null || _a === void 0 ? void 0 : _a.call(options);
6
- (_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(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);
7
11
  }
8
12
  export function hideTabBar(options) {
9
- var _a, _b;
10
- appStoreEmitter.emit(actions.toggleTabBar, { visible: false, animation: options.animation });
11
- (_a = options === null || options === void 0 ? void 0 : options.success) === null || _a === void 0 ? void 0 : _a.call(options);
12
- (_b = options === null || options === void 0 ? void 0 : options.complete) === null || _b === void 0 ? void 0 : _b.call(options);
13
- }
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
+ }
@@ -1,3 +1,3 @@
1
1
  export * from './createApp';
2
2
  export * from './createAppInstance';
3
- export declare function getApp(): import("@ray-js/runtime/lib/instance").AppInstance;
3
+ export declare function getApp(): import("@ray-js/runtime/lib/instance").AppInstance | null;
@@ -16,5 +16,5 @@ export declare class Application extends React.Component<ApplicationProps, {
16
16
  constructor(props: Readonly<ApplicationProps>);
17
17
  componentDidMount(): void;
18
18
  getGlobalConfig: (path: string | string[], defaultValue?: any) => any;
19
- render(): JSX.Element;
19
+ render(): JSX.Element | null;
20
20
  }
package/lib/index.js CHANGED
@@ -1,3 +1,3 @@
1
1
  export { createApp, getApp } from './app';
2
- export { lifecycle, PageInstance, PageInstanceContext, useAppEvent, usePageEvent, withPageLifecycle, } from '@ray-js/runtime';
3
- export * from './api';
2
+ export { lifecycle, PageInstance, PageInstanceContext, useAppEvent, usePageEvent, withPageLifecycle } from '@ray-js/runtime';
3
+ export * from './api';
@@ -1 +1 @@
1
- export * from '@ray-js/framework-native';
1
+ export * from '@ray-js/framework-native';
@@ -1,3 +1,3 @@
1
- import { responsive } from './responsive';
2
- // 响应式设计 rem 单位
3
- responsive();
1
+ import { responsive } from './responsive'; // 响应式设计 rem 单位
2
+
3
+ responsive();
@@ -1,20 +1,22 @@
1
- const htmlRoot = document.querySelector('html');
1
+ import "core-js/modules/es.parse-float.js";
2
+ var htmlRoot = document.querySelector('html');
2
3
  export function responsive() {
3
- function setRem() {
4
- let clientWidth = htmlRoot.clientWidth;
5
- // clientWidth = Math.min(clientWidth, 640); // PC 模式下限定最大值
6
- htmlRoot.style.fontSize = `${clientWidth / 7.5}px`;
7
- const div = document.createElement('div');
8
- div.style.width = '7.5rem';
9
- document.body.appendChild(div);
10
- htmlRoot.style.fontSize = `${(parseFloat(htmlRoot.style.fontSize) * clientWidth) / div.clientWidth}px`;
11
- document.body.removeChild(div);
12
- document.body.style.fontSize = `16px`;
13
- }
14
- let b = null;
15
- window.addEventListener('resize', function () {
16
- clearTimeout(b);
17
- b = setTimeout(setRem, 100);
18
- }, !1);
19
- setRem();
20
- }
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
+ }
@@ -1,24 +1,26 @@
1
+ import "core-js/modules/es.object.assign.js";
1
2
  import { Emitter } from '@ray-js/framework-shared';
2
- export const appStoreEmitter = new Emitter();
3
- export const renderOptions = {
4
- tabBarVisible: true,
5
- tabBarAnimation: false,
3
+ export var appStoreEmitter = new Emitter();
4
+ export var renderOptions = {
5
+ tabBarVisible: true,
6
+ tabBarAnimation: false
6
7
  };
7
- export const actions = {
8
- toggleTabBar: 'toggleTabBar',
9
- onChange: 'onChange',
8
+ export var actions = {
9
+ toggleTabBar: 'toggleTabBar',
10
+ onChange: 'onChange'
10
11
  };
11
- export const events = {
12
- tabBarChange: 'tabBarChange',
12
+ export var events = {
13
+ tabBarChange: 'tabBarChange'
13
14
  };
14
- const update = (eventName, nextState) => {
15
- Object.assign(renderOptions, nextState);
16
- appStoreEmitter.emit(eventName, renderOptions);
15
+
16
+ var update = function (eventName, nextState) {
17
+ Object.assign(renderOptions, nextState);
18
+ appStoreEmitter.emit(eventName, renderOptions);
17
19
  };
20
+
18
21
  appStoreEmitter.on(actions.toggleTabBar, function (next) {
19
- if (next.visible !== renderOptions.tabBarVisible)
20
- update(events.tabBarChange, {
21
- tabBarVisible: next.visible,
22
- tabBarAnimation: next.animation,
23
- });
24
- });
22
+ if (next.visible !== renderOptions.tabBarVisible) update(events.tabBarChange, {
23
+ tabBarVisible: next.visible,
24
+ tabBarAnimation: next.animation
25
+ });
26
+ });
@@ -1,2 +1,2 @@
1
1
  import get from 'lodash.get';
2
- export { get };
2
+ export { get };
@@ -1,11 +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";
1
4
  export function normalizeTabBar(tabBar, routes) {
2
- if (tabBar.list) {
3
- tabBar.list = tabBar.list.map((item) => {
4
- if (item.id) {
5
- item.route = routes.find((i) => i.id === item.id).route;
6
- }
7
- return item;
8
- });
9
- }
10
- return tabBar;
11
- }
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
+ }
@@ -1,3 +1,5 @@
1
+ import "core-js/modules/es.regexp.exec.js";
2
+ import "core-js/modules/es.string.replace.js";
1
3
  export function withPublicPath(basePath) {
2
- return PUBLIC_PATH + basePath.replace(/^\//, '');
3
- }
4
+ return PUBLIC_PATH + basePath.replace(/^\//, '');
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ray-js/framework",
3
- "version": "0.4.15-beta-0",
3
+ "version": "0.5.0",
4
4
  "description": "Ray Core",
5
5
  "keywords": [
6
6
  "ray"
@@ -20,21 +20,21 @@
20
20
  "watch": "tsc -p ./tsconfig.build.json --module esnext --outDir lib --watch"
21
21
  },
22
22
  "dependencies": {
23
- "@ray-js/framework-mp": "^0.4.15-beta-0",
24
- "@ray-js/framework-native": "^0.4.15-beta-0",
25
- "@ray-js/framework-shared": "^0.4.15-beta-0",
26
- "@ray-js/library": "^0.4.15-beta-0",
27
- "@ray-js/location": "^0.4.15-beta-0",
28
- "@ray-js/router": "^0.4.15-beta-0",
29
- "@ray-js/runtime": "^0.4.15-beta-0",
23
+ "@ray-js/framework-mp": "^0.5.0",
24
+ "@ray-js/framework-native": "^0.5.0",
25
+ "@ray-js/framework-shared": "^0.5.0",
26
+ "@ray-js/library": "^0.5.0",
27
+ "@ray-js/location": "^0.5.0",
28
+ "@ray-js/router": "^0.5.0",
29
+ "@ray-js/runtime": "^0.5.0",
30
30
  "clsx": "^1.1.1",
31
31
  "hoist-non-react-statics": "^3.3.2",
32
32
  "lodash.get": "^4.4.2",
33
33
  "tiny-invariant": "^1.1.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@ray-js/cli": "^0.4.15-beta-0",
37
- "@ray-js/types": "^0.4.15-beta-0"
36
+ "@ray-js/cli": "^0.5.0",
37
+ "@ray-js/types": "^0.5.0"
38
38
  },
39
39
  "maintainers": [
40
40
  {
@@ -42,6 +42,6 @@
42
42
  "email": "tuyafe@tuya.com"
43
43
  }
44
44
  ],
45
- "gitHead": "c9b5b2e847299ecbd30c8b1feb2413045c139bf7",
45
+ "gitHead": "5f49ac5a276532472d10aa60ec21c9a5f0b28ce8",
46
46
  "repository": {}
47
47
  }
@@ -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
- const root = document.createElement('div');
6
- root.id = 'root';
7
- document.body.appendChild(root);
8
- // 作为 web 构建的启动入口文件
9
- ReactDOM.render(<Application {...options}/>, root);
10
- }
@@ -1,12 +0,0 @@
1
- import { getCurrent } from '@ray-js/runtime';
2
- /**
3
- * 创建抽象的 App Instance 对标到小程序,提供给 getApp() 进行使用
4
- * @param appThis
5
- */
6
- export function createAppInstance(appThis) {
7
- const current = getCurrent();
8
- // App 实例仅且注册一次
9
- if (!current.app) {
10
- current.app = appThis;
11
- }
12
- }
package/lib/app/index.jsx DELETED
@@ -1,7 +0,0 @@
1
- import { getCurrent } from '@ray-js/runtime';
2
- export * from './createApp';
3
- export * from './createAppInstance';
4
- export function getApp() {
5
- const current = getCurrent();
6
- return current.app;
7
- }
@@ -1,29 +0,0 @@
1
- import React from 'react';
2
- import styles from './index.module.less';
3
- import { getApp } from '../../app';
4
- import location from '@ray-js/location';
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
- });
14
- }
15
- // 初次展现
16
- if (typeof app.onShow === 'function') {
17
- app.onShow({
18
- path: location.pathname,
19
- query: location.query,
20
- params: location.params,
21
- });
22
- }
23
- }
24
- render() {
25
- return (<div id='Application' className={styles.application}>
26
- {this.props.children}
27
- </div>);
28
- }
29
- }
@@ -1,58 +0,0 @@
1
- import '../../runtime';
2
- import React from 'react';
3
- import { createRouter } from '@ray-js/router';
4
- import { createAppInstance } from '../../app/createAppInstance';
5
- import { get } from '../../utils';
6
- import { normalizeTabBar } from '../../utils/normalizeTabBar';
7
- import { AppWrapper } from '../AppWrapper';
8
- import { PageWrapper } from '../PageWrapper';
9
- import { TabBar } from '../TabBar';
10
- const isClassComponent = (Component) => {
11
- return Component.prototype && typeof Component.prototype.render === 'function';
12
- };
13
- export class Application extends React.Component {
14
- constructor(props) {
15
- super(props);
16
- this.getGlobalConfig = (path, defaultValue) => {
17
- const { globalConfig = {} } = this.props;
18
- const value = get(globalConfig, path, defaultValue);
19
- return value;
20
- };
21
- this.state = {};
22
- const title = this.getGlobalConfig(['window', 'navigationBarTitleText'], 'Ray App');
23
- document.title = title;
24
- }
25
- componentDidMount() {
26
- const { routes, pages, tabBar, globalConfig } = this.props;
27
- const { basename } = globalConfig;
28
- document.body.style.backgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
29
- createRouter({
30
- basename,
31
- routes,
32
- pages,
33
- tabBar,
34
- onChange: (component, props) => {
35
- this.setState({ component, matchedPage: props.page });
36
- },
37
- });
38
- }
39
- render() {
40
- const { app: App, tabBar, routes, basename } = this.props;
41
- const { component: PageComponent, matchedPage } = this.state;
42
- // 空页面暂不渲染,否则 appEvent 无法应用到页面内部
43
- if (!matchedPage) {
44
- return null;
45
- }
46
- const isClassType = isClassComponent(PageComponent);
47
- return (<AppWrapper>
48
- <App ref={(appThis) => {
49
- createAppInstance(appThis);
50
- }}>
51
- <PageWrapper isClassType={isClassType} page={matchedPage} key={matchedPage.route} getGlobalConfig={this.getGlobalConfig}>
52
- <PageComponent />
53
- </PageWrapper>
54
- {matchedPage.isTabBar && (<TabBar basename={basename} config={normalizeTabBar(tabBar, routes)}/>)}
55
- </App>
56
- </AppWrapper>);
57
- }
58
- }
@@ -1,117 +0,0 @@
1
- import React from 'react';
2
- // import { normalizeTabBar } from '../../utils/normalizeTabBar';
3
- import { lifecycle, PageInstance, PageInstanceContext } from '@ray-js/runtime';
4
- import { pageLifecycles } from '@ray-js/types';
5
- import { get } from '../../utils';
6
- import './index.module.less';
7
- export class PageWrapper extends React.Component {
8
- constructor(props) {
9
- super(props);
10
- this.$reachBottomDistance = 50;
11
- this.handlePageResize = () => {
12
- const windowWidth = document.documentElement.clientWidth;
13
- const windowHeight = document.documentElement.clientHeight;
14
- lifecycle.emit({
15
- uniqueId: this.$instance.uniqueId,
16
- name: pageLifecycles.onResize,
17
- args: { windowWidth, windowHeight },
18
- });
19
- };
20
- this.handlePageScroll = () => {
21
- const event = { scrollTop: window.scrollY };
22
- lifecycle.emit({
23
- uniqueId: this.$instance.uniqueId,
24
- name: pageLifecycles.onPageScroll,
25
- args: event,
26
- });
27
- this.checkReachBottom();
28
- };
29
- this.checkReachBottom = () => {
30
- const isCurrentReachBottom = document.body.scrollHeight - (window.innerHeight + window.scrollY) <=
31
- this.$reachBottomDistance;
32
- if (!this.$isReachBottom && isCurrentReachBottom) {
33
- this.$isReachBottom = true;
34
- lifecycle.emit({
35
- uniqueId: this.$instance.uniqueId,
36
- name: pageLifecycles.onReachBottom,
37
- });
38
- return;
39
- }
40
- this.$isReachBottom = isCurrentReachBottom;
41
- };
42
- this.getPageConfig = (field, defaultValue) => {
43
- const { page } = this.props;
44
- const pageConfig = page.config;
45
- return get(pageConfig, field, defaultValue);
46
- };
47
- this.$instance = new PageInstance();
48
- lifecycle.addInstance(this.$instance);
49
- this.getGlobalConfig = this.props.getGlobalConfig;
50
- }
51
- componentDidMount() {
52
- const title = this.getPageConfig('navigationBarTitleText', '');
53
- document.title = title;
54
- window.addEventListener('scroll', this.handlePageScroll);
55
- window.addEventListener('resize', this.handlePageResize);
56
- const backgroundColor = this.getPageConfig('backgroundColor');
57
- if (backgroundColor) {
58
- document.body.style.backgroundColor = backgroundColor;
59
- }
60
- // 获取页面触底的距离
61
- this.$reachBottomDistance = this.getPageConfig('onReachBottomDistance', this.getGlobalConfig(['window', 'onReachBottomDistance'], 50) // 全局配置
62
- );
63
- // FIXME: 应用实例化未完成,didMount 从内至外执行
64
- // 此时触发 onShow onReady 获取不到 getApp 实例,组件内也存在这样的情况
65
- lifecycle.emit({
66
- uniqueId: this.$instance.uniqueId,
67
- name: pageLifecycles.onShow,
68
- });
69
- lifecycle.emit({
70
- uniqueId: this.$instance.uniqueId,
71
- name: pageLifecycles.onReady,
72
- });
73
- }
74
- componentWillUnmount() {
75
- window.removeEventListener('scroll', this.handlePageScroll);
76
- window.removeEventListener('resize', this.handlePageResize);
77
- // FIXME: 目前是 SPA 的页面直接切换,卸载前直接调用事件
78
- lifecycle.emit({
79
- uniqueId: this.$instance.uniqueId,
80
- name: pageLifecycles.onHide,
81
- });
82
- lifecycle.emit({
83
- uniqueId: this.$instance.uniqueId,
84
- name: pageLifecycles.onUnload,
85
- });
86
- lifecycle.removeInstance(this.$instance);
87
- // TODO: 实现 onPullDownRefresh 生命周期
88
- }
89
- render() {
90
- const { page, children, isClassType } = this.props;
91
- const $instance = this.$instance;
92
- const globalBackgroundColor = this.getGlobalConfig(['window', 'backgroundColor'], '#fff');
93
- const backgroundColor = this.getPageConfig('backgroundColor', globalBackgroundColor);
94
- document.body.style.backgroundColor = backgroundColor;
95
- return (<PageInstanceContext.Provider value={{ $instance, pageConfig: page.config }}>
96
- <v-page data-route={page.route}>
97
- {isClassType
98
- ? // @ts-ignore
99
- React.cloneElement(children, {
100
- ref(ins) {
101
- if (ins) {
102
- // 实现 class 生命周期用法的挂载
103
- Object.keys(pageLifecycles).forEach((event) => {
104
- if (typeof ins[event] === 'function') {
105
- $instance.registerLifecycle(event, ins, ins[event]);
106
- }
107
- });
108
- }
109
- },
110
- })
111
- : children}
112
- {/* TODO: 如果需要转场动画,需要在 PageWrapper 中渲染 */}
113
- {/* {page?.isTabBar && <TabBar config={tabBarConfig} />} */}
114
- </v-page>
115
- </PageInstanceContext.Provider>);
116
- }
117
- }
@@ -1,54 +0,0 @@
1
- import clsx from 'clsx';
2
- import React from 'react';
3
- import router from '@ray-js/router';
4
- import { events, appStoreEmitter, renderOptions } from '../../store/appStore';
5
- import { withPublicPath } from '../../utils/withPublicPath';
6
- import styles from './index.module.less';
7
- export class TabBar extends React.Component {
8
- constructor() {
9
- super(...arguments);
10
- this.state = {
11
- currentRoute: router.scheduler.currentRoute,
12
- renderOptions: renderOptions,
13
- };
14
- }
15
- componentDidMount() {
16
- this.unChangeHandle = router.scheduler.on('routeChange', (route) => {
17
- this.setState({
18
- currentRoute: route,
19
- });
20
- });
21
- this.unAppStoreChange = appStoreEmitter.on(events.tabBarChange, (state) => {
22
- this.setState({ renderOptions: state });
23
- });
24
- }
25
- componentWillUnmount() {
26
- var _a, _b;
27
- (_a = this.unChangeHandle) === null || _a === void 0 ? void 0 : _a.call(this);
28
- (_b = this.unAppStoreChange) === null || _b === void 0 ? void 0 : _b.call(this);
29
- }
30
- render() {
31
- const { config, basename = '' } = this.props;
32
- const { currentRoute, renderOptions } = this.state;
33
- return (<div data-route={currentRoute} className={clsx(styles.wrapper, {
34
- [styles.hidden]: !renderOptions.tabBarVisible && !renderOptions.tabBarAnimation,
35
- [styles.showIn]: renderOptions.tabBarVisible && renderOptions.tabBarAnimation,
36
- [styles.hideOut]: !renderOptions.tabBarVisible && renderOptions.tabBarAnimation,
37
- })}>
38
- <div className={styles.tabBar}>
39
- {config.list.map((item) => {
40
- const fullRoute = basename + item.route;
41
- const isActive = currentRoute === fullRoute;
42
- return (<div data-full-route={fullRoute} key={item.route || item.id} className={styles.item} onClick={() => {
43
- router.push(item.route);
44
- }}>
45
- {item.icon && (<img className={styles.icon} src={`${withPublicPath(isActive ? item.activeIcon : item.icon)}`}/>)}
46
- <span className={styles.text} style={{ color: isActive ? config.selectedColor : config.textColor }}>
47
- {item.text}
48
- </span>
49
- </div>);
50
- })}
51
- </div>
52
- </div>);
53
- }
54
- }
package/lib/createApp.jsx 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
- const root = document.createElement('div');
6
- root.id = 'root';
7
- document.body.appendChild(root);
8
- // 作为 web 构建的启动入口文件
9
- ReactDOM.render(<Application {...options}/>, root);
10
- }