@rsmax/web 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE +22 -0
  3. package/README.md +11 -0
  4. package/assets/app.css +154 -0
  5. package/assets/normalize.css +450 -0
  6. package/cjs/LoadingIcon.d.ts +6 -0
  7. package/cjs/LoadingIcon.js +39 -0
  8. package/cjs/PullToRefresh.d.ts +3 -0
  9. package/cjs/PullToRefresh.js +42 -0
  10. package/cjs/TabBar.d.ts +7 -0
  11. package/cjs/TabBar.js +57 -0
  12. package/cjs/api.d.ts +16 -0
  13. package/cjs/api.js +30 -0
  14. package/cjs/bootstrap.d.ts +2 -0
  15. package/cjs/bootstrap.js +18 -0
  16. package/cjs/bootstrapMpa.d.ts +1 -0
  17. package/cjs/bootstrapMpa.js +80 -0
  18. package/cjs/createApp.d.ts +4 -0
  19. package/cjs/createApp.js +72 -0
  20. package/cjs/createAppConfig.d.ts +54 -0
  21. package/cjs/createAppConfig.js +89 -0
  22. package/cjs/createPageConfig.d.ts +49 -0
  23. package/cjs/createPageConfig.js +162 -0
  24. package/cjs/hooks/useNativeEffect.d.ts +2 -0
  25. package/cjs/hooks/useNativeEffect.js +4 -0
  26. package/cjs/hooks/usePageInstance.d.ts +1 -0
  27. package/cjs/hooks/usePageInstance.js +6 -0
  28. package/cjs/hooks/useQuery.d.ts +3 -0
  29. package/cjs/hooks/useQuery.js +13 -0
  30. package/cjs/index.d.ts +10 -0
  31. package/cjs/index.js +39 -0
  32. package/cjs/types/index.d.ts +89 -0
  33. package/cjs/types/index.js +2 -0
  34. package/esm/LoadingIcon.d.ts +6 -0
  35. package/esm/LoadingIcon.js +13 -0
  36. package/esm/PullToRefresh.d.ts +3 -0
  37. package/esm/PullToRefresh.js +14 -0
  38. package/esm/TabBar.d.ts +7 -0
  39. package/esm/TabBar.js +30 -0
  40. package/esm/api.d.ts +16 -0
  41. package/esm/api.js +22 -0
  42. package/esm/bootstrap.d.ts +2 -0
  43. package/esm/bootstrap.js +12 -0
  44. package/esm/bootstrapMpa.d.ts +1 -0
  45. package/esm/bootstrapMpa.js +51 -0
  46. package/esm/createApp.d.ts +4 -0
  47. package/esm/createApp.js +43 -0
  48. package/esm/createAppConfig.d.ts +54 -0
  49. package/esm/createAppConfig.js +63 -0
  50. package/esm/createPageConfig.d.ts +49 -0
  51. package/esm/createPageConfig.js +133 -0
  52. package/esm/hooks/useNativeEffect.d.ts +2 -0
  53. package/esm/hooks/useNativeEffect.js +2 -0
  54. package/esm/hooks/usePageInstance.d.ts +1 -0
  55. package/esm/hooks/usePageInstance.js +3 -0
  56. package/esm/hooks/useQuery.d.ts +3 -0
  57. package/esm/hooks/useQuery.js +7 -0
  58. package/esm/index.d.ts +10 -0
  59. package/esm/index.js +10 -0
  60. package/esm/types/index.d.ts +89 -0
  61. package/esm/types/index.js +1 -0
  62. package/package.json +52 -0
  63. package/typings/index.d.ts +1 -0
  64. package/vitest.config.js +9 -0
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const React = __importStar(require("react"));
30
+ const rmc_pull_to_refresh_1 = __importDefault(require("rmc-pull-to-refresh"));
31
+ const LoadingIcon_1 = __importDefault(require("./LoadingIcon"));
32
+ const RemaxPullToRefresh = props => {
33
+ return (React.createElement(rmc_pull_to_refresh_1.default, Object.assign({}, props, { getScrollContainer: () => {
34
+ document.body;
35
+ }, indicator: {
36
+ activate: React.createElement(LoadingIcon_1.default, null),
37
+ deactivate: React.createElement(LoadingIcon_1.default, null),
38
+ release: React.createElement(LoadingIcon_1.default, { animate: true }),
39
+ finish: React.createElement(LoadingIcon_1.default, null),
40
+ } })));
41
+ };
42
+ exports.default = RemaxPullToRefresh;
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { History } from 'history';
3
+ import { TabBarConfig } from './types';
4
+ export declare function TabBar({ config, history }: {
5
+ config: TabBarConfig;
6
+ history: History;
7
+ }): React.JSX.Element;
package/cjs/TabBar.js ADDED
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.TabBar = void 0;
27
+ const React = __importStar(require("react"));
28
+ const react_router_dom_1 = require("react-router-dom");
29
+ function TabBar({ config, history }) {
30
+ var _a;
31
+ const [currentPath, setCurrentPath] = React.useState(history.location.pathname);
32
+ React.useEffect(() => {
33
+ setCurrentPath(history.location.pathname);
34
+ return history.listen(() => {
35
+ setCurrentPath(history.location.pathname);
36
+ });
37
+ }, []);
38
+ const isActive = (url) => {
39
+ if (!url.startsWith('/')) {
40
+ url = '/' + url;
41
+ }
42
+ return currentPath === url;
43
+ };
44
+ return (React.createElement("div", { className: "remax-tab-bar", style: { backgroundColor: (_a = config.backgroundColor) !== null && _a !== void 0 ? _a : '' } }, config.items.map((item, index) => (React.createElement(TabBarItem, { key: index, config: config, isActive: isActive(item.url), item: item })))));
45
+ }
46
+ exports.TabBar = TabBar;
47
+ function TabBarItem({ config, isActive, item }) {
48
+ var _a, _b;
49
+ const icon = isActive ? item.activeImage || item.image : item.image;
50
+ const textColor = (_a = config.textColor) !== null && _a !== void 0 ? _a : '#333';
51
+ const selectedColor = (_b = config.selectedColor) !== null && _b !== void 0 ? _b : '#108ee9';
52
+ return (React.createElement(react_router_dom_1.Link, { to: `/${item.url}`, className: "remax-tab-item" },
53
+ React.createElement("div", { className: "remax-tab-item-image", style: { backgroundImage: `url(${icon})` } }),
54
+ React.createElement("div", { className: "remax-tab-item-title", style: {
55
+ color: isActive ? selectedColor : textColor,
56
+ } }, item.title)));
57
+ }
package/cjs/api.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ interface NavigateToParams {
2
+ url: string;
3
+ }
4
+ interface NavigateBackParams {
5
+ /** 返回的页面数 */
6
+ delta?: number;
7
+ }
8
+ type RedirectToParams = NavigateToParams;
9
+ type ReLaunchParams = NavigateToParams;
10
+ type SwitchTabParams = NavigateToParams;
11
+ export declare function navigateTo(params: NavigateToParams): Promise<void>;
12
+ export declare function navigateBack(params?: NavigateBackParams): Promise<void>;
13
+ export declare function redirectTo(params: RedirectToParams): Promise<void>;
14
+ export declare function reLaunch(params: ReLaunchParams): void;
15
+ export declare function switchTab(params: SwitchTabParams): void;
16
+ export {};
package/cjs/api.js ADDED
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.switchTab = exports.reLaunch = exports.redirectTo = exports.navigateBack = exports.navigateTo = void 0;
4
+ const framework_shared_1 = require("@rsmax/framework-shared");
5
+ function navigateTo(params) {
6
+ const history = framework_shared_1.RuntimeOptions.get('history');
7
+ history.push(params.url);
8
+ return Promise.resolve();
9
+ }
10
+ exports.navigateTo = navigateTo;
11
+ function navigateBack(params) {
12
+ const history = framework_shared_1.RuntimeOptions.get('history');
13
+ history.go(-((params === null || params === void 0 ? void 0 : params.delta) || 1));
14
+ return Promise.resolve();
15
+ }
16
+ exports.navigateBack = navigateBack;
17
+ function redirectTo(params) {
18
+ const history = framework_shared_1.RuntimeOptions.get('history');
19
+ history.replace(params.url);
20
+ return Promise.resolve();
21
+ }
22
+ exports.redirectTo = redirectTo;
23
+ function reLaunch(params) {
24
+ window.location.href = params.url;
25
+ }
26
+ exports.reLaunch = reLaunch;
27
+ function switchTab(params) {
28
+ navigateTo(params);
29
+ }
30
+ exports.switchTab = switchTab;
@@ -0,0 +1,2 @@
1
+ import { BootstrapOptions } from './types';
2
+ export default function bootstrap(options: BootstrapOptions): void;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const react_dom_1 = require("react-dom");
7
+ const umi_hd_1 = __importDefault(require("umi-hd"));
8
+ const history_1 = require("history");
9
+ const framework_shared_1 = require("@rsmax/framework-shared");
10
+ const createApp_1 = __importDefault(require("./createApp"));
11
+ function bootstrap(options) {
12
+ (0, umi_hd_1.default)();
13
+ const { appConfig } = options;
14
+ const history = !appConfig.router || appConfig.router.type !== 'browser' ? (0, history_1.createHashHistory)() : (0, history_1.createBrowserHistory)();
15
+ framework_shared_1.RuntimeOptions.apply({ history, mpa: false });
16
+ (0, react_dom_1.render)((0, createApp_1.default)(options, history), document.getElementById('remax-app'));
17
+ }
18
+ exports.default = bootstrap;
@@ -0,0 +1 @@
1
+ export default function bootstrap(options: any): void;
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const React = __importStar(require("react"));
30
+ const react_dom_1 = require("react-dom");
31
+ const umi_hd_1 = __importDefault(require("umi-hd"));
32
+ const createAppConfig_1 = __importDefault(require("./createAppConfig"));
33
+ const framework_shared_1 = require("@rsmax/framework-shared");
34
+ const createPageConfig_1 = __importDefault(require("./createPageConfig"));
35
+ const noop = () => {
36
+ // ignore
37
+ };
38
+ function createApp(options) {
39
+ const { appComponent, pageComponent, page, appConfig } = options;
40
+ const AppConfig = (0, createAppConfig_1.default)(appComponent);
41
+ const PageConfig = (0, createPageConfig_1.default)(pageComponent, page.route);
42
+ return (React.createElement(AppConfig, null,
43
+ React.createElement(PageConfig, { pageConfig: Object.assign(Object.assign({}, appConfig.window), page.config), tabBar: appConfig.tabBar, location: window.location, cacheLifecycles: {
44
+ didCache: noop,
45
+ didRecover: noop,
46
+ } })));
47
+ }
48
+ function bootstrap(options) {
49
+ (0, umi_hd_1.default)();
50
+ const { plugins = [], page } = options;
51
+ const pluginDriver = new framework_shared_1.PluginDriver(plugins.map((plugin) => plugin.default || plugin));
52
+ const history = {
53
+ push(url) {
54
+ url = history.transformUrl(url);
55
+ console.log('not implemented');
56
+ },
57
+ go() {
58
+ console.log('not implemented');
59
+ },
60
+ replace(url) {
61
+ url = history.transformUrl(url);
62
+ location.replace(url);
63
+ },
64
+ page: null,
65
+ transformUrl(url) {
66
+ if (!url)
67
+ return url;
68
+ let publicPath = '';
69
+ if (url.startsWith('/'))
70
+ publicPath = location.pathname.replace(`/${page.route}.html`, '');
71
+ const arr = url.split('?');
72
+ arr[0] = arr[0] + '.html';
73
+ return publicPath + arr.join('?');
74
+ },
75
+ };
76
+ framework_shared_1.RuntimeOptions.apply({ pluginDriver, history, mpa: true });
77
+ const App = createApp(options);
78
+ (0, react_dom_1.render)(App, document.getElementById('remax-app'));
79
+ }
80
+ exports.default = bootstrap;
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { History } from 'history';
3
+ import { BootstrapOptions } from './types';
4
+ export default function createApp(options: BootstrapOptions, history: History): React.JSX.Element;
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ const React = __importStar(require("react"));
30
+ const framework_shared_1 = require("@rsmax/framework-shared");
31
+ const react_router_cache_route_1 = require("@remax/react-router-cache-route");
32
+ const react_router_dom_1 = require("react-router-dom");
33
+ const component_1 = __importDefault(require("@loadable/component"));
34
+ const createAppConfig_1 = __importDefault(require("./createAppConfig"));
35
+ const createPageConfig_1 = __importDefault(require("./createPageConfig"));
36
+ const TabBar_1 = require("./TabBar");
37
+ function createApp(options, history) {
38
+ var _a, _b, _c;
39
+ const { async = true, appComponent, appConfig, pageComponents, pages, plugins = [] } = options;
40
+ const AppConfig = (0, createAppConfig_1.default)(appComponent);
41
+ const pluginDriver = new framework_shared_1.PluginDriver(plugins.map(plugin => plugin.default || plugin));
42
+ framework_shared_1.RuntimeOptions.apply({ pluginDriver });
43
+ const pageComponentsHoc = pages.map((page, i) => {
44
+ const pageComponent = async
45
+ ? (0, component_1.default)(() => pageComponents[i]().then(({ default: c }) => (0, createPageConfig_1.default)(c, page.route)))
46
+ : (0, createPageConfig_1.default)(pageComponents[i](), page.route);
47
+ return pageComponent;
48
+ });
49
+ return (React.createElement(react_router_dom_1.Router, { history: history },
50
+ React.createElement(AppConfig, null,
51
+ React.createElement(react_router_cache_route_1.CacheSwitch, null,
52
+ React.createElement(react_router_dom_1.Route, { exact: true, path: "/" },
53
+ React.createElement(react_router_dom_1.Redirect, { to: `/${(_a = pages[0]) === null || _a === void 0 ? void 0 : _a.route}` })),
54
+ pages.map((page, i) => {
55
+ return (React.createElement(react_router_cache_route_1.CacheRoute, { key: page.route, className: "remax-cached-router-wrapper", path: `/${page.route}`, exact: true }, (props) => {
56
+ const pageComponent = pageComponentsHoc[i];
57
+ return React.createElement(pageComponent, Object.assign(Object.assign({}, props), { pageConfig: Object.assign(Object.assign({}, appConfig.window), page.config), tabBar: appConfig.tabBar }));
58
+ }));
59
+ }),
60
+ React.createElement(react_router_dom_1.Route, null,
61
+ React.createElement(react_router_dom_1.Redirect, { to: `/${(_b = pages[0]) === null || _b === void 0 ? void 0 : _b.route}` }))),
62
+ ((_c = appConfig.tabBar) === null || _c === void 0 ? void 0 : _c.items) && appConfig.tabBar.items.length > 0 && (React.createElement(TabBar_1.TabBar, { history: history, config: appConfig.tabBar })),
63
+ process.env.NODE_ENV === 'development' && React.createElement(LogLocation, null))));
64
+ }
65
+ exports.default = createApp;
66
+ function LogLocation() {
67
+ const location = (0, react_router_dom_1.useLocation)();
68
+ React.useEffect(() => {
69
+ console.log('[remax][react-router]location change', location.pathname);
70
+ }, [location]);
71
+ return null;
72
+ }
@@ -0,0 +1,54 @@
1
+ import * as React from 'react';
2
+ export default function createAppConfig(this: any, App: any): {
3
+ new (props: any): {
4
+ componentDidMount(): void;
5
+ componentWillUnmount(): void;
6
+ visibilityChangeEvent: () => void;
7
+ handelVisibilityChange: () => void;
8
+ render(): React.JSX.Element;
9
+ context: unknown;
10
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<any>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
11
+ forceUpdate(callback?: (() => void) | undefined): void;
12
+ readonly props: Readonly<any>;
13
+ state: Readonly<{}>;
14
+ refs: {
15
+ [key: string]: React.ReactInstance;
16
+ };
17
+ shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): boolean;
18
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
19
+ getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>): any;
20
+ componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>, snapshot?: any): void;
21
+ componentWillMount?(): void;
22
+ UNSAFE_componentWillMount?(): void;
23
+ componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
24
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
25
+ componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
26
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
27
+ };
28
+ new (props: any, context: any): {
29
+ componentDidMount(): void;
30
+ componentWillUnmount(): void;
31
+ visibilityChangeEvent: () => void;
32
+ handelVisibilityChange: () => void;
33
+ render(): React.JSX.Element;
34
+ context: unknown;
35
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<any>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
36
+ forceUpdate(callback?: (() => void) | undefined): void;
37
+ readonly props: Readonly<any>;
38
+ state: Readonly<{}>;
39
+ refs: {
40
+ [key: string]: React.ReactInstance;
41
+ };
42
+ shouldComponentUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): boolean;
43
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
44
+ getSnapshotBeforeUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>): any;
45
+ componentDidUpdate?(prevProps: Readonly<any>, prevState: Readonly<{}>, snapshot?: any): void;
46
+ componentWillMount?(): void;
47
+ UNSAFE_componentWillMount?(): void;
48
+ componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
49
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<any>, nextContext: any): void;
50
+ componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
51
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<any>, nextState: Readonly<{}>, nextContext: any): void;
52
+ };
53
+ contextType?: React.Context<any> | undefined;
54
+ };
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const React = __importStar(require("react"));
27
+ const react_is_1 = require("react-is");
28
+ const framework_shared_1 = require("@rsmax/framework-shared");
29
+ class DefaultAppComponent extends React.Component {
30
+ render() {
31
+ return React.createElement(React.Fragment, this.props);
32
+ }
33
+ }
34
+ function createAppConfig(App) {
35
+ const createConfig = (AppComponent = DefaultAppComponent) => {
36
+ const config = {
37
+ _instance: React.createRef(),
38
+ callLifecycle(lifecycle, ...args) {
39
+ const callbacks = framework_shared_1.AppInstanceContext.lifecycleCallback[lifecycle] || [];
40
+ let result;
41
+ callbacks.forEach((callback) => {
42
+ result = callback(...args);
43
+ });
44
+ if (result) {
45
+ return result;
46
+ }
47
+ const callback = (0, framework_shared_1.callbackName)(lifecycle);
48
+ if (this._instance.current && this._instance.current[callback]) {
49
+ return this._instance.current[callback](...args);
50
+ }
51
+ },
52
+ };
53
+ return class AppConfig extends React.Component {
54
+ constructor() {
55
+ super(...arguments);
56
+ this.visibilityChangeEvent = () => {
57
+ if (document.visibilityState === 'visible') {
58
+ config.callLifecycle(framework_shared_1.AppLifecycle.show);
59
+ }
60
+ else {
61
+ config.callLifecycle(framework_shared_1.AppLifecycle.hide);
62
+ }
63
+ };
64
+ this.handelVisibilityChange = () => {
65
+ document.addEventListener('visibilitychange', this.visibilityChangeEvent);
66
+ };
67
+ }
68
+ componentDidMount() {
69
+ window.onerror = (...params) => {
70
+ config.callLifecycle(framework_shared_1.AppLifecycle.error, ...params);
71
+ };
72
+ config.callLifecycle(framework_shared_1.AppLifecycle.launch);
73
+ this.handelVisibilityChange();
74
+ }
75
+ componentWillUnmount() {
76
+ document.removeEventListener('visibilitychange', this.visibilityChangeEvent);
77
+ }
78
+ render() {
79
+ let ref;
80
+ if ((0, framework_shared_1.isClassComponent)(AppComponent) || AppComponent.$$typeof === react_is_1.ForwardRef) {
81
+ ref = config._instance;
82
+ }
83
+ return React.createElement(AppComponent, Object.assign({}, this.props, { ref: ref }));
84
+ }
85
+ };
86
+ };
87
+ return createConfig(App);
88
+ }
89
+ exports.default = createAppConfig;
@@ -0,0 +1,49 @@
1
+ import * as React from 'react';
2
+ import { TabBarConfig, PageConfig } from './types';
3
+ interface PageConfigProps {
4
+ tabBar: TabBarConfig;
5
+ pageConfig: PageConfig;
6
+ location: any;
7
+ cacheLifecycles?: any;
8
+ }
9
+ export default function createPageConfig(Page: React.ComponentType<any>, name: string): {
10
+ new (props: any): {
11
+ state: {
12
+ refreshing: boolean;
13
+ };
14
+ title: string;
15
+ componentDidMount(): void;
16
+ componentWillUnmount(): void;
17
+ componentDidCache: () => void;
18
+ componentDidRecover: () => void;
19
+ setTitle: () => void;
20
+ isPullDownRefreshEnabled: () => boolean | undefined;
21
+ getReachBottomDistance: () => number;
22
+ isReachBottom: boolean;
23
+ scrollEvent: () => void;
24
+ registerPageScroll: () => void;
25
+ unregisterPageScroll: () => void;
26
+ handleRefresh: () => Promise<void>;
27
+ checkReachBottom: () => void;
28
+ render(): React.JSX.Element;
29
+ context: unknown;
30
+ setState<K extends never>(state: {} | ((prevState: Readonly<{}>, props: Readonly<PageConfigProps>) => {} | Pick<{}, K> | null) | Pick<{}, K> | null, callback?: (() => void) | undefined): void;
31
+ forceUpdate(callback?: (() => void) | undefined): void;
32
+ readonly props: Readonly<PageConfigProps>;
33
+ refs: {
34
+ [key: string]: React.ReactInstance;
35
+ };
36
+ shouldComponentUpdate?(nextProps: Readonly<PageConfigProps>, nextState: Readonly<{}>, nextContext: any): boolean;
37
+ componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
38
+ getSnapshotBeforeUpdate?(prevProps: Readonly<PageConfigProps>, prevState: Readonly<{}>): any;
39
+ componentDidUpdate?(prevProps: Readonly<PageConfigProps>, prevState: Readonly<{}>, snapshot?: any): void;
40
+ componentWillMount?(): void;
41
+ UNSAFE_componentWillMount?(): void;
42
+ componentWillReceiveProps?(nextProps: Readonly<PageConfigProps>, nextContext: any): void;
43
+ UNSAFE_componentWillReceiveProps?(nextProps: Readonly<PageConfigProps>, nextContext: any): void;
44
+ componentWillUpdate?(nextProps: Readonly<PageConfigProps>, nextState: Readonly<{}>, nextContext: any): void;
45
+ UNSAFE_componentWillUpdate?(nextProps: Readonly<PageConfigProps>, nextState: Readonly<{}>, nextContext: any): void;
46
+ };
47
+ contextType?: React.Context<any> | undefined;
48
+ };
49
+ export {};