@rsmax/web 1.3.12 → 1.3.13

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/cjs/createApp.js CHANGED
@@ -3,41 +3,59 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
6
+ const component_1 = __importDefault(require("@loadable/component"));
7
7
  const framework_shared_1 = require("@rsmax/framework-shared");
8
- const react_router_cache_route_1 = require("@remax/react-router-cache-route");
8
+ const react_1 = __importDefault(require("react"));
9
9
  const react_router_dom_1 = require("react-router-dom");
10
- const component_1 = __importDefault(require("@loadable/component"));
10
+ const KeepAlive_1 = require("./KeepAlive");
11
+ const TabBar_1 = require("./TabBar");
11
12
  const createAppConfig_1 = __importDefault(require("./createAppConfig"));
12
13
  const createPageConfig_1 = __importDefault(require("./createPageConfig"));
13
- const TabBar_1 = require("./TabBar");
14
- function createApp(options, history) {
15
- var _a, _b, _c;
14
+ function createApp(options) {
15
+ var _a;
16
16
  const { async = true, appComponent, appConfig, pageComponents, pages, plugins = [] } = options;
17
17
  const AppConfig = (0, createAppConfig_1.default)(appComponent);
18
18
  const pluginDriver = new framework_shared_1.PluginDriver(plugins.map(plugin => plugin.default || plugin));
19
- framework_shared_1.RuntimeOptions.apply({ pluginDriver });
20
19
  const pageComponentsHoc = pages.map((page, i) => {
21
- const pageComponent = async
20
+ return async
22
21
  ? (0, component_1.default)(() => pageComponents[i]().then(({ default: c }) => (0, createPageConfig_1.default)(c, page.route)))
23
22
  : (0, createPageConfig_1.default)(pageComponents[i](), page.route);
24
- return pageComponent;
25
23
  });
26
- return (react_1.default.createElement(react_router_dom_1.Router, { history: history },
27
- react_1.default.createElement(AppConfig, null,
28
- react_1.default.createElement(react_router_cache_route_1.CacheSwitch, null,
29
- react_1.default.createElement(react_router_dom_1.Route, { exact: true, path: "/" },
30
- react_1.default.createElement(react_router_dom_1.Redirect, { to: `/${(_a = pages[0]) === null || _a === void 0 ? void 0 : _a.route}` })),
31
- pages.map((page, i) => {
32
- return (react_1.default.createElement(react_router_cache_route_1.CacheRoute, { key: page.route, className: "rsmax-cached-router-wrapper", path: `/${page.route}`, exact: true }, (props) => {
33
- const pageComponent = pageComponentsHoc[i];
34
- return react_1.default.createElement(pageComponent, Object.assign(Object.assign({}, props), { pageConfig: Object.assign(Object.assign({}, appConfig.window), page.config), tabBar: appConfig.tabBar }));
35
- }));
36
- }),
37
- react_1.default.createElement(react_router_dom_1.Route, null,
38
- react_1.default.createElement(react_router_dom_1.Redirect, { to: `/${(_b = pages[0]) === null || _b === void 0 ? void 0 : _b.route}` }))),
39
- ((_c = appConfig.tabBar) === null || _c === void 0 ? void 0 : _c.items) && appConfig.tabBar.items.length > 0 && (react_1.default.createElement(TabBar_1.TabBar, { history: history, config: appConfig.tabBar })),
40
- process.env.NODE_ENV === 'development' && react_1.default.createElement(LogLocation, null))));
24
+ const AppConfigElement = () => {
25
+ var _a, _b, _c;
26
+ const navigate = (0, react_router_dom_1.useNavigate)();
27
+ react_1.default.useEffect(() => {
28
+ framework_shared_1.RuntimeOptions.apply({ pluginDriver, navigate, mpa: false });
29
+ }, [navigate]);
30
+ return (react_1.default.createElement(AppConfig, null,
31
+ react_1.default.createElement(KeepAlive_1.KeepAliveProvider, null,
32
+ react_1.default.createElement(react_router_dom_1.Routes, null,
33
+ react_1.default.createElement(react_router_dom_1.Route, { path: "/", element: react_1.default.createElement(react_router_dom_1.Navigate, { to: `/${(_a = pages[0]) === null || _a === void 0 ? void 0 : _a.route}`, replace: true }) }),
34
+ pages.map((page, i) => {
35
+ // 合并页面配置
36
+ const pageConfig = Object.assign(Object.assign({}, appConfig.window), page.config);
37
+ // 默认所有页面都开启keepAlive
38
+ const pageElement = react_1.default.createElement(pageComponentsHoc[i], {
39
+ pageConfig,
40
+ tabBar: appConfig.tabBar,
41
+ });
42
+ return (react_1.default.createElement(react_router_dom_1.Route, { key: page.route, path: `/${page.route}`, element: react_1.default.createElement(KeepAlive_1.KeepAlive, { cacheKey: `/${page.route}` }, pageElement) }));
43
+ }),
44
+ react_1.default.createElement(react_router_dom_1.Route, { path: "*", element:
45
+ /*找不到路由时重定向到首页*/
46
+ react_1.default.createElement(react_router_dom_1.Navigate, { to: `/${(_b = pages[0]) === null || _b === void 0 ? void 0 : _b.route}`, replace: true }) })),
47
+ ((_c = appConfig.tabBar) === null || _c === void 0 ? void 0 : _c.items) && appConfig.tabBar.items.length > 0 && react_1.default.createElement(TabBar_1.TabBar, { config: appConfig.tabBar }),
48
+ process.env.NODE_ENV === 'development' && react_1.default.createElement(LogLocation, null))));
49
+ };
50
+ if (((_a = options.appConfig.router) === null || _a === void 0 ? void 0 : _a.type) === 'browser') {
51
+ return (react_1.default.createElement(react_router_dom_1.BrowserRouter, null,
52
+ react_1.default.createElement(AppConfigElement, null)));
53
+ }
54
+ return (react_1.default.createElement(react_router_dom_1.HashRouter, { future: {
55
+ v7_startTransition: true,
56
+ v7_relativeSplatPath: true,
57
+ } },
58
+ react_1.default.createElement(AppConfigElement, null)));
41
59
  }
42
60
  exports.default = createApp;
43
61
  function LogLocation() {
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ const framework_shared_1 = require("@rsmax/framework-shared");
6
7
  const react_1 = __importDefault(require("react"));
7
8
  const react_is_1 = require("react-is");
8
- const framework_shared_1 = require("@rsmax/framework-shared");
9
9
  class DefaultAppComponent extends react_1.default.Component {
10
10
  render() {
11
11
  return react_1.default.createElement(react_1.default.Fragment, this.props);
@@ -16,6 +16,7 @@ function createAppConfig(App) {
16
16
  const config = {
17
17
  _instance: react_1.default.createRef(),
18
18
  callLifecycle(lifecycle, ...args) {
19
+ var _a;
19
20
  const callbacks = framework_shared_1.AppInstanceContext.lifecycleCallback[lifecycle] || [];
20
21
  let result;
21
22
  callbacks.forEach((callback) => {
@@ -25,7 +26,7 @@ function createAppConfig(App) {
25
26
  return result;
26
27
  }
27
28
  const callback = (0, framework_shared_1.callbackName)(lifecycle);
28
- if (this._instance.current && this._instance.current[callback]) {
29
+ if ((_a = this._instance.current) === null || _a === void 0 ? void 0 : _a[callback]) {
29
30
  return this._instance.current[callback](...args);
30
31
  }
31
32
  },
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { TabBarConfig, PageConfig } from './types';
2
+ import type { PageConfig, TabBarConfig } from './types';
3
3
  interface PageConfigProps {
4
4
  tabBar: TabBarConfig;
5
5
  pageConfig: PageConfig;
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_1 = __importDefault(require("react"));
7
- const qs_1 = __importDefault(require("qs"));
8
6
  const framework_shared_1 = require("@rsmax/framework-shared");
7
+ const qs_1 = __importDefault(require("qs"));
8
+ const react_1 = __importDefault(require("react"));
9
9
  const PullToRefresh_1 = __importDefault(require("./PullToRefresh"));
10
10
  const DEFAULT_REACH_BOTTOM_DISTANCE = 50;
11
11
  function createPageConfig(Page, name) {
@@ -20,6 +20,7 @@ function createPageConfig(Page, name) {
20
20
  };
21
21
  },
22
22
  callLifecycle(lifeCycle, ...args) {
23
+ var _a;
23
24
  const callbacks = this.lifeCycleCallback[lifeCycle] || [];
24
25
  let result;
25
26
  callbacks.forEach((callback) => {
@@ -29,7 +30,7 @@ function createPageConfig(Page, name) {
29
30
  return result;
30
31
  }
31
32
  const callback = (0, framework_shared_1.callbackName)(lifeCycle);
32
- if (this.wrapperRef.current && this.wrapperRef.current[callback]) {
33
+ if ((_a = this.wrapperRef.current) === null || _a === void 0 ? void 0 : _a[callback]) {
33
34
  return this.wrapperRef.current[callback](...args);
34
35
  }
35
36
  },
@@ -37,6 +38,7 @@ function createPageConfig(Page, name) {
37
38
  const PageWrapper = (0, framework_shared_1.createPageWrapper)(Page, name);
38
39
  return class PageConfig extends react_1.default.Component {
39
40
  constructor(props) {
41
+ var _a, _b;
40
42
  super(props);
41
43
  this.state = {
42
44
  refreshing: true,
@@ -101,8 +103,8 @@ function createPageConfig(Page, name) {
101
103
  }
102
104
  this.isReachBottom = isCurrentReachBottom;
103
105
  };
104
- props.cacheLifecycles.didCache(this.componentDidCache);
105
- props.cacheLifecycles.didRecover(this.componentDidRecover);
106
+ (_a = props.cacheLifecycles) === null || _a === void 0 ? void 0 : _a.didCache(this.componentDidCache);
107
+ (_b = props.cacheLifecycles) === null || _b === void 0 ? void 0 : _b.didRecover(this.componentDidRecover);
106
108
  }
107
109
  componentDidMount() {
108
110
  this.setTitle();
@@ -119,7 +121,7 @@ function createPageConfig(Page, name) {
119
121
  const { refreshing } = this.state;
120
122
  const hasTabBar = !!tabBar;
121
123
  const className = `rsmax-page ${hasTabBar ? 'with-tab-bar' : ''}`;
122
- const query = qs_1.default.parse(location.search, { ignoreQueryPrefix: true });
124
+ const query = qs_1.default.parse(location === null || location === void 0 ? void 0 : location.search, { ignoreQueryPrefix: true });
123
125
  if (this.isPullDownRefreshEnabled()) {
124
126
  return (react_1.default.createElement(PullToRefresh_1.default, { onRefresh: this.handleRefresh, refreshing: refreshing, distanceToRefresh: 50 },
125
127
  react_1.default.createElement("div", { className: className }, react_1.default.createElement(PageWrapper, {
@@ -3,9 +3,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const react_router_dom_1 = require("react-router-dom");
7
- const qs_1 = __importDefault(require("qs"));
8
6
  const framework_shared_1 = require("@rsmax/framework-shared");
7
+ const qs_1 = __importDefault(require("qs"));
8
+ const react_router_dom_1 = require("react-router-dom");
9
9
  function useQuery() {
10
10
  const location = framework_shared_1.RuntimeOptions.get('mpa') ? window.location : (0, react_router_dom_1.useLocation)();
11
11
  return qs_1.default.parse(location.search, { ignoreQueryPrefix: true });
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  export interface Page {
3
3
  route: string;
4
4
  config: PageConfig;
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export declare const KeepAliveProvider: React.FC<{
3
+ children: React.ReactNode;
4
+ }>;
5
+ interface KeepAliveProps {
6
+ cacheKey: string;
7
+ children: React.ReactNode;
8
+ }
9
+ export declare const KeepAlive: React.FC<KeepAliveProps>;
10
+ export {};
@@ -0,0 +1,68 @@
1
+ import React, { createContext, useContext, useRef, useState } from 'react';
2
+ import { useLocation } from 'react-router-dom';
3
+ const KeepAliveContext = createContext(null);
4
+ export const KeepAliveProvider = ({ children }) => {
5
+ const [cache, setCache] = useState(new Map());
6
+ return (React.createElement(KeepAliveContext.Provider, { value: { cache, setCache } },
7
+ children,
8
+ Array.from(cache.entries()).map(([key, item]) => (React.createElement("div", { key: key, style: {
9
+ display: item.status === 'active' ? 'block' : 'none',
10
+ height: '100%',
11
+ width: '100%',
12
+ } }, item.component)))));
13
+ };
14
+ export const KeepAlive = ({ cacheKey, children }) => {
15
+ const context = useContext(KeepAliveContext);
16
+ const location = useLocation();
17
+ const componentRef = useRef(children);
18
+ if (!context) {
19
+ throw new Error('KeepAlive must be used within KeepAliveProvider');
20
+ }
21
+ const { cache, setCache } = context;
22
+ React.useEffect(() => {
23
+ // 更新组件引用
24
+ componentRef.current = children;
25
+ setCache(prev => {
26
+ const next = new Map(prev);
27
+ if (next.has(cacheKey)) {
28
+ next.set(cacheKey, Object.assign(Object.assign({}, next.get(cacheKey)), { component: children }));
29
+ }
30
+ return next;
31
+ });
32
+ }, [children]);
33
+ React.useEffect(() => {
34
+ // 初始化缓存
35
+ if (!cache.has(cacheKey)) {
36
+ setCache(prev => {
37
+ const next = new Map(prev);
38
+ next.set(cacheKey, {
39
+ component: componentRef.current,
40
+ status: 'active',
41
+ });
42
+ return next;
43
+ });
44
+ }
45
+ // 更新状态
46
+ setCache(prev => {
47
+ const next = new Map(prev);
48
+ prev.forEach((value, key) => {
49
+ next.set(key, Object.assign(Object.assign({}, value), { status: key === cacheKey ? 'active' : 'inactive' }));
50
+ });
51
+ return next;
52
+ });
53
+ // 清理函数
54
+ return () => {
55
+ // 这里我们不会在路由变化时删除缓存
56
+ // 只是将状态设置为 inactive
57
+ setCache(prev => {
58
+ const next = new Map(prev);
59
+ if (next.has(cacheKey)) {
60
+ next.set(cacheKey, Object.assign(Object.assign({}, next.get(cacheKey)), { status: 'inactive' }));
61
+ }
62
+ return next;
63
+ });
64
+ };
65
+ }, [cacheKey, location.pathname]);
66
+ // 不直接渲染children,因为所有缓存的组件都在Provider中渲染
67
+ return null;
68
+ };
@@ -1,3 +1,3 @@
1
1
  import React from 'react';
2
- declare const RemaxPullToRefresh: React.FC<any>;
3
- export default RemaxPullToRefresh;
2
+ declare const RsmaxPullToRefresh: React.FC<any>;
3
+ export default RsmaxPullToRefresh;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import PullToRefresh from 'rmc-pull-to-refresh';
3
3
  import LoadingIcon from './LoadingIcon';
4
- const RemaxPullToRefresh = props => {
4
+ const RsmaxPullToRefresh = props => {
5
5
  return (React.createElement(PullToRefresh, Object.assign({}, props, { getScrollContainer: () => {
6
6
  document.body;
7
7
  }, indicator: {
@@ -11,4 +11,4 @@ const RemaxPullToRefresh = props => {
11
11
  finish: React.createElement(LoadingIcon, null),
12
12
  } })));
13
13
  };
14
- export default RemaxPullToRefresh;
14
+ export default RsmaxPullToRefresh;
package/esm/TabBar.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import React from 'react';
2
- import { History } from 'history';
3
- import { TabBarConfig } from './types';
4
- export declare function TabBar({ config, history }: {
2
+ import type { TabBarConfig } from './types';
3
+ export declare function TabBar({ config }: {
5
4
  config: TabBarConfig;
6
- history: History;
7
5
  }): React.JSX.Element;
package/esm/TabBar.js CHANGED
@@ -1,17 +1,13 @@
1
1
  import React from 'react';
2
- import { Link } from 'react-router-dom';
3
- export function TabBar({ config, history }) {
2
+ import { Link, useLocation } from 'react-router-dom';
3
+ export function TabBar({ config }) {
4
4
  var _a;
5
- const [currentPath, setCurrentPath] = React.useState(history.location.pathname);
6
- React.useEffect(() => {
7
- setCurrentPath(history.location.pathname);
8
- return history.listen(() => {
9
- setCurrentPath(history.location.pathname);
10
- });
11
- }, []);
5
+ const location = useLocation();
6
+ const currentPath = location.pathname;
7
+ React.useEffect(() => { }, [currentPath]);
12
8
  const isActive = (url) => {
13
9
  if (!url.startsWith('/')) {
14
- url = '/' + url;
10
+ url = `/${url}`;
15
11
  }
16
12
  return currentPath === url;
17
13
  };
@@ -22,9 +18,9 @@ function TabBarItem({ config, isActive, item }) {
22
18
  const icon = isActive ? item.activeImage || item.image : item.image;
23
19
  const textColor = (_a = config.textColor) !== null && _a !== void 0 ? _a : '#333';
24
20
  const selectedColor = (_b = config.selectedColor) !== null && _b !== void 0 ? _b : '#108ee9';
25
- return (React.createElement(Link, { to: `/${item.url}`, className: "rsmax-tab-item" },
26
- React.createElement("div", { className: "rsmax-tab-item-image", style: { backgroundImage: `url(${icon})` } }),
27
- React.createElement("div", { className: "rsmax-tab-item-title", style: {
21
+ return (React.createElement(Link, { to: item.url.startsWith('/') ? item.url : `/${item.url}`, className: 'rsmax-tab-item' },
22
+ React.createElement("div", { className: 'rsmax-tab-item-image', style: { backgroundImage: `url(${icon})` } }),
23
+ React.createElement("div", { className: 'rsmax-tab-item-title', style: {
28
24
  color: isActive ? selectedColor : textColor,
29
25
  } }, item.title)));
30
26
  }
package/esm/api.js CHANGED
@@ -1,22 +1,26 @@
1
1
  import { RuntimeOptions } from '@rsmax/framework-shared';
2
2
  export function navigateTo(params) {
3
- const history = RuntimeOptions.get('history');
4
- history.push(params.url);
3
+ const navigate = RuntimeOptions.get('navigate');
4
+ navigate(params.url, {
5
+ replace: true,
6
+ });
5
7
  return Promise.resolve();
6
8
  }
7
9
  export function navigateBack(params) {
8
- const history = RuntimeOptions.get('history');
9
- history.go(-((params === null || params === void 0 ? void 0 : params.delta) || 1));
10
+ const navigate = RuntimeOptions.get('navigate');
11
+ navigate(-((params === null || params === void 0 ? void 0 : params.delta) || 1));
10
12
  return Promise.resolve();
11
13
  }
12
14
  export function redirectTo(params) {
13
- const history = RuntimeOptions.get('history');
14
- history.replace(params.url);
15
+ const navigate = RuntimeOptions.get('navigate');
16
+ navigate(params.url, {
17
+ replace: true,
18
+ });
15
19
  return Promise.resolve();
16
20
  }
17
21
  export function reLaunch(params) {
18
22
  window.location.href = params.url;
19
23
  }
20
24
  export function switchTab(params) {
21
- navigateTo(params);
25
+ navigateTo(params).then();
22
26
  }
@@ -1,2 +1,2 @@
1
- import { BootstrapOptions } from './types';
1
+ import type { BootstrapOptions } from './types';
2
2
  export default function bootstrap(options: BootstrapOptions): void;
package/esm/bootstrap.js CHANGED
@@ -1,16 +1,11 @@
1
1
  import { createRoot } from 'react-dom/client';
2
2
  import hd from 'umi-hd';
3
- import { createHashHistory, createBrowserHistory } from 'history';
4
- import { RuntimeOptions } from '@rsmax/framework-shared';
5
3
  import createApp from './createApp';
6
4
  export default function bootstrap(options) {
7
5
  hd();
8
- const { appConfig } = options;
9
- const history = !appConfig.router || appConfig.router.type !== 'browser' ? createHashHistory() : createBrowserHistory();
10
- RuntimeOptions.apply({ history, mpa: false });
11
6
  const container = document.getElementById('rsmax-app');
12
7
  if (!container)
13
8
  throw new Error('Failed to find the root element');
14
9
  const root = createRoot(container);
15
- root.render(createApp(options, history));
10
+ root.render(createApp(options));
16
11
  }
@@ -1,8 +1,8 @@
1
+ import { PluginDriver, RuntimeOptions } from '@rsmax/framework-shared';
1
2
  import React from 'react';
2
3
  import { createRoot } from 'react-dom/client';
3
4
  import hd from 'umi-hd';
4
5
  import createAppConfig from './createAppConfig';
5
- import { PluginDriver, RuntimeOptions } from '@rsmax/framework-shared';
6
6
  import createPageConfig from './createPageConfig';
7
7
  const noop = () => {
8
8
  // ignore
@@ -41,11 +41,11 @@ export default function bootstrap(options) {
41
41
  if (url.startsWith('/'))
42
42
  publicPath = location.pathname.replace(`/${page.route}.html`, '');
43
43
  const arr = url.split('?');
44
- arr[0] = arr[0] + '.html';
44
+ arr[0] = `${arr[0]}.html`;
45
45
  return publicPath + arr.join('?');
46
46
  },
47
47
  };
48
- RuntimeOptions.apply({ pluginDriver, history, mpa: true });
48
+ RuntimeOptions.apply({ pluginDriver, mpa: true });
49
49
  const App = createApp(options);
50
50
  const container = document.getElementById('rsmax-app');
51
51
  if (!container)
@@ -1,4 +1,3 @@
1
1
  import 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;
2
+ import type { BootstrapOptions } from './types';
3
+ export default function createApp(options: BootstrapOptions): React.JSX.Element;
package/esm/createApp.js CHANGED
@@ -1,38 +1,56 @@
1
- import React from 'react';
2
- import { RuntimeOptions, PluginDriver } from '@rsmax/framework-shared';
3
- import { CacheRoute, CacheSwitch } from '@remax/react-router-cache-route';
4
- import { Router, Route, Redirect, useLocation } from 'react-router-dom';
5
1
  import loadable from '@loadable/component';
2
+ import { PluginDriver, RuntimeOptions } from '@rsmax/framework-shared';
3
+ import React from 'react';
4
+ import { BrowserRouter, HashRouter, Navigate, Route, Routes, useLocation, useNavigate } from 'react-router-dom';
5
+ import { KeepAlive, KeepAliveProvider } from './KeepAlive';
6
+ import { TabBar } from './TabBar';
6
7
  import createAppConfig from './createAppConfig';
7
8
  import createPageConfig from './createPageConfig';
8
- import { TabBar } from './TabBar';
9
- export default function createApp(options, history) {
10
- var _a, _b, _c;
9
+ export default function createApp(options) {
10
+ var _a;
11
11
  const { async = true, appComponent, appConfig, pageComponents, pages, plugins = [] } = options;
12
12
  const AppConfig = createAppConfig(appComponent);
13
13
  const pluginDriver = new PluginDriver(plugins.map(plugin => plugin.default || plugin));
14
- RuntimeOptions.apply({ pluginDriver });
15
14
  const pageComponentsHoc = pages.map((page, i) => {
16
- const pageComponent = async
15
+ return async
17
16
  ? loadable(() => pageComponents[i]().then(({ default: c }) => createPageConfig(c, page.route)))
18
17
  : createPageConfig(pageComponents[i](), page.route);
19
- return pageComponent;
20
18
  });
21
- return (React.createElement(Router, { history: history },
22
- React.createElement(AppConfig, null,
23
- React.createElement(CacheSwitch, null,
24
- React.createElement(Route, { exact: true, path: "/" },
25
- React.createElement(Redirect, { to: `/${(_a = pages[0]) === null || _a === void 0 ? void 0 : _a.route}` })),
26
- pages.map((page, i) => {
27
- return (React.createElement(CacheRoute, { key: page.route, className: "rsmax-cached-router-wrapper", path: `/${page.route}`, exact: true }, (props) => {
28
- const pageComponent = pageComponentsHoc[i];
29
- return React.createElement(pageComponent, Object.assign(Object.assign({}, props), { pageConfig: Object.assign(Object.assign({}, appConfig.window), page.config), tabBar: appConfig.tabBar }));
30
- }));
31
- }),
32
- React.createElement(Route, null,
33
- React.createElement(Redirect, { to: `/${(_b = pages[0]) === null || _b === void 0 ? void 0 : _b.route}` }))),
34
- ((_c = appConfig.tabBar) === null || _c === void 0 ? void 0 : _c.items) && appConfig.tabBar.items.length > 0 && (React.createElement(TabBar, { history: history, config: appConfig.tabBar })),
35
- process.env.NODE_ENV === 'development' && React.createElement(LogLocation, null))));
19
+ const AppConfigElement = () => {
20
+ var _a, _b, _c;
21
+ const navigate = useNavigate();
22
+ React.useEffect(() => {
23
+ RuntimeOptions.apply({ pluginDriver, navigate, mpa: false });
24
+ }, [navigate]);
25
+ return (React.createElement(AppConfig, null,
26
+ React.createElement(KeepAliveProvider, null,
27
+ React.createElement(Routes, null,
28
+ React.createElement(Route, { path: "/", element: React.createElement(Navigate, { to: `/${(_a = pages[0]) === null || _a === void 0 ? void 0 : _a.route}`, replace: true }) }),
29
+ pages.map((page, i) => {
30
+ // 合并页面配置
31
+ const pageConfig = Object.assign(Object.assign({}, appConfig.window), page.config);
32
+ // 默认所有页面都开启keepAlive
33
+ const pageElement = React.createElement(pageComponentsHoc[i], {
34
+ pageConfig,
35
+ tabBar: appConfig.tabBar,
36
+ });
37
+ return (React.createElement(Route, { key: page.route, path: `/${page.route}`, element: React.createElement(KeepAlive, { cacheKey: `/${page.route}` }, pageElement) }));
38
+ }),
39
+ React.createElement(Route, { path: "*", element:
40
+ /*找不到路由时重定向到首页*/
41
+ React.createElement(Navigate, { to: `/${(_b = pages[0]) === null || _b === void 0 ? void 0 : _b.route}`, replace: true }) })),
42
+ ((_c = appConfig.tabBar) === null || _c === void 0 ? void 0 : _c.items) && appConfig.tabBar.items.length > 0 && React.createElement(TabBar, { config: appConfig.tabBar }),
43
+ process.env.NODE_ENV === 'development' && React.createElement(LogLocation, null))));
44
+ };
45
+ if (((_a = options.appConfig.router) === null || _a === void 0 ? void 0 : _a.type) === 'browser') {
46
+ return (React.createElement(BrowserRouter, null,
47
+ React.createElement(AppConfigElement, null)));
48
+ }
49
+ return (React.createElement(HashRouter, { future: {
50
+ v7_startTransition: true,
51
+ v7_relativeSplatPath: true,
52
+ } },
53
+ React.createElement(AppConfigElement, null)));
36
54
  }
37
55
  function LogLocation() {
38
56
  const location = useLocation();
@@ -1,6 +1,6 @@
1
+ import { AppInstanceContext, AppLifecycle, callbackName, isClassComponent } from '@rsmax/framework-shared';
1
2
  import React from 'react';
2
3
  import { ForwardRef } from 'react-is';
3
- import { AppInstanceContext, AppLifecycle, callbackName, isClassComponent } from '@rsmax/framework-shared';
4
4
  class DefaultAppComponent extends React.Component {
5
5
  render() {
6
6
  return React.createElement(React.Fragment, this.props);
@@ -11,6 +11,7 @@ export default function createAppConfig(App) {
11
11
  const config = {
12
12
  _instance: React.createRef(),
13
13
  callLifecycle(lifecycle, ...args) {
14
+ var _a;
14
15
  const callbacks = AppInstanceContext.lifecycleCallback[lifecycle] || [];
15
16
  let result;
16
17
  callbacks.forEach((callback) => {
@@ -20,7 +21,7 @@ export default function createAppConfig(App) {
20
21
  return result;
21
22
  }
22
23
  const callback = callbackName(lifecycle);
23
- if (this._instance.current && this._instance.current[callback]) {
24
+ if ((_a = this._instance.current) === null || _a === void 0 ? void 0 : _a[callback]) {
24
25
  return this._instance.current[callback](...args);
25
26
  }
26
27
  },
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { TabBarConfig, PageConfig } from './types';
2
+ import type { PageConfig, TabBarConfig } from './types';
3
3
  interface PageConfigProps {
4
4
  tabBar: TabBarConfig;
5
5
  pageConfig: PageConfig;
@@ -1,6 +1,6 @@
1
- import React from 'react';
1
+ import { Lifecycle, callbackName, createPageWrapper } from '@rsmax/framework-shared';
2
2
  import qs from 'qs';
3
- import { createPageWrapper, Lifecycle, callbackName } from '@rsmax/framework-shared';
3
+ import React from 'react';
4
4
  import PullToRefresh from './PullToRefresh';
5
5
  const DEFAULT_REACH_BOTTOM_DISTANCE = 50;
6
6
  export default function createPageConfig(Page, name) {
@@ -15,6 +15,7 @@ export default function createPageConfig(Page, name) {
15
15
  };
16
16
  },
17
17
  callLifecycle(lifeCycle, ...args) {
18
+ var _a;
18
19
  const callbacks = this.lifeCycleCallback[lifeCycle] || [];
19
20
  let result;
20
21
  callbacks.forEach((callback) => {
@@ -24,7 +25,7 @@ export default function createPageConfig(Page, name) {
24
25
  return result;
25
26
  }
26
27
  const callback = callbackName(lifeCycle);
27
- if (this.wrapperRef.current && this.wrapperRef.current[callback]) {
28
+ if ((_a = this.wrapperRef.current) === null || _a === void 0 ? void 0 : _a[callback]) {
28
29
  return this.wrapperRef.current[callback](...args);
29
30
  }
30
31
  },
@@ -32,6 +33,7 @@ export default function createPageConfig(Page, name) {
32
33
  const PageWrapper = createPageWrapper(Page, name);
33
34
  return class PageConfig extends React.Component {
34
35
  constructor(props) {
36
+ var _a, _b;
35
37
  super(props);
36
38
  this.state = {
37
39
  refreshing: true,
@@ -96,8 +98,8 @@ export default function createPageConfig(Page, name) {
96
98
  }
97
99
  this.isReachBottom = isCurrentReachBottom;
98
100
  };
99
- props.cacheLifecycles.didCache(this.componentDidCache);
100
- props.cacheLifecycles.didRecover(this.componentDidRecover);
101
+ (_a = props.cacheLifecycles) === null || _a === void 0 ? void 0 : _a.didCache(this.componentDidCache);
102
+ (_b = props.cacheLifecycles) === null || _b === void 0 ? void 0 : _b.didRecover(this.componentDidRecover);
101
103
  }
102
104
  componentDidMount() {
103
105
  this.setTitle();
@@ -114,7 +116,7 @@ export default function createPageConfig(Page, name) {
114
116
  const { refreshing } = this.state;
115
117
  const hasTabBar = !!tabBar;
116
118
  const className = `rsmax-page ${hasTabBar ? 'with-tab-bar' : ''}`;
117
- const query = qs.parse(location.search, { ignoreQueryPrefix: true });
119
+ const query = qs.parse(location === null || location === void 0 ? void 0 : location.search, { ignoreQueryPrefix: true });
118
120
  if (this.isPullDownRefreshEnabled()) {
119
121
  return (React.createElement(PullToRefresh, { onRefresh: this.handleRefresh, refreshing: refreshing, distanceToRefresh: 50 },
120
122
  React.createElement("div", { className: className }, React.createElement(PageWrapper, {
@@ -1,6 +1,6 @@
1
- import { useLocation } from 'react-router-dom';
2
- import qs from 'qs';
3
1
  import { RuntimeOptions } from '@rsmax/framework-shared';
2
+ import qs from 'qs';
3
+ import { useLocation } from 'react-router-dom';
4
4
  export default function useQuery() {
5
5
  const location = RuntimeOptions.get('mpa') ? window.location : useLocation();
6
6
  return qs.parse(location.search, { ignoreQueryPrefix: true });
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import type React from 'react';
2
2
  export interface Page {
3
3
  route: string;
4
4
  config: PageConfig;