@shuvi/router-react 0.0.1-rc.9 → 1.0.0-rc.10

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/lib/index.js CHANGED
@@ -1,16 +1,32 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
5
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.Link = exports.Router = exports.RouterView = exports.MemoryRouter = exports.useIsomorphicEffect = exports.generatePath = void 0;
6
18
  var utils_1 = require("./utils");
7
- exports.generatePath = utils_1.generatePath;
19
+ Object.defineProperty(exports, "generatePath", { enumerable: true, get: function () { return utils_1.generatePath; } });
20
+ Object.defineProperty(exports, "useIsomorphicEffect", { enumerable: true, get: function () { return utils_1.useIsomorphicEffect; } });
8
21
  var MemoryRouter_1 = require("./MemoryRouter");
9
- exports.MemoryRouter = MemoryRouter_1.MemoryRouter;
22
+ Object.defineProperty(exports, "MemoryRouter", { enumerable: true, get: function () { return MemoryRouter_1.MemoryRouter; } });
10
23
  var RouterView_1 = require("./RouterView");
11
- exports.RouterView = RouterView_1.RouterView;
24
+ Object.defineProperty(exports, "RouterView", { enumerable: true, get: function () { return RouterView_1.RouterView; } });
12
25
  var Router_1 = require("./Router");
13
- exports.Router = Router_1.Router;
26
+ Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return Router_1.Router; } });
14
27
  var Link_1 = require("./Link");
15
- exports.Link = Link_1.Link;
16
- __export(require("./hooks"));
28
+ Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return Link_1.Link; } });
29
+ __exportStar(require("./hooks"), exports);
30
+ __exportStar(require("./contexts"), exports);
31
+ __exportStar(require("./types"), exports);
32
+ __exportStar(require("@shuvi/router"), exports);
package/lib/types.d.ts CHANGED
@@ -1,21 +1,21 @@
1
1
  /// <reference types="react" />
2
- import { IParams, InitialEntry, State, PathRecord, IRouteRecord as IOriginRouteRecord, IPartialRouteRecord as IOriginalRouteRecord, IRouter } from '@shuvi/router';
3
- export declare type IRouteRecord = IOriginRouteRecord<React.ReactNode>;
4
- export declare type IPartialRouteRecord = IOriginalRouteRecord;
2
+ import { IParams, InitialEntry, State, PathRecord, IRouteRecord as IOriginalRouteRecord, IRouter } from '@shuvi/router';
3
+ export declare type IReactRouteRecord<T = {}> = IOriginalRouteRecord<React.ReactNode, T>;
4
+ export declare type IReactPartialRouteRecord = Partial<IReactRouteRecord>;
5
5
  export interface IRouterContextObject {
6
6
  static: boolean;
7
7
  router: IRouter;
8
8
  }
