next-use-contextual-routing 3.2.0 → 4.1.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/dist/index.js +10 -16
  3. package/package.json +40 -54
package/README.md CHANGED
@@ -122,6 +122,7 @@ The path to return to to close contextual navigation.
122
122
  | v2.2.0 | v9.X -> v12.X |
123
123
  | v3.0.0 | v13.X |
124
124
  | v3.2.0 + | v13.X -> v14.X |
125
+ | v4.0.0 + | v15.X -> v16.X |
125
126
 
126
127
  ## Notes
127
128
 
package/dist/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { useCallback } from 'react';
2
2
  import { useRouter } from 'next/router.js';
3
- import stringify from 'qs-stringify';
4
- export var RETURN_HREF_QUERY_PARAM = '_UCR_return_href';
3
+ export const RETURN_HREF_QUERY_PARAM = '_UCR_return_href';
5
4
  /**
6
5
  * During contextual routing browser URL will be controlled by Next Router's "as" prop
7
6
  * while the page actually rendered is defined by Next Router's "href" prop.
@@ -12,27 +11,22 @@ export var RETURN_HREF_QUERY_PARAM = '_UCR_return_href';
12
11
  * router.query: {"terms": "foo-bar"} same as above
13
12
  */
14
13
  export function useContextualRouting() {
15
- var router = useRouter();
16
- var returnHrefQueryParam = typeof router.query[RETURN_HREF_QUERY_PARAM] === 'string'
14
+ const router = useRouter();
15
+ const returnHrefQueryParam = typeof router.query[RETURN_HREF_QUERY_PARAM] === 'string'
17
16
  ? router.query[RETURN_HREF_QUERY_PARAM]
18
17
  : undefined;
19
- var watchedQuery = Object.assign({}, router.query);
18
+ const watchedQuery = Object.assign({}, router.query);
20
19
  delete watchedQuery[RETURN_HREF_QUERY_PARAM];
21
20
  /*
22
21
  * After a page refresh there is no RETURN_HREF_QUERY_PARAM in router.query
23
22
  * RETURN_HREF_QUERY_PARAM is only available in those history entries where
24
23
  * contextual navigation is enabled (or WAS enabled in case history.back() is triggered)
25
24
  */
26
- var returnHref = returnHrefQueryParam !== null && returnHrefQueryParam !== void 0 ? returnHrefQueryParam : router.asPath;
25
+ const returnHref = returnHrefQueryParam !== null && returnHrefQueryParam !== void 0 ? returnHrefQueryParam : router.asPath;
27
26
  // @NOTE JSON.stringify might be replaced with any hashing solution
28
- var queryHash = JSON.stringify(watchedQuery);
29
- var makeContextualHref = useCallback(function (extraParams) {
30
- var _a;
31
- return router.pathname +
32
- '?' +
33
- stringify(Object.assign({}, router.query, extraParams, (_a = {},
34
- _a[RETURN_HREF_QUERY_PARAM] = returnHref,
35
- _a)));
36
- }, [queryHash, returnHref]);
37
- return { returnHref: returnHref, makeContextualHref: makeContextualHref };
27
+ const queryHash = JSON.stringify(watchedQuery);
28
+ const makeContextualHref = useCallback((extraParams) => router.pathname +
29
+ '?' +
30
+ new URLSearchParams(Object.assign(Object.assign(Object.assign({}, router.query), extraParams), { [RETURN_HREF_QUERY_PARAM]: returnHref })).toString(), [queryHash, returnHref]);
31
+ return { returnHref, makeContextualHref };
38
32
  }
package/package.json CHANGED
@@ -1,7 +1,23 @@
1
1
  {
2
2
  "name": "next-use-contextual-routing",
3
3
  "description": "Generate Next.js contextual routing paths",
4
- "version": "3.2.0",
4
+ "version": "4.1.0",
5
+ "keywords": [
6
+ "next",
7
+ "next.js",
8
+ "contextual",
9
+ "routing",
10
+ "snowlift",
11
+ "route as modal",
12
+ "modal route",
13
+ "hook"
14
+ ],
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/toomuchdesign/next-use-contextual-routing.git"
18
+ },
19
+ "author": "Andrea Carraro <me@andreacarraro.it>",
20
+ "license": "ISC",
5
21
  "main": "dist/index.js",
6
22
  "module": "dist/index.js",
7
23
  "types": "dist/index.d.ts",
