@xfe-repo/web-router 1.2.2 → 1.2.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { History } from 'history';
2
2
  import { LoadableComponent, loadableReady } from '@loadable/component';
3
- import { ParsedQuery } from 'query-string';
3
+ import { ParsedQuery } from '@xfe-repo/web-utils/tools';
4
4
  import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
5
5
  import { RegisterComponentStatic } from '@xfe-repo/web-register';
6
6
  import { LinkProps as LinkProps$1 } from 'react-router-dom';
@@ -32,17 +32,11 @@ declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_js
32
32
 
33
33
  type LinkProps = Omit<LinkProps$1, 'to'> & {
34
34
  to: string;
35
- reLaunch?: boolean;
36
35
  preload?: boolean;
37
36
  };
38
37
  declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
39
38
 
40
- type NavigatorStack = {
41
- pathname: string;
42
- };
43
39
  interface NavigatorType extends History {
44
- stack: NavigatorStack[];
45
- reLaunch: (path: string, state?: any) => void;
46
40
  preload: (path: string, isReplace?: boolean, query?: ParsedQuery<string | number | boolean>) => Promise<void>;
47
41
  leave: (path: string) => void;
48
42
  }
@@ -56,4 +50,4 @@ declare function createNavigator(options: CreateNavigatorOptions): NavigatorType
56
50
  declare const getClientNavigator: () => NavigatorType;
57
51
  declare const routerReady: typeof loadableReady;
58
52
 
59
- export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorStack, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
53
+ export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { History } from 'history';
2
2
  import { LoadableComponent, loadableReady } from '@loadable/component';
3
- import { ParsedQuery } from 'query-string';
3
+ import { ParsedQuery } from '@xfe-repo/web-utils/tools';
4
4
  import React, { ReactElement, PropsWithChildren, ComponentType } from 'react';
5
5
  import { RegisterComponentStatic } from '@xfe-repo/web-register';
6
6
  import { LinkProps as LinkProps$1 } from 'react-router-dom';
@@ -32,17 +32,11 @@ declare const Router: React.MemoExoticComponent<(props: RouterProps) => react_js
32
32
 
33
33
  type LinkProps = Omit<LinkProps$1, 'to'> & {
34
34
  to: string;
35
- reLaunch?: boolean;
36
35
  preload?: boolean;
37
36
  };
38
37
  declare const Link: React.MemoExoticComponent<(props: LinkProps) => react_jsx_runtime.JSX.Element>;
39
38
 
40
- type NavigatorStack = {
41
- pathname: string;
42
- };
43
39
  interface NavigatorType extends History {
44
- stack: NavigatorStack[];
45
- reLaunch: (path: string, state?: any) => void;
46
40
  preload: (path: string, isReplace?: boolean, query?: ParsedQuery<string | number | boolean>) => Promise<void>;
47
41
  leave: (path: string) => void;
48
42
  }
@@ -56,4 +50,4 @@ declare function createNavigator(options: CreateNavigatorOptions): NavigatorType
56
50
  declare const getClientNavigator: () => NavigatorType;
57
51
  declare const routerReady: typeof loadableReady;
58
52
 
59
- export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorStack, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
53
+ export { type CreateNavigatorOptions, type GetRoutesConfig, Link, type NavigatorType, type PageComponent, type RouteConfig, Router, createNavigator, getClientNavigator, getRoutes, routerDynamicRegx, routerIndexRegx, routerReady };
package/dist/index.js CHANGED
@@ -290,8 +290,7 @@ module.exports = __toCommonJS(src_exports);
290
290
  var import_history = require("history");
291
291
  var import_component2 = require("@loadable/component");
292
292
  var import_react_router_dom3 = require("react-router-dom");
293
- var import_query_string = __toESM(require("query-string"));
294
- var import_env = require("@xfe-repo/web-utils/env");
293
+ var import_tools = require("@xfe-repo/web-utils/tools");
295
294
  __reExport(src_exports, require("react-router-dom"), module.exports);
296
295
  // src/routes.ts
297
296
  var import_component = __toESM(require("@loadable/component"));
@@ -366,40 +365,37 @@ var import_react2 = require("react");
366
365
  var import_react_router_dom2 = require("react-router-dom");
367
366
  var import_jsx_runtime2 = require("react/jsx-runtime");
368
367
  var Link = (0, import_react2.memo)(function(props) {
369
- var to = props.to, children = props.children, reLaunch = props.reLaunch, preload = props.preload, replace = props.replace, className = props.className;
368
+ var to = props.to, children = props.children, preload = props.preload, replace = props.replace, className = props.className, target = props.target;
370
369
  var _navigator2 = (0, import_react2.useMemo)(function() {
371
370
  return getClientNavigator();
372
371
  }, []);
373
372
  if (/http(s)?:\/{2}/.test(to)) {
374
373
  var handleLink = function(e) {
374
+ if (e.ctrlKey || e.metaKey) return;
375
375
  e.preventDefault();
376
- window.location.href = to;
376
+ if (target === "_blank") {
377
+ window.open(to);
378
+ } else {
379
+ window.location.href = to;
380
+ }
377
381
  };
378
382
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
379
383
  href: to,
380
384
  onClick: handleLink,
381
385
  className: className,
382
- children: children
383
- });
384
- }
385
- if (reLaunch) {
386
- var handleLink1 = function(e) {
387
- e.preventDefault();
388
- _navigator2.reLaunch(to);
389
- };
390
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
391
- href: to,
392
- onClick: handleLink1,
393
- className: className,
386
+ target: target,
394
387
  children: children
395
388
  });
