@common-stack/client-react 0.1.21 → 0.2.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.
- package/lib/__tests__/fill-register-test.d.ts +1 -0
- package/lib/__tests__/fill-register-test.js +66 -0
- package/lib/__tests__/fill-register-test.js.map +1 -0
- package/lib/__tests__/helpers/sample-menu.d.ts +79 -0
- package/lib/__tests__/helpers/sample-menu.js +78 -0
- package/lib/__tests__/helpers/sample-menu.js.map +1 -0
- package/lib/__tests__/integrated-routes.test.d.ts +1 -0
- package/lib/__tests__/integrated-routes.test.js +83 -0
- package/lib/__tests__/integrated-routes.test.js.map +1 -0
- package/lib/__tests__/render-routes.test.d.ts +3 -0
- package/lib/__tests__/render-routes.test.js +89 -0
- package/lib/__tests__/render-routes.test.js.map +1 -0
- package/lib/connector/base-connector.d.ts +52 -0
- package/lib/connector/base-connector.js +148 -0
- package/lib/connector/base-connector.js.map +1 -0
- package/lib/connector/connector.d.ts +7 -43
- package/lib/connector/connector.js +15 -0
- package/lib/connector/connector.js.map +1 -0
- package/lib/connector/connector.native.d.ts +7 -0
- package/lib/connector/connector.native.js +14 -0
- package/lib/connector/connector.native.js.map +1 -0
- package/lib/connector/connector.test.d.ts +1 -0
- package/lib/connector/connector.test.js +32 -0
- package/lib/connector/connector.test.js.map +1 -0
- package/lib/connector/index.js +14 -0
- package/lib/connector/index.js.map +1 -0
- package/lib/index.d.ts +1 -2
- package/lib/index.js +9 -2147
- package/lib/index.js.map +1 -1
- package/lib/index.native.d.ts +9 -0
- package/lib/index.native.js +24 -0
- package/lib/index.native.js.map +1 -0
- package/lib/interfaces/extended-feature.js +3 -0
- package/lib/interfaces/extended-feature.js.map +1 -0
- package/lib/interfaces/index.js +17 -0
- package/lib/interfaces/index.js.map +1 -0
- package/lib/interfaces/menu.js +12 -0
- package/lib/interfaces/menu.js.map +1 -0
- package/lib/interfaces/new-router.d.ts +18 -1
- package/lib/interfaces/new-router.js +3 -0
- package/lib/interfaces/new-router.js.map +1 -0
- package/lib/interfaces/router.js +3 -0
- package/lib/interfaces/router.js.map +1 -0
- package/lib/inversify/InversifyContext.js +37 -0
- package/lib/inversify/InversifyContext.js.map +1 -0
- package/lib/inversify/index.js +14 -0
- package/lib/inversify/index.js.map +1 -0
- package/lib/plugin-area/__tests__/higher-order-component-util.test.d.ts +1 -0
- package/lib/plugin-area/__tests__/higher-order-component-util.test.js +60 -0
- package/lib/plugin-area/__tests__/higher-order-component-util.test.js.map +1 -0
- package/lib/plugin-area/__tests__/plugin-api.test.d.ts +1 -0
- package/lib/plugin-area/__tests__/plugin-api.test.js +54 -0
- package/lib/plugin-area/__tests__/plugin-api.test.js.map +1 -0
- package/lib/plugin-area/{plugin-area.d.ts → base-plugin-area.d.ts} +1 -1
- package/lib/plugin-area/base-plugin-area.js +68 -0
- package/lib/plugin-area/base-plugin-area.js.map +1 -0
- package/lib/plugin-area/higher-order-component-util.js +23 -0
- package/lib/plugin-area/higher-order-component-util.js.map +1 -0
- package/lib/plugin-area/index.d.ts +2 -2
- package/lib/plugin-area/index.js +34 -0
- package/lib/plugin-area/index.js.map +1 -0
- package/lib/plugin-area/index.native.d.ts +2 -0
- package/lib/plugin-area/index.native.js +31 -0
- package/lib/plugin-area/index.native.js.map +1 -0
- package/lib/plugin-area/plugin-api.js +79 -0
- package/lib/plugin-area/plugin-api.js.map +1 -0
- package/lib/plugin-area/plugin-context.js +44 -0
- package/lib/plugin-area/plugin-context.js.map +1 -0
- package/lib/route/__tests__/admin-new-routes.test.d.ts +1 -0
- package/lib/route/__tests__/admin-new-routes.test.js +175 -0
- package/lib/route/__tests__/admin-new-routes.test.js.map +1 -0
- package/lib/route/__tests__/config-routes.test.d.ts +0 -0
- package/lib/route/__tests__/config-routes.test.js +326 -0
- package/lib/route/__tests__/config-routes.test.js.map +1 -0
- package/lib/route/__tests__/getFlatMenus.test.d.ts +1 -0
- package/lib/route/__tests__/getFlatMenus.test.js +96 -0
- package/lib/route/__tests__/getFlatMenus.test.js.map +1 -0
- package/lib/route/__tests__/render-routes-config.test.d.ts +2 -0
- package/lib/route/__tests__/render-routes-config.test.js +69 -0
- package/lib/route/__tests__/render-routes-config.test.js.map +1 -0
- package/lib/route/__tests__/route-type.test.d.ts +1 -0
- package/lib/route/__tests__/route-type.test.js +9 -0
- package/lib/route/__tests__/route-type.test.js.map +1 -0
- package/lib/route/get-routes.d.ts +3 -0
- package/lib/route/get-routes.js +86 -0
- package/lib/route/get-routes.js.map +1 -0
- package/lib/route/get-routes.test.d.ts +1 -0
- package/lib/route/get-routes.test.js +170 -0
- package/lib/route/get-routes.test.js.map +1 -0
- package/lib/route/index.js +14 -0
- package/lib/route/index.js.map +1 -0
- package/lib/route/index.native.d.ts +1 -0
- package/lib/route/index.native.js +14 -0
- package/lib/route/index.native.js.map +1 -0
- package/lib/route/old/__tests__/config-sidebar-menu.test.d.ts +1 -0
- package/lib/route/old/__tests__/config-sidebar-menu.test.js +198 -0
- package/lib/route/old/__tests__/config-sidebar-menu.test.js.map +1 -0
- package/lib/route/old/get-menus.d.ts +2 -0
- package/lib/route/old/get-menus.js +63 -0
- package/lib/route/old/get-menus.js.map +1 -0
- package/lib/route/old/get-routes-notused.d.ts +11 -0
- package/lib/route/old/get-routes-notused.js +61 -0
- package/lib/route/old/get-routes-notused.js.map +1 -0
- package/lib/route/old/render.d.ts +2 -0
- package/lib/route/old/render.js +30 -0
- package/lib/route/old/render.js.map +1 -0
- package/lib/route/render-routes-test.d.ts +1 -0
- package/lib/route/render-routes-test.js +40 -0
- package/lib/route/render-routes-test.js.map +1 -0
- package/lib/route/render-routes.d.ts +2 -14
- package/lib/route/render-routes.js +164 -0
- package/lib/route/render-routes.js.map +1 -0
- package/lib/route/render-routes.native.d.ts +4 -0
- package/lib/route/render-routes.native.js +158 -0
- package/lib/route/render-routes.native.js.map +1 -0
- package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.d.ts +1 -0
- package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js +60 -0
- package/lib/route-based-plugin-area/__tests__/higher-order-component-util.test.js.map +1 -0
- package/lib/route-based-plugin-area/__tests__/plugin-api.test.d.ts +1 -0
- package/lib/route-based-plugin-area/__tests__/plugin-api.test.js +54 -0
- package/lib/route-based-plugin-area/__tests__/plugin-api.test.js.map +1 -0
- package/lib/route-based-plugin-area/higher-order-component-util.js +23 -0
- package/lib/route-based-plugin-area/higher-order-component-util.js.map +1 -0
- package/lib/route-based-plugin-area/index.js +15 -0
- package/lib/route-based-plugin-area/index.js.map +1 -0
- package/lib/route-based-plugin-area/plugin-api.js +79 -0
- package/lib/route-based-plugin-area/plugin-api.js.map +1 -0
- package/lib/route-based-plugin-area/plugin-context.js +44 -0
- package/lib/route-based-plugin-area/plugin-context.js.map +1 -0
- package/lib/route-based-plugin-area/route-based-plugin-area.js +68 -0
- package/lib/route-based-plugin-area/route-based-plugin-area.js.map +1 -0
- package/lib/{router/router.d.ts → router-factory/index.d.ts} +0 -0
- package/lib/router-factory/index.js +30 -0
- package/lib/router-factory/index.js.map +1 -0
- package/lib/router-factory/index.native.d.ts +2 -0
- package/lib/router-factory/index.native.js +30 -0
- package/lib/router-factory/index.native.js.map +1 -0
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +15 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/sort-keys.d.ts +1 -0
- package/lib/utils/sort-keys.js +73 -0
- package/lib/utils/sort-keys.js.map +1 -0
- package/lib/utils/sort-keys.test.d.ts +1 -0
- package/lib/utils/sort-keys.test.js +30 -0
- package/lib/utils/sort-keys.test.js.map +1 -0
- package/lib/utils/utils.d.ts +4 -0
- package/lib/utils/utils.js +13 -0
- package/lib/utils/utils.js.map +1 -0
- package/package.json +7 -6
- package/lib/plugin-area/browser-plugin-area.d.ts +0 -2
- package/lib/router/index.d.ts +0 -1
- package/lib/slot-fill/context.d.ts +0 -94
- package/lib/slot-fill/fill.d.ts +0 -10
- package/lib/slot-fill/index.d.ts +0 -4
- package/lib/slot-fill/slot.d.ts +0 -8
- package/lib/slot-fill/utils/index.d.ts +0 -1
- package/lib/slot-fill/utils/isEmptyElement.d.ts +0 -8
- package/lib/utils/route-utils.d.ts +0 -17
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const React = __importStar(require("react"));
|
|
23
|
+
const react_router_dom_1 = require("react-router-dom");
|
|
24
|
+
function TestInitialProps({ foo }) {
|
|
25
|
+
return React.createElement("h1", { "data-testid": "test" }, foo);
|
|
26
|
+
}
|
|
27
|
+
let mountCount = 0;
|
|
28
|
+
function TestInitialPropsWithoutUnmount({ foo }) {
|
|
29
|
+
React.useEffect(() => {
|
|
30
|
+
return () => {
|
|
31
|
+
mountCount++;
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
34
|
+
return (React.createElement("div", null,
|
|
35
|
+
React.createElement("h1", { "data-testid": "test2" }, foo),
|
|
36
|
+
React.createElement("a", { href: "#bar" }, "link-bar"),
|
|
37
|
+
React.createElement(react_router_dom_1.Link, { to: "/get-initial-props" }, "change-route"),
|
|
38
|
+
React.createElement("h2", { id: "bar" }, "h2-bar")));
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=render-routes-test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-routes-test.js","sourceRoot":"","sources":["../../src/route/render-routes-test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAE/B,uDAAwC;AAMxC,SAAS,gBAAgB,CAAC,EAAE,GAAG,EAAmB;IAC9C,OAAO,2CAAgB,MAAM,IAAE,GAAG,CAAM,CAAC;AAC7C,CAAC;AAED,IAAI,UAAU,GAAG,CAAC,CAAC;AACnB,SAAS,8BAA8B,CAAC,EAAE,GAAG,EAAkB;IAC3D,KAAK,CAAC,SAAS,CAAC,GAAG,EAAE;QACjB,OAAO,GAAG,EAAE;YACR,UAAU,EAAE,CAAC;QACjB,CAAC,CAAA;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IACP,OAAO,CACH;QACI,2CAAgB,OAAO,IAAE,GAAG,CAAM;QAClC,2BAAG,IAAI,EAAC,MAAM,eAAa;QAC3B,oBAAC,uBAAI,IAAC,EAAE,EAAC,oBAAoB,mBAAoB;QACjD,4BAAI,EAAE,EAAC,KAAK,aAAY,CACtB,CACT,CAAA;AACL,CAAC"}
|
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
routes: IRoute[];
|
|
5
|
-
plugin?: Plugin;
|
|
6
|
-
extraProps?: object;
|
|
7
|
-
pageInitialProps?: object;
|
|
8
|
-
getInitialPropsCtx?: object;
|
|
9
|
-
isServer?: boolean;
|
|
10
|
-
ssrProps?: object;
|
|
11
|
-
rootRoutes?: IRoute[];
|
|
12
|
-
auth?: boolean;
|
|
13
|
-
authWrapper?: () => void;
|
|
14
|
-
}
|
|
15
|
-
declare function renderRoutes(opts: IOpts): JSX.Element;
|
|
2
|
+
import { IRouterRederOptions } from '../interfaces/new-router';
|
|
3
|
+
declare function renderRoutes(opts: IRouterRederOptions): JSX.Element;
|
|
16
4
|
export { renderRoutes as renderRoutes2 };
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
31
|
+
var t = {};
|
|
32
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
35
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
36
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
37
|
+
t[p[i]] = s[p[i]];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.renderRoutes2 = void 0;
|
|
43
|
+
const React = __importStar(require("react"));
|
|
44
|
+
const react_1 = require("react");
|
|
45
|
+
const react_router_1 = require("react-router");
|
|
46
|
+
function wrapInitialPropsFetch(route, opts) {
|
|
47
|
+
const { component } = route, restRouteParams = __rest(route, ["component"]);
|
|
48
|
+
let Component = route.component;
|
|
49
|
+
function ComponentWithInitialPropsFetch(props) {
|
|
50
|
+
const [initialProps, setInitialProps] = react_1.useState(() => window.g_initialProps);
|
|
51
|
+
react_1.useEffect(() => {
|
|
52
|
+
/**
|
|
53
|
+
* 1. 首次渲染时,此时 window.g_initialProps 变量存在,不需要再走一次 getInitialProps,这样一次 SSR 就走了 2 次 getInitialProps
|
|
54
|
+
* 2. 但是路由切换时,window.getInitialProps 会被赋为 null,这时候就走 getInitialProps 逻辑
|
|
55
|
+
* 3. 如果任何时候都走 2 次,配置 forceInitial: true,这个场景用于静态站点的首屏加载希望走最新数据
|
|
56
|
+
* 4. 开启动态加载后,会在执行 getInitialProps 前预加载下
|
|
57
|
+
*/
|
|
58
|
+
const handleGetInitialProps = () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
// preload when enalbe dynamicImport
|
|
60
|
+
if (Component.preload) {
|
|
61
|
+
const preloadComponent = yield Component.preload();
|
|
62
|
+
// for test case, really use .default
|
|
63
|
+
Component = preloadComponent.default || preloadComponent;
|
|
64
|
+
}
|
|
65
|
+
//@sri not suppported
|
|
66
|
+
// const defaultCtx = {
|
|
67
|
+
// isServer: false,
|
|
68
|
+
// match: props?.match,
|
|
69
|
+
// route,
|
|
70
|
+
// ...(opts.getInitialPropsCtx || {}),
|
|
71
|
+
// ...restRouteParams,
|
|
72
|
+
// };
|
|
73
|
+
//@sri not suppported
|
|
74
|
+
// if (Component?.getInitialProps) {
|
|
75
|
+
// const ctx = await opts.plugin.applyPlugins({
|
|
76
|
+
// key: 'ssr.modifyGetInitialPropsCtx',
|
|
77
|
+
// type: ApplyPluginsType.modify,
|
|
78
|
+
// initialValue: defaultCtx,
|
|
79
|
+
// async: true,
|
|
80
|
+
// });
|
|
81
|
+
// const initialProps = await Component!.getInitialProps!(
|
|
82
|
+
// ctx || defaultCtx,
|
|
83
|
+
// );
|
|
84
|
+
// setInitialProps(initialProps);
|
|
85
|
+
// }
|
|
86
|
+
});
|
|
87
|
+
// null 时,一定会触发 getInitialProps 执行
|
|
88
|
+
if (!window.g_initialProps) {
|
|
89
|
+
handleGetInitialProps();
|
|
90
|
+
}
|
|
91
|
+
}, [window.location.pathname, window.location.search]);
|
|
92
|
+
return React.createElement(Component, Object.assign({}, props, initialProps));
|
|
93
|
+
}
|
|
94
|
+
// flag for having wrappered
|
|
95
|
+
ComponentWithInitialPropsFetch.wrapInitialPropsLoaded = true;
|
|
96
|
+
ComponentWithInitialPropsFetch.displayName = 'ComponentWithInitialPropsFetch';
|
|
97
|
+
return ComponentWithInitialPropsFetch;
|
|
98
|
+
}
|
|
99
|
+
function render({ route, opts, props, }) {
|
|
100
|
+
const routes = renderRoutes(Object.assign(Object.assign({}, opts), { routes: route.routes || [], rootRoutes: opts.rootRoutes }));
|
|
101
|
+
let { component: Component, wrappers } = route;
|
|
102
|
+
if (Component) {
|
|
103
|
+
const defaultPageInitialProps = opts.isServer
|
|
104
|
+
? {}
|
|
105
|
+
: window.g_initialProps;
|
|
106
|
+
const newProps = Object.assign(Object.assign(Object.assign(Object.assign({}, props), opts.extraProps), (opts.pageInitialProps || defaultPageInitialProps)), { route, routes: opts.rootRoutes });
|
|
107
|
+
// @ts-ignore
|
|
108
|
+
let ret = React.createElement(Component, Object.assign({}, newProps), routes);
|
|
109
|
+
// route.wrappers
|
|
110
|
+
if (wrappers) {
|
|
111
|
+
let len = wrappers.length - 1;
|
|
112
|
+
while (len >= 0) {
|
|
113
|
+
ret = react_1.createElement(wrappers[len], newProps, ret);
|
|
114
|
+
len -= 1;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return ret;
|
|
118
|
+
}
|
|
119
|
+
else {
|
|
120
|
+
return routes;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function getRouteElement({ route, index, opts }) {
|
|
124
|
+
const routeProps = {
|
|
125
|
+
key: route.key || index,
|
|
126
|
+
exact: route.exact,
|
|
127
|
+
strict: route.strict,
|
|
128
|
+
sensitive: route.sensitive,
|
|
129
|
+
path: route.path,
|
|
130
|
+
};
|
|
131
|
+
if (route.redirect) {
|
|
132
|
+
return React.createElement(react_router_1.Redirect, Object.assign({}, routeProps, { from: route.path, to: route.redirect }));
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
// avoid mount and unmount with url hash change
|
|
136
|
+
// @sri not supproted yet
|
|
137
|
+
// if (
|
|
138
|
+
// // only when SSR config enable
|
|
139
|
+
// opts.ssrProps &&
|
|
140
|
+
// !opts.isServer &&
|
|
141
|
+
// // make sure loaded once
|
|
142
|
+
// !(route.component as any)?.wrapInitialPropsLoaded &&
|
|
143
|
+
// (route.component?.getInitialProps || route.component?.preload)
|
|
144
|
+
// ) {
|
|
145
|
+
// // client Render for enable ssr, but not sure SSR success
|
|
146
|
+
// route.component = wrapInitialPropsFetch(route, opts);
|
|
147
|
+
// }
|
|
148
|
+
return (React.createElement(react_router_1.Route, Object.assign({}, routeProps, { render: (props) => {
|
|
149
|
+
return render({ route, opts, props });
|
|
150
|
+
} })));
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function renderRoutes(opts) {
|
|
154
|
+
return opts.routes ? (React.createElement(react_router_1.Switch, null, opts.routes.map((route, index) => {
|
|
155
|
+
const renderedR = getRouteElement({
|
|
156
|
+
route,
|
|
157
|
+
index,
|
|
158
|
+
opts: Object.assign(Object.assign({}, opts), { rootRoutes: opts.rootRoutes || opts.routes }),
|
|
159
|
+
});
|
|
160
|
+
return renderedR;
|
|
161
|
+
}))) : null;
|
|
162
|
+
}
|
|
163
|
+
exports.renderRoutes2 = renderRoutes;
|
|
164
|
+
//# sourceMappingURL=render-routes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-routes.js","sourceRoot":"","sources":["../../src/route/render-routes.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,iCAA2D;AAG3D,+CAAuD;AAGvD,SAAS,qBAAqB,CAAC,KAAa,EAAE,IAAyB;IACrE,MAAM,EAAE,SAAS,KAAyB,KAAK,EAAzB,eAAe,UAAK,KAAK,EAAzC,aAAiC,CAAQ,CAAC;IAChD,IAAI,SAAS,GAAQ,KAAM,CAAC,SAAS,CAAC;IACtC,SAAS,8BAA8B,CAAC,KAAU;QAChD,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,gBAAQ,CAC9C,GAAG,EAAE,CAAE,MAAc,CAAC,cAAc,CACrC,CAAC;QAEF,iBAAS,CAAC,GAAG,EAAE;YACb;;;;;eAKG;YACH,MAAM,qBAAqB,GAAG,GAAS,EAAE;gBACvC,oCAAoC;gBACpC,IAAI,SAAS,CAAC,OAAO,EAAE;oBAC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sB;QACtB,6BAA6B;QAC7B,yDAAyD;QACzD,mEAAmE;QACnE,MAAM;QACN,8DAA8D;QAC9D,0DAA0D;QAC1D,IAAI;QACJ,OAAO,CACL,oBAAC,oBAAK,oBACA,UAAU,IACd,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE;gBACxB,OAAO,MAAM,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;YACxC,CAAC,IACD,CACH,CAAC;KACH;AACH,CAAC;AAED,SAAS,YAAY,CAAC,IAAyB;IAC7C,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CACnB,oBAAC,qBAAM,QACJ,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE;QAEhC,MAAM,SAAS,GAAG,eAAe,CAAC;YAChC,KAAK;YACL,KAAK;YACL,IAAI,kCACC,IAAI,KACP,UAAU,EAAE,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,MAAM,GAC3C;SACF,CAAC,CAAC;QACH,OAAO,SAAS,CAAC;IACnB,CAAC,CAEA,CACM,CACV,CAAC,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAEwB,qCAAa"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
22
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
23
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
24
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
25
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
26
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
27
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
31
|
+
var t = {};
|
|
32
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
33
|
+
t[p] = s[p];
|
|
34
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
35
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
36
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
37
|
+
t[p[i]] = s[p[i]];
|
|
38
|
+
}
|
|
39
|
+
return t;
|
|
40
|
+
};
|
|
41
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
+
exports.renderRoutes2 = void 0;
|
|
43
|
+
const React = __importStar(require("react"));
|
|
44
|
+
const react_1 = require("react");
|
|
45
|
+
const react_router_native_1 = require("react-router-native");
|
|
46
|
+
function wrapInitialPropsFetch(route, opts) {
|
|
47
|
+
const { component } = route, restRouteParams = __rest(route, ["component"]);
|
|
48
|
+
let Component = route.component;
|
|
49
|
+
function ComponentWithInitialPropsFetch(props) {
|
|
50
|
+
const [initialProps, setInitialProps] = react_1.useState(() => window.g_initialProps);
|
|
51
|
+
react_1.useEffect(() => {
|
|
52
|
+
/**
|
|
53
|
+
* 1. 首次渲染时,此时 window.g_initialProps 变量存在,不需要再走一次 getInitialProps,这样一次 SSR 就走了 2 次 getInitialProps
|
|
54
|
+
* 2. 但是路由切换时,window.getInitialProps 会被赋为 null,这时候就走 getInitialProps 逻辑
|
|
55
|
+
* 3. 如果任何时候都走 2 次,配置 forceInitial: true,这个场景用于静态站点的首屏加载希望走最新数据
|
|
56
|
+
* 4. 开启动态加载后,会在执行 getInitialProps 前预加载下
|
|
57
|
+
*/
|
|
58
|
+
const handleGetInitialProps = () => __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
// preload when enalbe dynamicImport
|
|
60
|
+
if (Component.preload) {
|
|
61
|
+
const preloadComponent = yield Component.preload();
|
|
62
|
+
// for test case, really use .default
|
|
63
|
+
Component = preloadComponent.default || preloadComponent;
|
|
64
|
+
}
|
|
65
|
+
// @sri not suppported
|
|
66
|
+
// const defaultCtx = {
|
|
67
|
+
// isServer: false,
|
|
68
|
+
// match: props?.match,
|
|
69
|
+
// route,
|
|
70
|
+
// ...(opts.getInitialPropsCtx || {}),
|
|
71
|
+
// ...restRouteParams,
|
|
72
|
+
// };
|
|
73
|
+
// @sri not suppported
|
|
74
|
+
// if (Component?.getInitialProps) {
|
|
75
|
+
// const ctx = await opts.plugin.applyPlugins({
|
|
76
|
+
// key: 'ssr.modifyGetInitialPropsCtx',
|
|
77
|
+
// type: ApplyPluginsType.modify,
|
|
78
|
+
// initialValue: defaultCtx,
|
|
79
|
+
// async: true,
|
|
80
|
+
// });
|
|
81
|
+
// const initialProps = await Component!.getInitialProps!(
|
|
82
|
+
// ctx || defaultCtx,
|
|
83
|
+
// );
|
|
84
|
+
// setInitialProps(initialProps);
|
|
85
|
+
// }
|
|
86
|
+
});
|
|
87
|
+
// null 时,一定会触发 getInitialProps 执行
|
|
88
|
+
if (!window.g_initialProps) {
|
|
89
|
+
handleGetInitialProps();
|
|
90
|
+
}
|
|
91
|
+
}, [window.location.pathname, window.location.search]);
|
|
92
|
+
return React.createElement(Component, Object.assign({}, props, initialProps));
|
|
93
|
+
}
|
|
94
|
+
// flag for having wrappered
|
|
95
|
+
ComponentWithInitialPropsFetch.wrapInitialPropsLoaded = true;
|
|
96
|
+
ComponentWithInitialPropsFetch.displayName = 'ComponentWithInitialPropsFetch';
|
|
97
|
+
return ComponentWithInitialPropsFetch;
|
|
98
|
+
}
|
|
99
|
+
function render({ route, opts, props }) {
|
|
100
|
+
const routes = renderRoutes(Object.assign(Object.assign({}, opts), { routes: route.routes || [], rootRoutes: opts.rootRoutes }));
|
|
101
|
+
const { component: Component, wrappers } = route;
|
|
102
|
+
if (Component) {
|
|
103
|
+
const defaultPageInitialProps = opts.isServer ? {} : window.g_initialProps;
|
|
104
|
+
const newProps = Object.assign(Object.assign(Object.assign(Object.assign({}, props), opts.extraProps), (opts.pageInitialProps || defaultPageInitialProps)), { route, routes: opts.rootRoutes });
|
|
105
|
+
// @ts-ignore
|
|
106
|
+
let ret = React.createElement(Component, Object.assign({}, newProps), routes);
|
|
107
|
+
// route.wrappers
|
|
108
|
+
if (wrappers) {
|
|
109
|
+
let len = wrappers.length - 1;
|
|
110
|
+
while (len >= 0) {
|
|
111
|
+
ret = react_1.createElement(wrappers[len], newProps, ret);
|
|
112
|
+
len -= 1;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return ret;
|
|
116
|
+
}
|
|
117
|
+
return routes;
|
|
118
|
+
}
|
|
119
|
+
function getRouteElement({ route, index, opts }) {
|
|
120
|
+
const routeProps = {
|
|
121
|
+
key: route.key || index,
|
|
122
|
+
exact: route.exact,
|
|
123
|
+
strict: route.strict,
|
|
124
|
+
sensitive: route.sensitive,
|
|
125
|
+
path: route.path,
|
|
126
|
+
};
|
|
127
|
+
if (route.redirect) {
|
|
128
|
+
return React.createElement(react_router_native_1.Redirect, Object.assign({}, routeProps, { from: route.path, to: route.redirect }));
|
|
129
|
+
}
|
|
130
|
+
// avoid mount and unmount with url hash change
|
|
131
|
+
// @sri not supproted yet
|
|
132
|
+
// if (
|
|
133
|
+
// // only when SSR config enable
|
|
134
|
+
// opts.ssrProps &&
|
|
135
|
+
// !opts.isServer &&
|
|
136
|
+
// // make sure loaded once
|
|
137
|
+
// !(route.component as any)?.wrapInitialPropsLoaded &&
|
|
138
|
+
// (route.component?.getInitialProps || route.component?.preload)
|
|
139
|
+
// ) {
|
|
140
|
+
// // client Render for enable ssr, but not sure SSR success
|
|
141
|
+
// route.component = wrapInitialPropsFetch(route, opts);
|
|
142
|
+
// }
|
|
143
|
+
return (React.createElement(react_router_native_1.Route, Object.assign({}, routeProps, { render: (props) => {
|
|
144
|
+
return render({ route, opts, props });
|
|
145
|
+
} })));
|
|
146
|
+
}
|
|
147
|
+
function renderRoutes(opts) {
|
|
148
|
+
return opts.routes ? (React.createElement(react_router_native_1.Switch, null, opts.routes.map((route, index) => {
|
|
149
|
+
const renderedR = getRouteElement({
|
|
150
|
+
route,
|
|
151
|
+
index,
|
|
152
|
+
opts: Object.assign(Object.assign({}, opts), { rootRoutes: opts.rootRoutes || opts.routes }),
|
|
153
|
+
});
|
|
154
|
+
return renderedR;
|
|
155
|
+
}))) : null;
|
|
156
|
+
}
|
|
157
|
+
exports.renderRoutes2 = renderRoutes;
|
|
158
|
+
//# sourceMappingURL=render-routes.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-routes.native.js","sourceRoot":"","sources":["../../src/route/render-routes.native.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA+B;AAC/B,iCAA2D;AAG3D,6DAA8D;AAE9D,SAAS,qB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+
export {};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
const react_1 = __importStar(require("react"));
|
|
23
|
+
const higher_order_component_util_1 = require("../higher-order-component-util");
|
|
24
|
+
describe('createHigherOrderComponent', () => {
|
|
25
|
+
it('should use default name for anonymous function', () => {
|
|
26
|
+
const TestComponent = higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => OriginalComponent, 'withTest')(() => react_1.default.createElement("div", null));
|
|
27
|
+
expect(TestComponent.displayName).toBe('WithTest(Component');
|
|
28
|
+
});
|
|
29
|
+
it('should use camel case starting with upper for wrapper prefix ', () => {
|
|
30
|
+
const TestComponent = higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => OriginalComponent, 'with-one-two_threeFOUR')(() => react_1.default.createElement("div", null));
|
|
31
|
+
expect(TestComponent.displayName).toBe('WithOneTwoThreeFour(Component)');
|
|
32
|
+
});
|
|
33
|
+
it('should use function name', () => {
|
|
34
|
+
function SomeComponent() {
|
|
35
|
+
return react_1.default.createElement("div", null);
|
|
36
|
+
}
|
|
37
|
+
const TestComponent = higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => OriginalComponent, 'withTest')(SomeComponent);
|
|
38
|
+
expect(TestComponent.displayName).toBe('WithTest(SomeComponent)');
|
|
39
|
+
});
|
|
40
|
+
it('should use component class name', () => {
|
|
41
|
+
class SomeAnotherComponent extends react_1.Component {
|
|
42
|
+
render() {
|
|
43
|
+
return react_1.default.createElement("div", null);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
const TestComponent = higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => OriginalComponent, 'withTest')(SomeAnotherComponent);
|
|
47
|
+
expect(TestComponent.displayName).toBe('WithTest(SomeAnotherComponent)');
|
|
48
|
+
});
|
|
49
|
+
it('should use displayName property', () => {
|
|
50
|
+
class SomeYetAnotherComponent extends react_1.Component {
|
|
51
|
+
render() {
|
|
52
|
+
return react_1.default.createElement("div", null);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
SomeYetAnotherComponent.displayName = 'CustomDisplayName';
|
|
56
|
+
const TestComponent = higher_order_component_util_1.createHigherOrderComponent((OriginalComponent) => OriginalComponent, 'withTest')(SomeYetAnotherComponent);
|
|
57
|
+
expect(TestComponent.displayName).toBe('WithTest(CustomDisplayName)');
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
//# sourceMappingURL=higher-order-component-util.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"higher-order-component-util.test.js","sourceRoot":"","sources":["../../../src/route-based-plugin-area/__tests__/higher-order-component-util.test.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+CAAyC;AAGzC,gFAA4E;AAE5E,QAAQ,CAAC,4BAA4B,EAAE,GAAG,EAAE;IAC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vC,gCAAgC,CAChC,CAAC;IACH,CAAC,CAAE,CAAC;IAEJ,EAAE,CAAE,iCAAiC,EAAE,GAAG,EAAE;QAC3C,MAAM,uBAAwB,SAAQ,iBAAS;YAC9C,MAAM;gBACL,OAAO,0CAAO,CAAC;YAChB,CAAC;SACD;QACA,uBAA+B,CAAC,WAAW,GAAG,mBAAmB,CAAC;QACnE,MAAM,aAAa,GAAG,wDAA0B,CAC/C,CAAE,iBAAiB,EAAG,EAAE,CAAC,iBAAiB,EAC1C,UAAU,CACV,CAAE,uBAAuB,CAAE,CAAC;QAE7B,MAAM,CAAE,aAAa,CAAC,WAAW,CAAE,CAAC,IAAI,CACvC,6BAA6B,CAC7B,CAAC;IACH,CAAC,CAAE,CAAC;AACL,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const plugin_api_1 = require("../plugin-api");
|
|
4
|
+
describe('registerPlugin', () => {
|
|
5
|
+
afterEach(() => {
|
|
6
|
+
plugin_api_1.getRouteBasePlugins().forEach((plugin) => {
|
|
7
|
+
plugin_api_1.unregisterRouteBasePlugin(plugin.name);
|
|
8
|
+
});
|
|
9
|
+
});
|
|
10
|
+
it('successfully registers a plugin', () => {
|
|
11
|
+
const name = 'plugin';
|
|
12
|
+
const icon = 'smiley';
|
|
13
|
+
const Component = () => 'plugin content';
|
|
14
|
+
plugin_api_1.registerRouteBasePlugin(name, {
|
|
15
|
+
render: Component,
|
|
16
|
+
icon,
|
|
17
|
+
});
|
|
18
|
+
expect(plugin_api_1.getRouteBasePlugin(name)).toEqual({
|
|
19
|
+
name,
|
|
20
|
+
render: Component,
|
|
21
|
+
icon,
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it('fails to register a plugin without a settings object', () => {
|
|
25
|
+
plugin_api_1.registerRouteBasePlugin();
|
|
26
|
+
expect(console).toThrowError('No settings object provided!');
|
|
27
|
+
});
|
|
28
|
+
it('fails to register a plugin with special character in the name', () => {
|
|
29
|
+
plugin_api_1.registerRouteBasePlugin('plugin/with/special/characters', {
|
|
30
|
+
render: () => { },
|
|
31
|
+
});
|
|
32
|
+
expect(console).toThrowError('Plugin names must include only lowercase alphanumeric characters or dashes, and start with a letter. Example: "my-plugin".');
|
|
33
|
+
});
|
|
34
|
+
it('fails to register a plugin with a non-string name', () => {
|
|
35
|
+
plugin_api_1.registerRouteBasePlugin({}, {
|
|
36
|
+
render: () => { },
|
|
37
|
+
});
|
|
38
|
+
expect(console).toThrowError('Plugin names must be strings.');
|
|
39
|
+
});
|
|
40
|
+
it('fails to register a plugin without a render function', () => {
|
|
41
|
+
plugin_api_1.registerRouteBasePlugin('another-plugin', {});
|
|
42
|
+
expect(console).toThrowError('The "render" property must be specified and must be a valid function.');
|
|
43
|
+
});
|
|
44
|
+
it('fails to register a plugin that was already been registered', () => {
|
|
45
|
+
plugin_api_1.registerRouteBasePlugin('plugin', {
|
|
46
|
+
render: () => 'plugin content',
|
|
47
|
+
});
|
|
48
|
+
plugin_api_1.registerRouteBasePlugin('plugin', {
|
|
49
|
+
render: () => 'plugin content',
|
|
50
|
+
});
|
|
51
|
+
expect(console).toThrowError('Plugin "plugin" is already registered.');
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
//# sourceMappingURL=plugin-api.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-api.test.js","sourceRoot":"","sources":["../../../src/route-based-plugin-area/__tests__/plugin-api.test.ts"],"names":[],"mappings":";;AAAA,8CAA2H;AAG3H,QAAQ,CAAC,gBAAgB,EAAE,GAAG,EAAE;IAC5B,SAAS,CAAC,GAAG,EAAE;QACX,gCAAmB,EAAE,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YACrC,sCAAyB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAC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,CAC7B,uEAAuE,CACvE,CAAC;IACH,CAAC,CAAE,CAAC;IAEJ,EAAE,CAAE,6DAA6D,EAAE,GAAG,EAAE;QACvE,oCAAuB,CAAE,QAAQ,EAAE;YAClC,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB;SAC9B,CAAE,CAAC;QACJ,oCAAuB,CAAE,QAAQ,EAAE;YAClC,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB;SAC9B,CAAE,CAAC;QACJ,MAAM,CAAE,OAAO,CAAE,CAAC,YAAY,CAC7B,wCAAwC,CACxC,CAAC;IACH,CAAC,CAAE,CAAC;AACL,CAAC,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createHigherOrderComponent = void 0;
|
|
4
|
+
const lodash_1 = require("lodash");
|
|
5
|
+
/**
|
|
6
|
+
* Given a function mapping a component to an enhanced component and modifier
|
|
7
|
+
* name, returns the enhanced component augmented with a generated displayName.
|
|
8
|
+
*
|
|
9
|
+
* @param mapComponentToEnhancedComponent Function mapping component to enhanced component.
|
|
10
|
+
* @param modifierName Seed name from which to generated display name.
|
|
11
|
+
*
|
|
12
|
+
* @return Component class with generated display name assigned.
|
|
13
|
+
*/
|
|
14
|
+
function createHigherOrderComponent(mapComponentToEnhancedComponent, modifierName) {
|
|
15
|
+
return (OriginalComponent) => {
|
|
16
|
+
const EnhancedComponent = mapComponentToEnhancedComponent(OriginalComponent);
|
|
17
|
+
const { displayName = OriginalComponent.name || 'Component', } = OriginalComponent;
|
|
18
|
+
EnhancedComponent.displayName = `${lodash_1.upperFirst(lodash_1.camelCase(modifierName))}(${displayName})`;
|
|
19
|
+
return EnhancedComponent;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
exports.createHigherOrderComponent = createHigherOrderComponent;
|
|
23
|
+
//# sourceMappingURL=higher-order-component-util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"higher-order-component-util.js","sourceRoot":"","sources":["../../src/route-based-plugin-area/higher-order-component-util.ts"],"names":[],"mappings":";;;AACA,mCAA+C;AAE/C;;;;;;;;GAQG;AACH,SAAgB,0BAA0B,CACtC,+BAA+B,EAC/B,YAAY;IAEZ,OAAO,CAAE,iBAAiB,EAAG,EAAE;QAC3B,MAAM,iBAAiB,GAAG,+BAA+B,CACrD,iBAAiB,CACpB,CAAC;QACF,MAAM,EACF,WAAW,GAAG,iBAAiB,CAAC,IAAI,IAAI,WAAW,GACtD,GAAG,iBAAiB,CAAC;QACtB,iBAAiB,CAAC,WAAW,GAAG,GAAI,mBAAU,CAC1C,kBAAS,CAAC,YAAY,CAAC,CAC1B,IAAI,WAAW,GAAG,CAAC;QAEpB,OAAO,iBAAiB,CAAC;IAC7B,CAAC,CAAA;AACL,CAAC;AAjBD,gEAiBC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./route-based-plugin-area"), exports);
|
|
14
|
+
__exportStar(require("./plugin-api"), exports);
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/route-based-plugin-area/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4DAA0C;AAC1C,+CAA6B"}
|