@modern-js/plugin-router-v5 2.17.0 → 2.17.2-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ function _defineProperty(obj, key, value) {
2
+ if (key in obj) {
3
+ Object.defineProperty(obj, key, {
4
+ value: value,
5
+ enumerable: true,
6
+ configurable: true,
7
+ writable: true
8
+ });
9
+ } else {
10
+ obj[key] = value;
11
+ }
12
+ return obj;
13
+ }
14
+ function _objectSpread(target) {
15
+ for(var i = 1; i < arguments.length; i++){
16
+ var source = arguments[i] != null ? arguments[i] : {};
17
+ var ownKeys = Object.keys(source);
18
+ if (typeof Object.getOwnPropertySymbols === "function") {
19
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
20
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
21
+ }));
22
+ }
23
+ ownKeys.forEach(function(key) {
24
+ _defineProperty(target, key, source[key]);
25
+ });
26
+ }
27
+ return target;
28
+ }
29
+ function _objectWithoutProperties(source, excluded) {
30
+ if (source == null) return {};
31
+ var target = _objectWithoutPropertiesLoose(source, excluded);
32
+ var key, i;
33
+ if (Object.getOwnPropertySymbols) {
34
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
35
+ for(i = 0; i < sourceSymbolKeys.length; i++){
36
+ key = sourceSymbolKeys[i];
37
+ if (excluded.indexOf(key) >= 0) continue;
38
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
39
+ target[key] = source[key];
40
+ }
41
+ }
42
+ return target;
43
+ }
44
+ function _objectWithoutPropertiesLoose(source, excluded) {
45
+ if (source == null) return {};
46
+ var target = {};
47
+ var sourceKeys = Object.keys(source);
48
+ var key, i;
49
+ for(i = 0; i < sourceKeys.length; i++){
50
+ key = sourceKeys[i];
51
+ if (excluded.indexOf(key) >= 0) continue;
52
+ target[key] = source[key];
53
+ }
54
+ return target;
55
+ }
56
+ import { jsx } from "react/jsx-runtime";
57
+ import { Route, matchPath } from "react-router-dom";
58
+ import { DefaultNotFound } from "./DefaultNotFound";
59
+ function renderRoutes(routesConfig) {
60
+ var extraProps = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
61
+ var Layout = function(_param) {
62
+ var Component = _param.Component, props = _objectWithoutProperties(_param, [
63
+ "Component"
64
+ ]);
65
+ var GlobalLayout = routesConfig === null || routesConfig === void 0 ? void 0 : routesConfig.globalApp;
66
+ if (!GlobalLayout) {
67
+ return /* @__PURE__ */ jsx(Component, _objectSpread({}, props));
68
+ }
69
+ return /* @__PURE__ */ jsx(GlobalLayout, _objectSpread({
70
+ Component: Component
71
+ }, props));
72
+ };
73
+ var findMatchedRoute = function(pathname) {
74
+ var ref;
75
+ return routesConfig === null || routesConfig === void 0 ? void 0 : (ref = routesConfig.routes) === null || ref === void 0 ? void 0 : ref.find(function(route) {
76
+ var info = matchPath(pathname, {
77
+ path: route.path,
78
+ exact: route.exact,
79
+ sensitive: route.sensitive
80
+ });
81
+ return Boolean(info);
82
+ });
83
+ };
84
+ return /* @__PURE__ */ jsx(Route, {
85
+ path: "/",
86
+ render: function(props) {
87
+ var matchedRoute = findMatchedRoute(props.location.pathname);
88
+ if (!matchedRoute) {
89
+ return /* @__PURE__ */ jsx(DefaultNotFound, {});
90
+ }
91
+ return /* @__PURE__ */ jsx(Route, {
92
+ path: matchedRoute.path,
93
+ exact: matchedRoute.exact,
94
+ sensitive: matchedRoute.sensitive,
95
+ render: function(routeProps) {
96
+ return /* @__PURE__ */ jsx(Layout, _objectSpread({
97
+ Component: matchedRoute.component
98
+ }, routeProps, extraProps));
99
+ }
100
+ });
101
+ }
102
+ });
103
+ }
104
+ function getLocation(serverContext) {
105
+ var ref;
106
+ var ref1 = (serverContext === null || serverContext === void 0 ? void 0 : serverContext.request) || {}, pathname = ref1.pathname, url = ref1.url;
107
+ var cleanUrl = (ref = url === null || url === void 0 ? void 0 : url.replace("http://", "")) === null || ref === void 0 ? void 0 : ref.replace("https://", "");
108
+ var index = (cleanUrl || "").indexOf(pathname);
109
+ if (index === -1) {
110
+ return pathname;
111
+ }
112
+ return cleanUrl.substring(index);
113
+ }
114
+ var urlJoin = function() {
115
+ for(var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++){
116
+ parts[_key] = arguments[_key];
117
+ }
118
+ var separator = "/";
119
+ var replace = new RegExp("".concat(separator, "{1,}"), "g");
120
+ return standardSlash(parts.join(separator).replace(replace, separator));
121
+ };
122
+ function standardSlash(str) {
123
+ var addr = str;
124
+ if (!addr || typeof addr !== "string") {
125
+ return addr;
126
+ }
127
+ if (addr.startsWith(".")) {
128
+ addr = addr.slice(1);
129
+ }
130
+ if (!addr.startsWith("/")) {
131
+ addr = "/".concat(addr);
132
+ }
133
+ if (addr.endsWith("/") && addr !== "/") {
134
+ addr = addr.slice(0, addr.length - 1);
135
+ }
136
+ return addr;
137
+ }
138
+ export { getLocation, renderRoutes, standardSlash, urlJoin };
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare const DefaultNotFound: () => JSX.Element;
@@ -0,0 +1,5 @@
1
+ import { RouteProps } from 'react-router-dom';
2
+ declare const modifyRoutesHook: import("@modern-js/plugin").Waterfall<RouteProps<string, {
3
+ [x: string]: string | undefined;
4
+ }>[]>;
5
+ export { modifyRoutesHook };
@@ -36,7 +36,7 @@ export type HistoryConfig = {
36
36
  };