396
389
  }
397
390
  if (preload) {
398
- var handleLink2 = function() {
391
+ var handleLink1 = function() {
399
392
  var _ref = _async_to_generator(function(e) {
400
393
  return _ts_generator(this, function(_state) {
401
394
  switch(_state.label){
402
395
  case 0:
396
+ if (e.ctrlKey || e.metaKey) return [
397
+ 2
398
+ ];
403
399
  e.preventDefault();
404
400
  return [
405
401
  4,
@@ -413,13 +409,13 @@ var Link = (0, import_react2.memo)(function(props) {
413
409
  }
414
410
  });
415
411
  });
416
- return function handleLink2(e) {
412
+ return function handleLink1(e) {
417
413
  return _ref.apply(this, arguments);
418
414
  };
419
415
  }();
420
416
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("a", {
421
417
  href: to,
422
- onClick: handleLink2,
418
+ onClick: handleLink1,
423
419
  className: className,
424
420
  children: children
425
421
  });
@@ -443,38 +439,6 @@ function createNavigator(options) {
443
439
  originHistory = (0, import_history.createHashHistory)();
444
440
  }
445
441
  _navigator = originHistory;
446
- var initialStack = [
447
- {
448
- pathname: _navigator.location.pathname
449
- }
450
- ];
451
- var stack = _navigator.stack = initialStack;
452
- _navigator.listen(function(param) {
453
- var location = param.location, action = param.action;
454
- var pathname = location.pathname;
455
- if (action === "PUSH") {
456
- stack.push({
457
- pathname: pathname
458
- });
459
- } else if (action === "REPLACE") {
460
- stack.pop();
461
- stack.push({
462
- pathname: pathname
463
- });
464
- } else if (action === "POP") {
465
- stack.pop();
466
- }
467
- if (!import_env.isProduction) console.log("router", action, pathname, stack);
468
- });
469
- _navigator.reLaunch = function(path, state) {
470
- var _stack_;
471
- var shouldBlack = -stack.length + 1;
472
- if (shouldBlack < 0) _navigator.go(shouldBlack);
473
- if (((_stack_ = stack[0]) === null || _stack_ === void 0 ? void 0 : _stack_.pathname) === path) return;
474
- setTimeout(function() {
475
- _navigator.replace(path, state);
476
- }, 1);
477
- };
478
442
  _navigator.preload = function() {
479
443
  var _ref = _async_to_generator(function(path, isReplace, query) {
480
444
  var _, _this, _path_split, tmp, originPath, tmp1, search, matchPath, currentRoute, _pageModule_default_emitOnLoad, _pageModule_default, pageModule, _currentRoute_Component_emitOnLoad, _currentRoute_Component;
@@ -484,7 +448,7 @@ function createNavigator(options) {
484
448
  _path_split = _sliced_to_array(path.split("?"), 2), tmp = _path_split[0], originPath = tmp === void 0 ? "" : tmp, tmp1 = _path_split[1], search = tmp1 === void 0 ? "" : tmp1;
485
449
  matchPath = originPath.toLowerCase();
486
450
  currentRoute = (_this = (0, import_react_router_dom3.matchRoutes)(routes, matchPath)) === null || _this === void 0 ? void 0 : (_ = _this[0]) === null || _ === void 0 ? void 0 : _.route;
487
- query = query || import_query_string.default.parse(search, {
451
+ query = query || import_tools.queryString.parse(search, {
488
452
  parseBooleans: true,
489
453
  parseNumbers: true
490
454
  });
package/dist/index.mjs CHANGED
@@ -200,8 +200,7 @@ function _ts_generator(thisArg, body) {
200
200
  import { createHashHistory, createBrowserHistory, createMemoryHistory } from "history";
201
201
  import { loadableReady } from "@loadable/component";
202
202
  import { matchRoutes } from "react-router-dom";
203
- import queryString from "query-string";
204
- import { isProduction } from "@xfe-repo/web-utils/env";
203
+ import { queryString } from "@xfe-repo/web-utils/tools";
205
204
  export * from "react-router-dom";
206
205
  // src/routes.ts
207
206
  import loadable from "@loadable/component";
@@ -276,40 +275,37 @@ import { memo as memo2, useMemo } from "react";
276
275
  import { Link as OriginalLink } from "react-router-dom";
277
276
  import { jsx as jsx2 } from "react/jsx-runtime";
278
277
  var Link = memo2(function(props) {
279
- var to = props.to, children = props.children, reLaunch = props.reLaunch, preload = props.preload, replace = props.replace, className = props.className;
278
+ var to = props.to, children = props.children, preload = props.preload, replace = props.replace, className = props.className, target = props.target;
280
279
  var _navigator2 = useMemo(function() {
281
280
  return getClientNavigator();
282
281
  }, []);
283
282
  if (/http(s)?:\/{2}/.test(to)) {
284
283
  var handleLink = function(e) {
284
+ if (e.ctrlKey || e.metaKey) return;
285
285
  e.preventDefault();
286
- window.location.href = to;
286
+ if (target === "_blank") {
287
+ window.open(to);
288
+ } else {
289
+ window.location.href = to;
290
+ }
287
291
  };
288
292
  return /* @__PURE__ */ jsx2("a", {
289
293
  href: to,
290
294
  onClick: handleLink,
291
295
  className: className,
292
- children: children
293
- });
294
- }
295
- if (reLaunch) {
296
- var handleLink1 = function(e) {
297
- e.preventDefault();
298
- _navigator2.reLaunch(to);
299
- };
300
- return /* @__PURE__ */ jsx2("a", {
301
- href: to,
302
- onClick: handleLink1,
303
- className: className,
296
+ target: target,
304
297
  children: children
305
298
  });
306
299
  }
307
300
  if (preload) {
308
- var handleLink2 = function() {
301
+ var handleLink1 = function() {
309
302
  var _ref = _async_to_generator(function(e) {
310
303
  return _ts_generator(this, function(_state) {
311
304
  switch(_state.label){
312
305
  case 0:
306
+ if (e.ctrlKey || e.metaKey) return [
307
+ 2
308
+ ];
313
309
  e.preventDefault();
314
310
  return [
315
311
  4,
@@ -323,13 +319,13 @@ var Link = memo2(function(props) {
323
319
  }
324
320
  });
325
321
  });
326
- return function handleLink2(e) {
322
+ return function handleLink1(e) {
327
323
  return _ref.apply(this, arguments);
328
324
  };
329
325
  }();
330
326
  return /* @__PURE__ */ jsx2("a", {
331
327
  href: to,
332
- onClick: handleLink2,
328
+ onClick: handleLink1,
333
329
  className: className,
334
330
  children: children
335
331
  });
@@ -353,38 +349,6 @@ function createNavigator(options) {
353
349
  originHistory = createHashHistory();
354
350
  }
355
351
  _navigator = originHistory;
356
- var initialStack = [
357
- {
358
- pathname: _navigator.location.pathname
359
- }
360
- ];
361
- var stack = _navigator.stack = initialStack;
362
- _navigator.listen(function(param) {
363
- var location = param.location, action = param.action;
364
- var pathname = location.pathname;
365
- if (action === "PUSH") {
366
- stack.push({
367
- pathname: pathname
368
- });
369
- } else if (action === "REPLACE") {
370
- stack.pop();
371
- stack.push({
372
- pathname: pathname
373
- });
374
- } else if (action === "POP") {
375
- stack.pop();
376
- }
377
- if (!isProduction) console.log("router", action, pathname, stack);
378
- });
379
- _navigator.reLaunch = function(path, state) {
380
- var _stack_;
381
- var shouldBlack = -stack.length + 1;
382
- if (shouldBlack < 0) _navigator.go(shouldBlack);
383
- if (((_stack_ = stack[0]) === null || _stack_ === void 0 ? void 0 : _stack_.pathname) === path) return;
384
- setTimeout(function() {
385
- _navigator.replace(path, state);
386
- }, 1);
387
- };
388
352
  _navigator.preload = function() {
389
353
  var _ref = _async_to_generator(function(path, isReplace, query) {
390
354
  var _matchRoutes_, _matchRoutes, _path_split, tmp, originPath, tmp1, search, matchPath, currentRoute, _pageModule_default_emitOnLoad, _pageModule_default, pageModule, _currentRoute_Component_emitOnLoad, _currentRoute_Component;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xfe-repo/web-router",
3
- "version": "1.2.2",
3
+ "version": "1.2.5",
4
4
  "sideEffects": false,
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -22,17 +22,18 @@
22
22
  "dependencies": {
23
23
  "@loadable/component": "^5.16.4",
24
24
  "history": "^5.3.0",
25
- "query-string": "^7.1.3",
26
- "react-router-dom": "6.28.0",
27
- "@xfe-repo/web-utils": "1.3.5"
25
+ "react-router-dom": "6.28.0"
28
26
  },
29
27
  "devDependencies": {
30
28
  "@types/loadable__component": "^5.13.9",
31
29
  "@types/node": "^20.16.5",
32
30
  "@types/react": "^18",
33
31
  "@xfe-repo/eslint-config": "0.0.5",
34
- "@xfe-repo/typescript-config": "0.0.6",
35
- "@xfe-repo/web-register": "1.3.4"
32
+ "@xfe-repo/web-register": "1.3.5",
33
+ "@xfe-repo/typescript-config": "0.0.6"
34
+ },
35
+ "peerDependencies": {
36
+ "@xfe-repo/web-utils": "1.3.7"
36
37
  },
37
38
  "publishConfig": {
38
39
  "registry": "https://registry.npmjs.org/"