@modern-js/plugin-router-v5 2.18.1 → 2.18.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,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "modifyRoutesHook", {
6
+ enumerable: true,
7
+ get: () => modifyRoutesHook
8
+ });
9
+ const _plugin = require("@modern-js/plugin");
10
+ const modifyRoutesHook = (0, _plugin.createWaterfall)();
@@ -14,6 +14,7 @@ const _hoistnonreactstatics = /* @__PURE__ */ _interop_require_default(require("
14
14
  const _runtime = require("@modern-js/runtime");
15
15
  const _runtimebrowser = require("@modern-js/utils/runtime-browser");
16
16
  const _utils = require("./utils");
17
+ const _hooks = require("./hooks");
17
18
  function _interop_require_default(obj) {
18
19
  return obj && obj.__esModule ? obj : {
19
20
  default: obj
@@ -60,6 +61,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
60
61
  return newObj;
61
62
  }
62
63
  const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
64
+ const { routes: originRoutes } = routesConfig;
63
65
  const isBrow = (0, _runtime.isBrowser)();
64
66
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
65
67
  if (isBrow) {
@@ -67,7 +69,10 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
67
69
  }
68
70
  return {
69
71
  name: "@modern-js/plugin-router",
70
- setup: () => {
72
+ registerHook: {
73
+ modifyRoutes: _hooks.modifyRoutesHook
74
+ },
75
+ setup: (api) => {
71
76
  return {
72
77
  init({ context }, next) {
73
78
  context.router = {
@@ -85,16 +90,21 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
85
90
  const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
86
91
  historyOptions.basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
87
92
  const history = customHistory || (supportHtml5History ? (0, _history.createBrowserHistory)(historyOptions) : (0, _history.createHashHistory)(historyOptions));
88
- return (props) => /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
89
- history,
90
- children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
91
- ...props,
92
- Component: createRoutes()
93
- }) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
94
- ...props,
95
- children: (0, _utils.renderRoutes)(routesConfig, props)
96
- })
97
- });
93
+ return (props) => {
94
+ const runner = api.useHookRunners();
95
+ const routes = runner.modifyRoutes(originRoutes);
96
+ routesConfig.routes = routes;
97
+ return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.Router, {
98
+ history,
99
+ children: createRoutes ? /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
100
+ ...props,
101
+ Component: createRoutes()
102
+ }) : /* @__PURE__ */ (0, _jsxruntime.jsx)(App, {
103
+ ...props,
104
+ children: (0, _utils.renderRoutes)(routesConfig, props)
105
+ })
106
+ });
107
+ };
98
108
  }