37
37
  export type RouterConfig = Partial<HistoryConfig> & {
38
38
  mode?: 'react-router-5';
39
- routesConfig?: {
39
+ routesConfig: {
40
40
  globalApp?: React.ComponentType<any>;
41
41
  routes?: SingleRouteConfig[];
42
42
  };
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.17.0",
18
+ "version": "2.17.2-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/cli/index.d.ts",
21
21
  "main": "./dist/cjs/cli/index.js",
@@ -59,8 +59,9 @@
59
59
  "history": "^4.7.9",
60
60
  "hoist-non-react-statics": "^3.3.2",
61
61
  "react-router-dom": "^5.3.4",
62
- "@modern-js/types": "2.17.0",
63
- "@modern-js/utils": "2.17.0"
62
+ "@modern-js/plugin": "2.17.1",
63
+ "@modern-js/types": "2.17.1",
64
+ "@modern-js/utils": "2.17.1"
64
65
  },
65
66
  "peerDependencies": {
66
67
  "react": ">=17",
@@ -78,12 +79,12 @@
78
79
  "react-dom": "^18",
79
80
  "ts-jest": "^29.0.4",
80
81
  "typescript": "^4",
81
- "@modern-js/app-tools": "2.17.0",
82
- "@modern-js/core": "2.17.0",
83
- "@modern-js/runtime": "2.17.0",
84
- "@modern-js/utils": "2.17.0",
85
- "@scripts/build": "2.17.0",
86
- "@scripts/jest-config": "2.17.0"
82
+ "@modern-js/app-tools": "2.17.1",
83
+ "@modern-js/core": "2.17.1",
84
+ "@modern-js/runtime": "2.17.1",
85
+ "@modern-js/utils": "2.17.1",
86
+ "@scripts/build": "2.17.1",
87
+ "@scripts/jest-config": "2.17.1"
87
88
  },
88
89
  "sideEffects": false,
89
90
  "modernConfig": {},