@xfe-repo/web-router 1.1.0 → 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 +20 -7
- package/dist/index.mjs +13 -8
- package/package.json +6 -5
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
|
}
|
|
@@ -285,29 +291,34 @@ var import_history = require("history");
|
|
|
285
291
|
var import_component2 = require("@loadable/component");
|
|
286
292
|
var import_react_router_dom3 = require("react-router-dom");
|
|
287
293
|
var import_query_string = __toESM(require("query-string"));
|
|
294
|
+
var import_env = require("@xfe-repo/web-utils/env");
|
|
288
295
|
__reExport(src_exports, require("react-router-dom"), module.exports);
|
|
289
296
|
// src/routes.ts
|
|
290
297
|
var import_component = __toESM(require("@loadable/component"));
|
|
298
|
+
var routerIndexRegx = /^(?!.*component)(.*)?\/index(\[[^.]+])?\.(ts|js)x?$/;
|
|
299
|
+
var routerDynamicRegx = /\[([^.]+)]/;
|
|
291
300
|
var getRoutes = function(config) {
|
|
292
|
-
var pagesIndexPath = config.pagesIndexPath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
301
|
+
var pagesIndexPath = config.pagesIndexPath, getRoutePath = config.getRoutePath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
293
302
|
var routes = [];
|
|
294
303
|
pagesIndexPath.forEach(function(pageIndexPath) {
|
|
304
|
+
var _pageIndexPath_match;
|
|
295
305
|
if (pageIndexPath.startsWith("./")) return;
|
|
296
|
-
var regExpResult = pageIndexPath.match(RegExp("(?<=pages\\/).*(?=\\/index.(?:tsx|js))"));
|
|
297
|
-
var pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
|
|
298
306
|
var pageComponent = (0, import_component.default)(function() {
|
|
299
|
-
return getPageComponents(
|
|
307
|
+
return getPageComponents(pageIndexPath);
|
|
300
308
|
}, {
|
|
301
309
|
fallback: fallback
|
|
302
310
|
});
|
|
303
|
-
var routerPath = "
|
|
304
|
-
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);
|
|
305
315
|
var config2 = {
|
|
306
316
|
path: routerPath,
|
|
307
317
|
Component: pageComponent
|
|
308
318
|
};
|
|
309
319
|
routes.push(config2);
|
|
310
320
|
});
|
|
321
|
+
console.log("routes", routes);
|
|
311
322
|
return routes;
|
|
312
323
|
};
|
|
313
324
|
// src/Router.tsx
|
|
@@ -454,7 +465,7 @@ function createNavigator(options) {
|
|
|
454
465
|
} else if (action === "POP") {
|
|
455
466
|
stack.pop();
|
|
456
467
|
}
|
|
457
|
-
console.log("router", action, pathname, stack);
|
|
468
|
+
if (!import_env.isProduction) console.log("router", action, pathname, stack);
|
|
458
469
|
});
|
|
459
470
|
_navigator.reLaunch = function(path, state) {
|
|
460
471
|
var _stack_;
|
|
@@ -541,5 +552,7 @@ var routerReady = import_component2.loadableReady;
|
|
|
541
552
|
createNavigator: createNavigator,
|
|
542
553
|
getClientNavigator: getClientNavigator,
|
|
543
554
|
getRoutes: getRoutes,
|
|
555
|
+
routerDynamicRegx: routerDynamicRegx,
|
|
556
|
+
routerIndexRegx: routerIndexRegx,
|
|
544
557
|
routerReady: routerReady
|
|
545
558
|
}, require("react-router-dom")));
|
package/dist/index.mjs
CHANGED
|
@@ -201,29 +201,34 @@ import { createHashHistory, createBrowserHistory, createMemoryHistory } from "hi
|
|
|
201
201
|
import { loadableReady } from "@loadable/component";
|
|
202
202
|
import { matchRoutes } from "react-router-dom";
|
|
203
203
|
import queryString from "query-string";
|
|
204
|
+
import { isProduction } from "@xfe-repo/web-utils/env";
|
|
204
205
|
export * from "react-router-dom";
|
|
205
206
|
// src/routes.ts
|
|
206
207
|
import loadable from "@loadable/component";
|
|
208
|
+
var routerIndexRegx = /^(?!.*component)(.*)?\/index(\[[^.]+])?\.(ts|js)x?$/;
|
|
209
|
+
var routerDynamicRegx = /\[([^.]+)]/;
|
|
207
210
|
var getRoutes = function(config) {
|
|
208
|
-
var pagesIndexPath = config.pagesIndexPath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
211
|
+
var pagesIndexPath = config.pagesIndexPath, getRoutePath = config.getRoutePath, getPageComponents = config.getPageComponents, fallback = config.fallback;
|
|
209
212
|
var routes = [];
|
|
210
213
|
pagesIndexPath.forEach(function(pageIndexPath) {
|
|
214
|
+
var _pageIndexPath_match;
|
|
211
215
|
if (pageIndexPath.startsWith("./")) return;
|
|
212
|
-
var regExpResult = pageIndexPath.match(RegExp("(?<=pages\\/).*(?=\\/index.(?:tsx|js))"));
|
|
213
|
-
var pageRelativePath = regExpResult ? regExpResult[0].toLowerCase() : "";
|
|
214
216
|
var pageComponent = loadable(function() {
|
|
215
|
-
return getPageComponents(
|
|
217
|
+
return getPageComponents(pageIndexPath);
|
|
216
218
|
}, {
|
|
217
219
|
fallback: fallback
|
|
218
220
|
});
|
|
219
|
-
var routerPath = "
|
|
220
|
-
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);
|
|
221
225
|
var config2 = {
|
|
222
226
|
path: routerPath,
|
|
223
227
|
Component: pageComponent
|
|
224
228
|
};
|
|
225
229
|
routes.push(config2);
|
|
226
230
|
});
|
|
231
|
+
console.log("routes", routes);
|
|
227
232
|
return routes;
|
|
228
233
|
};
|
|
229
234
|
// src/Router.tsx
|
|
@@ -370,7 +375,7 @@ function createNavigator(options) {
|
|
|
370
375
|
} else if (action === "POP") {
|
|
371
376
|
stack.pop();
|
|
372
377
|
}
|
|
373
|
-
console.log("router", action, pathname, stack);
|
|
378
|
+
if (!isProduction) console.log("router", action, pathname, stack);
|
|
374
379
|
});
|
|
375
380
|
_navigator.reLaunch = function(path, state) {
|
|
376
381
|
var _stack_;
|
|
@@ -450,4 +455,4 @@ var getClientNavigator = function() {
|
|
|
450
455
|
return _navigator;
|
|
451
456
|
};
|
|
452
457
|
var routerReady = loadableReady;
|
|
453
|
-
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",
|
|
@@ -23,15 +23,16 @@
|
|
|
23
23
|
"@loadable/component": "^5.16.4",
|
|
24
24
|
"history": "^5.3.0",
|
|
25
25
|
"query-string": "^7.1.3",
|
|
26
|
-
"react-router-dom": "^6.26.2"
|
|
26
|
+
"react-router-dom": "^6.26.2",
|
|
27
|
+
"@xfe-repo/web-utils": "1.1.3"
|
|
27
28
|
},
|
|
28
29
|
"devDependencies": {
|
|
29
30
|
"@types/loadable__component": "^5.13.9",
|
|
30
31
|
"@types/node": "^20.16.5",
|
|
31
32
|
"@types/react": "^18",
|
|
32
|
-
"@xfe-repo/eslint-config": "0.0.
|
|
33
|
-
"@xfe-repo/typescript-config": "0.0.
|
|
34
|
-
"@xfe-repo/web-register": "1.1.
|
|
33
|
+
"@xfe-repo/eslint-config": "0.0.4",
|
|
34
|
+
"@xfe-repo/typescript-config": "0.0.6",
|
|
35
|
+
"@xfe-repo/web-register": "1.1.3"
|
|
35
36
|
},
|
|
36
37
|
"scripts": {
|
|
37
38
|
"build": "tsup",
|