99
109
  return (props) => {
100
110
  const runtimeContext = (0, _react.useContext)(_runtime.RuntimeReactContext);
@@ -104,6 +114,10 @@ const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5His
104
114
  const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
105
115
  const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
106
116
  const basename = baseUrl === "/" ? (0, _utils.urlJoin)(baseUrl, historyOptions.basename) : baseUrl;
117
+ const runner = api.useHookRunners();
118
+ const routes = runner.modifyRoutes(originRoutes);
119
+ routesConfig.routes = routes;
120
+ console.log("originRoutes111111111", originRoutes);
107
121
  return /* @__PURE__ */ (0, _jsxruntime.jsx)(_reactrouterdom.StaticRouter, {
108
122
  basename: basename === "/" ? "" : basename,
109
123
  location: location1,
@@ -0,0 +1,3 @@
1
+ import { createWaterfall } from "@modern-js/plugin";
2
+ var modifyRoutesHook = createWaterfall();
3
+ export { modifyRoutesHook };
@@ -58,8 +58,10 @@ import hoistNonReactStatics from "hoist-non-react-statics";
58
58
  import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
59
59
  import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
60
60
  import { renderRoutes, getLocation, urlJoin } from "./utils";
61
+ import { modifyRoutesHook } from "./hooks";
61
62
  export var routerPlugin = function(param) {
62
63
  var _param_serverBase = param.serverBase, serverBase = _param_serverBase === void 0 ? [] : _param_serverBase, customHistory = param.history, _param_supportHtml5History = param.supportHtml5History, supportHtml5History = _param_supportHtml5History === void 0 ? true : _param_supportHtml5History, routesConfig = param.routesConfig, createRoutes = param.createRoutes, _param_historyOptions = param.historyOptions, historyOptions = _param_historyOptions === void 0 ? {} : _param_historyOptions;
64
+ var originRoutes = routesConfig.routes;
63
65
  var isBrow = isBrowser();
64
66
  var select = function(pathname) {
65
67
  return serverBase.find(function(baseUrl) {
@@ -71,7 +73,10 @@ export var routerPlugin = function(param) {
71
73
  }
72
74
  return {
73
75
  name: "@modern-js/plugin-router",
74
- setup: function() {
76
+ registerHook: {
77
+ modifyRoutes: modifyRoutesHook
78
+ },
79
+ setup: function(api) {
75
80
  return {
76
81
  init: function init(param2, next) {
77
82
  var context = param2.context;
@@ -92,6 +97,9 @@ export var routerPlugin = function(param) {
92
97
  historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
93
98
  var history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
94
99
  return function(props) {
100
+ var runner = api.useHookRunners();
101
+ var routes = runner.modifyRoutes(originRoutes);
102
+ routesConfig.routes = routes;
95
103
  return /* @__PURE__ */ _jsx(Router, {
96
104
  history: history,
97
105
  children: createRoutes ? /* @__PURE__ */ _jsx(App, _object_spread_props(_object_spread({}, props), {
@@ -110,6 +118,10 @@ export var routerPlugin = function(param) {
110
118
  var request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
111
119
  var baseUrl2 = request === null || request === void 0 ? void 0 : request.baseUrl;
112
120
  var basename = baseUrl2 === "/" ? urlJoin(baseUrl2, historyOptions.basename) : baseUrl2;
121
+ var runner = api.useHookRunners();
122
+ var routes = runner.modifyRoutes(originRoutes);
123
+ routesConfig.routes = routes;
124
+ console.log("originRoutes111111111", originRoutes);
113
125
  return /* @__PURE__ */ _jsx(StaticRouter, {
114
126
  basename: basename === "/" ? "" : basename,
115
127
  location: _$location,
@@ -0,0 +1,3 @@
1
+ import { createWaterfall } from "@modern-js/plugin";
2
+ const modifyRoutesHook = createWaterfall();
3
+ export { modifyRoutesHook };
@@ -6,7 +6,9 @@ import hoistNonReactStatics from "hoist-non-react-statics";
6
6
  import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
7
7
  import { parsedJSONFromElement } from "@modern-js/utils/runtime-browser";
8
8
  import { renderRoutes, getLocation, urlJoin } from "./utils";
9
+ import { modifyRoutesHook } from "./hooks";
9
10
  export const routerPlugin = ({ serverBase = [], history: customHistory, supportHtml5History = true, routesConfig, createRoutes, historyOptions = {} }) => {
11
+ const { routes: originRoutes } = routesConfig;
10
12
  const isBrow = isBrowser();
11
13
  const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
12
14
  if (isBrow) {
@@ -14,7 +16,10 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
14
16
  }
15
17
  return {
16
18
  name: "@modern-js/plugin-router",
17
- setup: () => {
19
+ registerHook: {
20
+ modifyRoutes: modifyRoutesHook
21
+ },
22
+ setup: (api) => {
18
23
  return {
19
24
  init({ context }, next) {
20
25
  context.router = {
@@ -32,16 +37,21 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
32
37
  const baseUrl = ((_window__SERVER_DATA = window._SERVER_DATA) === null || _window__SERVER_DATA === void 0 ? void 0 : _window__SERVER_DATA.router.baseUrl) || select(location.pathname);
33
38
  historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
34
39
  const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
35
- return (props) => /* @__PURE__ */ _jsx(Router, {
36
- history,
37
- children: createRoutes ? /* @__PURE__ */ _jsx(App, {
38
- ...props,
39
- Component: createRoutes()
40
- }) : /* @__PURE__ */ _jsx(App, {
41
- ...props,
42
- children: renderRoutes(routesConfig, props)
43
- })
44
- });
40
+ return (props) => {
41
+ const runner = api.useHookRunners();
42
+ const routes = runner.modifyRoutes(originRoutes);
43
+ routesConfig.routes = routes;
44
+ return /* @__PURE__ */ _jsx(Router, {
45
+ history,
46
+ children: createRoutes ? /* @__PURE__ */ _jsx(App, {
47
+ ...props,
48
+ Component: createRoutes()
49
+ }) : /* @__PURE__ */ _jsx(App, {
50
+ ...props,
51
+ children: renderRoutes(routesConfig, props)
52
+ })
53
+ });
54
+ };
45
55
  }
46
56
  return (props) => {
47
57
  const runtimeContext = useContext(RuntimeReactContext);
@@ -51,6 +61,10 @@ export const routerPlugin = ({ serverBase = [], history: customHistory, supportH
51
61
  const request = ssrContext === null || ssrContext === void 0 ? void 0 : ssrContext.request;
52
62
  const baseUrl = request === null || request === void 0 ? void 0 : request.baseUrl;
53
63
  const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
64
+ const runner = api.useHookRunners();
65
+ const routes = runner.modifyRoutes(originRoutes);
66
+ routesConfig.routes = routes;
67
+ console.log("originRoutes111111111", originRoutes);
54
68
  return /* @__PURE__ */ _jsx(StaticRouter, {
55
69
  basename: basename === "/" ? "" : basename,
56
70
  location: location1,
@@ -0,0 +1,128 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import {
21
+ getEntryOptions,
22
+ createRuntimeExportsUtils,
23
+ PLUGIN_SCHEMAS
24
+ } from "@modern-js/utils";
25
+ import "./types";
26
+ const PLUGIN_IDENTIFIER = "router";
27
+ const ROUTES_IDENTIFIER = "routes";
28
+ const isV5 = (config) => {
29
+ var _a, _b, _c;
30
+ return typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
31
+ };
32
+ var cli_default = () => ({
33
+ name: "@modern-js/plugin-router-v5",
34
+ required: ["@modern-js/runtime"],
35
+ setup: (api) => {
36
+ const runtimeConfigMap = /* @__PURE__ */ new Map();
37
+ let pluginsExportsUtils;
38
+ let routerExportsUtils;
39
+ return {
40
+ config() {
41
+ const appContext = api.useAppContext();
42
+ pluginsExportsUtils = createRuntimeExportsUtils(
43
+ appContext.internalDirectory,
44
+ "plugins"
45
+ );
46
+ routerExportsUtils = createRuntimeExportsUtils(
47
+ appContext.internalDirectory,
48
+ "router"
49
+ );
50
+ return {
51
+ source: {
52
+ alias: {
53
+ "@modern-js/runtime/plugins": pluginsExportsUtils.getPath(),
54
+ "@modern-js/runtime/router-v5": routerExportsUtils.getPath()
55
+ }
56
+ }
57
+ };
58
+ },
59
+ validateSchema() {
60
+ return PLUGIN_SCHEMAS["@modern-js/plugin-router"];
61
+ },
62
+ modifyEntryImports({ entrypoint, imports }) {
63
+ const { entryName } = entrypoint;
64
+ const userConfig = api.useResolvedConfigContext();
65
+ const { packageName } = api.useAppContext();
66
+ const runtimeConfig = getEntryOptions(
67
+ entryName,
68
+ userConfig.runtime,
69
+ userConfig.runtimeByEntries,
70
+ packageName
71
+ );
72
+ runtimeConfigMap.set(entryName, runtimeConfig);
73
+ if (isV5(userConfig)) {
74
+ imports.push({
75
+ value: "@modern-js/runtime/plugins",
76
+ specifiers: [{ imported: PLUGIN_IDENTIFIER }]
77
+ });
78
+ } else {
79
+ throw new Error(
80
+ `should enable runtime.router.mode for entry ${entryName}`
81
+ );
82
+ }
83
+ return {
84
+ entrypoint,
85
+ imports
86
+ };
87
+ },
88
+ modifyEntryRuntimePlugins({ entrypoint, plugins }) {
89
+ const { entryName, fileSystemRoutes } = entrypoint;
90
+ const { serverRoutes } = api.useAppContext();
91
+ const runtimeConfig = runtimeConfigMap.get(entryName);
92
+ const userConfig = api.useResolvedConfigContext();
93
+ if (isV5(userConfig)) {
94
+ const serverBase = serverRoutes.filter((route) => route.entryName === entryName).map((route) => route.urlPath).sort((a, b) => a.length - b.length > 0 ? -1 : 1);
95
+ plugins.push({
96
+ name: PLUGIN_IDENTIFIER,
97
+ options: JSON.stringify(__spreadProps(__spreadValues({
98
+ serverBase
99
+ }, runtimeConfig.router), {
100
+ routesConfig: fileSystemRoutes ? `{ ${ROUTES_IDENTIFIER}, globalApp: App }` : void 0
101
+ })).replace(
102
+ /"routesConfig"\s*:\s*"((\S|\s)+)"/g,
103
+ '"routesConfig": $1,'
104
+ )
105
+ });
106
+ }
107
+ return {
108
+ entrypoint,
109
+ plugins
110
+ };
111
+ },
112
+ addRuntimeExports() {
113
+ const userConfig = api.useResolvedConfigContext();
114
+ if (isV5(userConfig)) {
115
+ pluginsExportsUtils.addExport(
116
+ `export { default as router } from '@modern-js/plugin-router-v5/runtime'`
117
+ );
118
+ routerExportsUtils == null ? void 0 : routerExportsUtils.addExport(
119
+ `export * from '@modern-js/plugin-router-v5/runtime'`
120
+ );
121
+ }
122
+ }
123
+ };
124
+ }
125
+ });
126
+ export {
127
+ cli_default as default
128
+ };
File without changes
@@ -0,0 +1,5 @@
1
+ import { default as default2 } from "./runtime";
2
+ export * from "./runtime";
3
+ export {
4
+ default2 as default
5
+ };
@@ -0,0 +1,14 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ const DefaultNotFound = () => /* @__PURE__ */ jsx("div", {
3
+ style: {
4
+ margin: "150px auto",
5
+ textAlign: "center",
6
+ display: "flex",
7
+ alignItems: "center",
8
+ justifyContent: "center"
9
+ },
10
+ children: "404"
11
+ });
12
+ export {
13
+ DefaultNotFound
14
+ };
@@ -0,0 +1,7 @@
1
+ import { routerPlugin } from "./plugin";
2
+ var runtime_default = routerPlugin;
3
+ export * from "react-router-dom";
4
+ export * from "history";
5
+ export {
6
+ runtime_default as default
7
+ };
@@ -0,0 +1,106 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { jsx } from "react/jsx-runtime";
21
+ import { useContext } from "react";
22
+ import {
23
+ createBrowserHistory,
24
+ createHashHistory
25
+ } from "history";
26
+ import {
27
+ Router,
28
+ StaticRouter,
29
+ useRouteMatch,
30
+ useLocation
31
+ } from "react-router-dom";
32
+ import hoistNonReactStatics from "hoist-non-react-statics";
33
+ import { RuntimeReactContext, isBrowser } from "@modern-js/runtime";
34
+ import { renderRoutes, getLocation, urlJoin } from "./utils";
35
+ const routerPlugin = ({
36
+ serverBase = [],
37
+ history: customHistory,
38
+ supportHtml5History = true,
39
+ routesConfig,
40
+ historyOptions = {}
41
+ }) => {
42
+ const isBrow = isBrowser();
43
+ const select = (pathname) => serverBase.find((baseUrl) => pathname.search(baseUrl) === 0) || "/";
44
+ return {
45
+ name: "@modern-js/plugin-router",
46
+ setup: () => {
47
+ return {
48
+ init({ context }, next) {
49
+ context.router = {
50
+ useRouteMatch,
51
+ useLocation
52
+ };
53
+ return next({ context });
54
+ },
55
+ hoc: ({ App }, next) => {
56
+ const getRouteApp = () => {
57
+ var _a;
58
+ if (isBrow) {
59
+ const baseUrl = ((_a = window._SERVER_DATA) == null ? void 0 : _a.router.baseUrl) || select(location.pathname);
60
+ historyOptions.basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
61
+ const history = customHistory || (supportHtml5History ? createBrowserHistory(historyOptions) : createHashHistory(historyOptions));
62
+ return (props) => /* @__PURE__ */ jsx(Router, {
63
+ history,
64
+ children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
65
+ children: routesConfig ? renderRoutes(routesConfig, props) : null
66
+ }))
67
+ });
68
+ }
69
+ return (props) => {
70
+ const runtimeContext = useContext(RuntimeReactContext);
71
+ const { ssrContext } = runtimeContext;
72
+ const location2 = getLocation(ssrContext);
73
+ const routerContext = (ssrContext == null ? void 0 : ssrContext.redirection) || {};
74
+ const request = ssrContext == null ? void 0 : ssrContext.request;
75
+ const baseUrl = request == null ? void 0 : request.baseUrl;
76
+ const basename = baseUrl === "/" ? urlJoin(baseUrl, historyOptions.basename) : baseUrl;
77
+ return /* @__PURE__ */ jsx(StaticRouter, {
78
+ basename: basename === "/" ? "" : basename,
79
+ location: location2,
80
+ context: routerContext,
81
+ children: /* @__PURE__ */ jsx(App, __spreadProps(__spreadValues({}, props), {
82
+ children: routesConfig ? renderRoutes(routesConfig, props) : null
83
+ }))
84
+ });
85
+ };
86
+ };
87
+ let RouteApp = getRouteApp();
88
+ if (App) {
89
+ RouteApp = hoistNonReactStatics(RouteApp, App);
90
+ }
91
+ if (routesConfig == null ? void 0 : routesConfig.globalApp) {
92
+ return next({
93
+ App: hoistNonReactStatics(RouteApp, routesConfig.globalApp)
94
+ });
95
+ }
96
+ return next({
97
+ App: RouteApp
98
+ });
99
+ }
100
+ };
101
+ }
102
+ };
103
+ };
104
+ export {
105
+ routerPlugin
106
+ };
@@ -0,0 +1,108 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __objRest = (source, exclude) => {
18
+ var target = {};
19
+ for (var prop in source)
20
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
21
+ target[prop] = source[prop];
22
+ if (source != null && __getOwnPropSymbols)
23
+ for (var prop of __getOwnPropSymbols(source)) {
24
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
25
+ target[prop] = source[prop];
26
+ }
27
+ return target;
28
+ };
29
+ import { jsx } from "react/jsx-runtime";
30
+ import { Route, matchPath } from "react-router-dom";
31
+ import { DefaultNotFound } from "./DefaultNotFound";
32
+ function renderRoutes(routesConfig, extraProps = {}) {
33
+ const Layout = (_a) => {
34
+ var _b = _a, { Component } = _b, props = __objRest(_b, ["Component"]);
35
+ const GlobalLayout = routesConfig == null ? void 0 : routesConfig.globalApp;
36
+ if (!GlobalLayout) {
37
+ return /* @__PURE__ */ jsx(Component, __spreadValues({}, props));
38
+ }
39
+ return /* @__PURE__ */ jsx(GlobalLayout, __spreadValues({
40
+ Component
41
+ }, props));
42
+ };
43
+ const findMatchedRoute = (pathname) => {
44
+ var _a;
45
+ return (_a = routesConfig == null ? void 0 : routesConfig.routes) == null ? void 0 : _a.find((route) => {
46
+ const info = matchPath(pathname, {
47
+ path: route.path,
48
+ exact: route.exact,
49
+ sensitive: route.sensitive
50
+ });
51
+ return Boolean(info);
52
+ });
53
+ };
54
+ return /* @__PURE__ */ jsx(Route, {
55
+ path: "/",
56
+ render: (props) => {
57
+ const matchedRoute = findMatchedRoute(props.location.pathname);
58
+ if (!matchedRoute) {
59
+ return /* @__PURE__ */ jsx(DefaultNotFound, {});
60
+ }
61
+ return /* @__PURE__ */ jsx(Route, {
62
+ path: matchedRoute.path,
63
+ exact: matchedRoute.exact,
64
+ sensitive: matchedRoute.sensitive,
65
+ render: (routeProps) => /* @__PURE__ */ jsx(Layout, __spreadValues(__spreadValues({
66
+ Component: matchedRoute.component
67
+ }, routeProps), extraProps))
68
+ });
69
+ }
70
+ });
71
+ }
72
+ function getLocation(serverContext) {
73
+ var _a;
74
+ const { pathname, url } = (serverContext == null ? void 0 : serverContext.request) || {};
75
+ const cleanUrl = (_a = url == null ? void 0 : url.replace("http://", "")) == null ? void 0 : _a.replace("https://", "");
76
+ const index = (cleanUrl || "").indexOf(pathname);
77
+ if (index === -1) {
78
+ return pathname;
79
+ }
80
+ return cleanUrl.substring(index);
81
+ }
82
+ const urlJoin = (...parts) => {
83
+ const separator = "/";
84
+ const replace = new RegExp(`${separator}{1,}`, "g");
85
+ return standardSlash(parts.join(separator).replace(replace, separator));
86
+ };
87
+ function standardSlash(str) {
88
+ let addr = str;
89
+ if (!addr || typeof addr !== "string") {
90
+ return addr;
91
+ }
92
+ if (addr.startsWith(".")) {
93
+ addr = addr.slice(1);
94
+ }
95
+ if (!addr.startsWith("/")) {
96
+ addr = `/${addr}`;
97
+ }
98
+ if (addr.endsWith("/") && addr !== "/") {
99
+ addr = addr.slice(0, addr.length - 1);
100
+ }
101
+ return addr;
102
+ }
103
+ export {
104
+ getLocation,
105
+ renderRoutes,
106
+ standardSlash,
107
+ urlJoin
108
+ };