@@ -9,16 +25,17 @@
9
25
  "files": [
10
26
  "dist"
11
27
  ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
12
31
  "scripts": {
13
- "clean": "rm -rf dist",
14
- "build": "npm run clean && tsc -p tsconfig.build.json",
32
+ "build": "rimraf ./dist && tsc -p tsconfig.build.json",
33
+ "test": "vitest --config ./vitest.config.mts",
15
34
  "preversion": "npm run prepare",
16
35
  "version": "git add package.json",
17
36
  "postversion": "git push && git push --tags",
18
- "prepare": "npx simple-git-hooks && npm run source:check && npm run test && npm run build && npm run test:bundles",
19
- "test": "jest --coverage",
20
- "test:bundles": "es-check es5 --module './@(dist)/*.js'",
21
- "tag": "node ./scripts/tag.js",
37
+ "prepare": "npx simple-git-hooks && npm run source:check && npm run test -- --run && npm run build",
38
+ "release": "npm run prepare && npx changeset publish",
22
39
  "prettier:check": "prettier . --check",
23
40
  "prettier:fix": "npm run prettier:check -- --write",
24
41
  "type:check": "tsc --noEmit",
@@ -28,63 +45,32 @@
28
45
  "demo:start": "cd ./demo && next",
29
46
  "demo:build": "npm run build && cd ./demo && BUILD_TARGET=github-pages next build && touch ./out/.nojekyll"
30
47
  },
31
- "keywords": [
32
- "next",
33
- "next.js",
34
- "contextual",
35
- "routing",
36
- "snowlift",
37
- "route as modal",
38
- "modal route",
39
- "hook"
40
- ],
41
- "repository": {
42
- "type": "git",
43
- "url": "git+https://github.com/toomuchdesign/next-use-contextual-routing.git"
44
- },
45
- "author": "Andrea Carraro <me@andreacarraro.it>",
46
- "license": "ISC",
47
- "dependencies": {
48
- "qs-stringify": "^1.2.1"
49
- },
50
48
  "devDependencies": {
49
+ "@changesets/changelog-github": "^0.5.1",
51
50
  "@changesets/cli": "^2.27.7",
52
51
  "@testing-library/react": "^16.0.0",
53
- "@types/jest": "^29.2.3",
54
- "@types/react": "^18.0.25",
55
- "es-check": "^7.2.1",
56
- "jest": "^29.3.1",
57
- "jest-environment-jsdom": "^29.3.1",
58
- "next": "^14.2.4",
59
- "next-13": "npm:next@^13.5.6",
52
+ "@tsconfig/node20": "^20.1.4",
53
+ "@types/node": "^20.19.0",
54
+ "@types/react": "^19.1.6",
55
+ "@vitest/coverage-v8": "^4.0.0",
56
+ "jsdom": "^26.0.0",
57
+ "next": "^16.0.0",
60
58
  "prettier": "^3.3.2",
61
- "react": "^18.2.0",
62
- "react-dom": "^18.2.0",
59
+ "qs-stringify": "^1.2.1",
60
+ "react": "^19.1.0",
61
+ "react-dom": "^19.1.0",
63
62
  "react-modal": "^3.16.1",
64
- "react-test-renderer": "^18.2.0",
63
+ "react-test-renderer": "^19.1.0",
64
+ "rimraf": "^6.0.1",
65
65
  "simple-git-hooks": "^2.11.1",
66
- "ts-jest": "^29.0.3",
67
- "typescript": "^5.5.3"
66
+ "typescript": "^5.5.3",
67
+ "vitest": "^4.0.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "next": "^13.0.0 | ^14.0.0",
70
+ "next": "^15.0.0 || ^16.0.0",
71
71
  "react": ">=18.0.0"
72
72
  },
73
- "jest": {
74
- "preset": "ts-jest/presets/js-with-ts",
75
- "testPathIgnorePatterns": [
76
- ".test-d\\.ts"
77
- ],
78
- "coveragePathIgnorePatterns": [
79
- "__tests__"
80
- ],
81
- "coverageReporters": [
82
- "text",
83
- "lcov"
84
- ],
85
- "testEnvironment": "jsdom"
86
- },
87
73
  "simple-git-hooks": {
88
- "pre-commit": "npm run source:check && npm run test"
74
+ "pre-commit": "npm run prepare"
89
75
  }
90
76
  }