@xfe-repo/web-router 1.1.3 → 1.1.5
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/dist/index.d.mts +7 -5
- package/dist/index.d.ts +7 -5
- package/dist/index.js +18 -6
- package/dist/index.mjs +11 -7
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -3,6 +3,7 @@ import { LoadableComponent, loadableReady } from '@loadable/component';
|
|
|
3
3
|
import { ParsedQuery } from 'query-string';
|
|
4
4
|
import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
|
|
5
5
|
import { RegisterComponentStatic } from '@xfe-repo/web-register';
|
|
6
|
+
import { LinkProps as LinkProps$1 } from 'react-router-dom';
|
|
6
7
|
export * from 'react-router-dom';
|
|
7
8
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
9
|
|
|
@@ -13,9 +14,12 @@ type RouteConfig = {
|
|
|
13
14
|
};
|
|
14
15
|
type GetRoutesConfig = {
|
|
15
16
|
pagesIndexPath: string[];
|
|
17
|
+
getRoutePath?: (path: string) => string;
|
|
16
18
|
getPageComponents: (path: string) => Promise<any>;
|
|
17
19
|
fallback?: ReactElement;
|
|
18
20
|
};
|
|
21
|
+
declare const routerIndexRegx: RegExp;
|
|
22
|
+
declare const routerDynamicRegx: RegExp;
|
|
19
23
|
declare const getRoutes: (config: GetRoutesConfig) => RouteConfig[];
|
|
20
24
|
|
|
21
25
|
type RouterProps = PropsWithChildren<{
|
|
@@ -26,13 +30,11 @@ type RouterProps = PropsWithChildren<{
|
|
|
26
30
|
}>;
|
|
27
31
|
declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_jsx_runtime.JSX.Element>;
|
|
28
32
|
|
|
29
|
-
type LinkProps =
|
|
33
|
+
type LinkProps = Omit<LinkProps$1, 'to'> & {
|
|
30
34
|
to: string;
|
|
31
35
|
reLaunch?: boolean;
|
|
32
|
-
replace?: boolean;
|
|
33
36
|
preload?: boolean;
|
|
34
|
-
|
|
35
|
-
}>;
|
|
37
|
+
};
|
|
36
38
|
declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
|
|
37
39
|
|
|
38
40
|
type NavigatorStack = {
|
|
@@ -54,4 +56,4 @@ declare function createNavigator(options: CreateNavigatorOptions): NavigatorType
|
|
|
54
56
|
declare const getClientNavigator: () => NavigatorType;
|
|
55
57
|
declare const routerReady: typeof loadableReady;
|
|
56
58
|
|
|
57
|
-
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorStack, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerReady };
|
|
59
|
+
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorStack, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { LoadableComponent, loadableReady } from '@loadable/component';
|
|
|
3
3
|
import { ParsedQuery } from 'query-string';
|
|
4
4
|
import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
|
|
5
5
|
import { RegisterComponentStatic } from '@xfe-repo/web-register';
|
|
6
|
+
import { LinkProps as LinkProps$1 } from 'react-router-dom';
|
|
6
7
|
export * from 'react-router-dom';
|
|
7
8
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
8
9
|
|
|
@@ -13,9 +14,12 @@ type RouteConfig = {
|
|
|
13
14
|
};
|
|
14
15
|
type GetRoutesConfig = {
|
|
15
16
|
pagesIndexPath: string[];
|
|
17
|
+
getRoutePath?: (path: string) => string;
|
|
16
18
|
getPageComponents: (path: string) => Promise<any>;
|
|
17
19
|
fallback?: ReactElement;
|
|
18
20
|
};
|
|
21
|
+
declare const routerIndexRegx: RegExp;
|
|
22
|
+
declare const routerDynamicRegx: RegExp;
|
|
19
23
|
declare const getRoutes: (config: GetRoutesConfig) => RouteConfig[];
|
|
20
24
|
|
|
21
25
|
type RouterProps = PropsWithChildren<{
|
|
@@ -26,13 +30,11 @@ type RouterProps = PropsWithChildren<{
|
|
|
26
30
|
}>;
|
|
27
31
|
declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_jsx_runtime.JSX.Element>;
|
|
28
32
|
|
|
29
|
-
type LinkProps =
|
|
33
|
+
type LinkProps = Omit<LinkProps$1, 'to'> & {
|
|
30
34
|
to: string;
|
|
31
35
|
reLaunch?: boolean;
|
|
32
|
-
replace?: boolean;
|
|
33
36
|
preload?: boolean;
|
|
34
|
-
|
|
35
|
-
}>;
|
|
37
|
+
};
|
|
36
38
|
declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
|
|
37
39
|
|
|
38
40
|
type NavigatorStack = {
|
|
@@ -54,4 +56,4 @@ declare function createNavigator(options: CreateNavigatorOptions): NavigatorType
|
|
|
54
56
|
declare const getClientNavigator: () => NavigatorType;
|
|
55
57
|
declare const routerReady: typeof loadableReady;
|
|
56
58
|
|
|
57
|
-
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorStack, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerReady };
|
|
59
|
+
export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorStack, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
|
package/dist/index.js
CHANGED
|
@@ -276,6 +276,12 @@ __export(src_exports, {
|
|
|
276
276
|
getRoutes: function() {
|
|
277
277
|
return getRoutes;
|
|
278
278
|
},
|
|
279
|
+
routerDynamicRegx: function() {
|
|
280
|
+
return routerDynamicRegx;
|
|
281
|
+
},
|
|
282
|
+
routerIndexRegx: function() {
|
|
283
|
+
return routerIndexRegx;
|
|
284
|
+
},
|
|
279
285
|
routerReady: function() {
|
|
280
286
|
return routerReady;
|
|
281
287
|
}
|
|
@@ -289,26 +295,30 @@ var import_env = require("@xfe-repo/web-utils/env");
|
|
|
289
295
|
__reExport(src_exports, require("react-router-dom"), module.exports);
|
|
290
296
|
// src/routes.ts
|
|
291
297
|
var import_component = __toESM(require("@loadable/component"));
|
|
298
|
+
var routerIndexRegx = /^(?!.*component)(.*)?\/index(\[[^.]+])?\.(ts|js)x?$/;
|
|
299
|
+
var routerDynamicRegx = /\[([^.]+)]/;
|
|
292
300
|
var getRoutes = function(config) {
|
|
293
|
-
var pagesIndexPath = config.pagesIndexPath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
301
|
+
var pagesIndexPath = config.pagesIndexPath, getRoutePath = config.getRoutePath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
294
302
|
var routes = [];
|
|
295
303
|
pagesIndexPath.forEach(function(pageIndexPath) {
|
|
304
|
+
var _pageIndexPath_match;
|
|
296
305
|
if (pageIndexPath.startsWith("./")) return;
|
|
297
|
-
var regExpResult = pageIndexPath.match(RegExp("(?<=pages\\/).*(?=\\/index.(?:tsx|js))"));
|
|
298
|
-
var pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
|
|
299
306
|
var pageComponent = (0, import_component.default)(function() {
|
|
300
|
-
return getPageComponents(
|
|
307
|
+
return getPageComponents(pageIndexPath);
|
|
301
308
|
}, {
|
|
302
309
|
fallback: fallback
|
|
303
310
|
});
|
|
304
|
-
var routerPath = "
|
|
305
|
-
if (routerPath === "
|
|
311
|
+
var routerPath = getRoutePath ? getRoutePath(pageIndexPath) : pageIndexPath.replace(routerIndexRegx, "$1");
|
|
312
|
+
if (routerPath === "home" || routerPath === "index") routerPath = "/";
|
|
313
|
+
var dynamicRoute = ((_pageIndexPath_match = pageIndexPath.match(routerDynamicRegx)) === null || _pageIndexPath_match === void 0 ? void 0 : _pageIndexPath_match[1]) || "";
|
|
314
|
+
if (dynamicRoute) routerPath = "".concat(routerPath, "/").concat(dynamicRoute);
|
|
306
315
|
var config2 = {
|
|
307
316
|
path: routerPath,
|
|
308
317
|
Component: pageComponent
|
|
309
318
|
};
|
|
310
319
|
routes.push(config2);
|
|
311
320
|
});
|
|
321
|
+
console.log("routes", routes);
|
|
312
322
|
return routes;
|
|
313
323
|
};
|
|
314
324
|
// src/Router.tsx
|
|
@@ -542,5 +552,7 @@ var routerReady = import_component2.loadableReady;
|
|
|
542
552
|
createNavigator: createNavigator,
|
|
543
553
|
getClientNavigator: getClientNavigator,
|
|
544
554
|
getRoutes: getRoutes,
|
|
555
|
+
routerDynamicRegx: routerDynamicRegx,
|
|
556
|
+
routerIndexRegx: routerIndexRegx,
|
|
545
557
|
routerReady: routerReady
|
|
546
558
|
}, require("react-router-dom")));
|
package/dist/index.mjs
CHANGED
|
@@ -205,26 +205,30 @@ import { isProduction } from "@xfe-repo/web-utils/env";
|
|
|
205
205
|
export * from "react-router-dom";
|
|
206
206
|
// src/routes.ts
|
|
207
207
|
import loadable from "@loadable/component";
|
|
208
|
+
var routerIndexRegx = /^(?!.*component)(.*)?\/index(\[[^.]+])?\.(ts|js)x?$/;
|
|
209
|
+
var routerDynamicRegx = /\[([^.]+)]/;
|
|
208
210
|
var getRoutes = function(config) {
|
|
209
|
-
var pagesIndexPath = config.pagesIndexPath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
211
|
+
var pagesIndexPath = config.pagesIndexPath, getRoutePath = config.getRoutePath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
210
212
|
var routes = [];
|
|
211
213
|
pagesIndexPath.forEach(function(pageIndexPath) {
|
|
214
|
+
var _pageIndexPath_match;
|
|
212
215
|
if (pageIndexPath.startsWith("./")) return;
|
|
213
|
-
var regExpResult = pageIndexPath.match(RegExp("(?<=pages\\/).*(?=\\/index.(?:tsx|js))"));
|
|
214
|
-
var pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
|
|
215
216
|
var pageComponent = loadable(function() {
|
|
216
|
-
return getPageComponents(
|
|
217
|
+
return getPageComponents(pageIndexPath);
|
|
217
218
|
}, {
|
|
218
219
|
fallback: fallback
|
|
219
220
|
});
|
|
220
|
-
var routerPath = "
|
|
221
|
-
if (routerPath === "
|
|
221
|
+
var routerPath = getRoutePath ? getRoutePath(pageIndexPath) : pageIndexPath.replace(routerIndexRegx, "$1");
|
|
222
|
+
if (routerPath === "home" || routerPath === "index") routerPath = "/";
|
|
223
|
+
var dynamicRoute = ((_pageIndexPath_match = pageIndexPath.match(routerDynamicRegx)) === null || _pageIndexPath_match === void 0 ? void 0 : _pageIndexPath_match[1]) || "";
|
|
224
|
+
if (dynamicRoute) routerPath = "".concat(routerPath, "/").concat(dynamicRoute);
|
|
222
225
|
var config2 = {
|
|
223
226
|
path: routerPath,
|
|
224
227
|
Component: pageComponent
|
|
225
228
|
};
|
|
226
229
|
routes.push(config2);
|
|
227
230
|
});
|
|
231
|
+
console.log("routes", routes);
|
|
228
232
|
return routes;
|
|
229
233
|
};
|
|
230
234
|
// src/Router.tsx
|
|
@@ -451,4 +455,4 @@ var getClientNavigator = function() {
|
|
|
451
455
|
return _navigator;
|
|
452
456
|
};
|
|
453
457
|
var routerReady = loadableReady;
|
|
454
|
-
export { Link, Router, createNavigator, getClientNavigator, getRoutes, routerReady };
|
|
458
|
+
export { Link, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xfe-repo/web-router",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.5",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"@types/node": "^20.16.5",
|
|
32
32
|
"@types/react": "^18",
|
|
33
33
|
"@xfe-repo/eslint-config": "0.0.4",
|
|
34
|
-
"@xfe-repo/
|
|
35
|
-
"@xfe-repo/
|
|
34
|
+
"@xfe-repo/typescript-config": "0.0.6",
|
|
35
|
+
"@xfe-repo/web-register": "1.1.3"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "tsup",
|