9
- export interface IRouteContextObject {
9
+ export interface IRouteContextObject<ExtendedTypes = {}> {
10
10
  depth: number;
11
11
  params: IParams;
12
12
  pathname: string;
13
- route: IRouteRecord | null;
13
+ route: IReactRouteRecord<ExtendedTypes> | null;
14
14
  }
15
15
  export interface IMemoryRouterProps {
16
16
  basename?: string;
17
17
  children?: React.ReactNode;
18
- routes?: IRouteRecord[];
18
+ routes?: IReactRouteRecord[];
19
19
  initialEntries?: InitialEntry[];
20
20
  initialIndex?: number;
21
21
  }
@@ -26,12 +26,6 @@ export interface INavigateProps {
26
26
  }
27
27
  export interface IOutletProps {
28
28
  }
29
- export interface IRouteProps {
30
- caseSensitive?: boolean;
31
- children?: React.ReactNode;
32
- element?: React.ReactElement | null;
33
- path?: string;
34
- }
35
29
  export interface IRouterProps {
36
30
  children?: React.ReactNode;
37
31
  static?: boolean;
package/lib/utils.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { IParams } from '@shuvi/router';
2
- import invariant from '@shuvi/utils/lib/invariant';
3
2
  export declare function useIsomorphicEffect(cb: any, deps: any): void;
4
3
  export declare const readOnly: <T extends unknown>(obj: T) => T;
5
4
  export declare function warning(cond: boolean, message: string): void;
@@ -8,4 +7,3 @@ export declare function warningOnce(key: string, cond: boolean, message: string)
8
7
  * Returns a path with params interpolated.
9
8
  */
10
9
  export declare function generatePath(path: string, params?: IParams): string;
11
- export { invariant };
package/lib/utils.js CHANGED
@@ -1,18 +1,15 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generatePath = exports.warningOnce = exports.warning = exports.readOnly = exports.useIsomorphicEffect = void 0;
4
+ const router_1 = require("@shuvi/router");
6
5
  const react_1 = require("react");
7
6
  const constants_1 = require("./constants");
8
- const invariant_1 = __importDefault(require("@shuvi/utils/lib/invariant"));
9
- exports.invariant = invariant_1.default;
10
7
  function useIsomorphicEffect(cb, deps) {
11
8
  if (typeof window !== 'undefined') {
12
- react_1.useLayoutEffect(cb, deps);
9
+ (0, react_1.useLayoutEffect)(cb, deps);
13
10
  }
14
11
  else {
15
- react_1.useEffect(cb, deps);
12
+ (0, react_1.useEffect)(cb, deps);
16
13
  }
17
14
  }
18
15
  exports.useIsomorphicEffect = useIsomorphicEffect;
@@ -47,11 +44,6 @@ exports.warningOnce = warningOnce;
47
44
  * Returns a path with params interpolated.
48
45
  */
49
46
  function generatePath(path, params = {}) {
50
- return path
51
- .replace(/:(\w+)/g, (_, key) => {
52
- invariant_1.default(params[key] != null, `Missing ":${key}" param`);
53
- return params[key];
54
- })
55
- .replace(/\/*\*$/, _ => params['*'] == null ? '' : params['*'].replace(/^\/*/, '/'));
47
+ return (0, router_1.matchStringify)(path, params);
56
48
  }
57
49
  exports.generatePath = generatePath;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shuvi/router-react",
3
- "version": "0.0.1-rc.9",
3
+ "version": "1.0.0-rc.10",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/shuvijs/shuvi.git",
@@ -12,30 +12,38 @@
12
12
  "module": "esm/index.js",
13
13
  "types": "lib/index.d.ts",
14
14
  "files": [
15
- "lib"
15
+ "lib",
16
+ "esm"
16
17
  ],
17
18
  "scripts": {
18
19
  "dev": "run-p watch:*",
19
- "watch:esm": "tsc -p tsconfig.build.esm.json -w",
20
- "watch:cjs": "tsc -p tsconfig.build.cjs.json -w",
20
+ "watch:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm -w",
21
+ "watch:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib -w",
21
22
  "prebuild": "rimraf lib esm",
22
23
  "build": "run-p build:*",
23
- "build:esm": "tsc -p tsconfig.build.esm.json",
24
- "build:cjs": "tsc -p tsconfig.build.cjs.json"
24
+ "build:esm": "tsc -p tsconfig.build.json -m esnext --outDir esm",
25
+ "build:cjs": "tsc -p tsconfig.build.json -m commonjs --outDir lib"
25
26
  },
26
27
  "engines": {
27
28
  "node": ">= 12.0.0"
28
29
  },
29
30
  "dependencies": {
30
- "@shuvi/router": "^0.0.1-rc.9"
31
+ "@shuvi/router": "1.0.0-rc.10",
32
+ "@shuvi/platform-shared": "1.0.0-rc.10",
33
+ "@shuvi/utils": "1.0.0-rc.10",
34
+ "prop-types": "^15.8.1",
35
+ "use-sync-external-store": "1.1.0"
31
36
  },
32
37
  "devDependencies": {
33
- "@types/react": "^16.9.43",
34
- "@types/react-test-renderer": "^16.9.2",
35
- "react-test-renderer": "^16.13.1"
38
+ "@types/prop-types": "^15.7.5",
39
+ "@types/react": "18.0.9",
40
+ "@types/react-test-renderer": "18.0.0",
41
+ "@types/use-sync-external-store": "0.0.3",
42
+ "react-test-renderer": "^18.1.0",
43
+ "react": "18.1.0",
44
+ "react-dom": "18.1.0"
36
45
  },
37
46
  "peerDependencies": {
38
- "react": ">=16.8"
39
- },
40
- "gitHead": "b0c352fb22c6f707e96c786d1d001c0588fc2833"
47
+ "react": ">=16.8.0"
48
+ }
41
49
  }