next-use-contextual-routing 3.1.0 → 4.0.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 +6 -4
  2. package/dist/index.js +10 -16
  3. package/package.json +37 -51
package/README.md CHANGED
@@ -117,10 +117,12 @@ The path to return to to close contextual navigation.
117
117
 
118
118
  ## Next.js versions support
119
119
 
120
- | Next use contextual routing | Next.js |
121
- | --------------------------- | ------------- |
122
- | v2.2.0 | v9.X -> v12.X |
123
- | v3.0.0 + | v13.X |
120
+ | Next use contextual routing | Next.js |
121
+ | --------------------------- | -------------- |
122
+ | v2.2.0 | v9.X -> v12.X |
123
+ | v3.0.0 | v13.X |
124
+ | v3.2.0 + | v13.X -> v14.X |
125
+ | v4.0.0 + | v15.X |
124
126
 
125
127
  ## Notes
126
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,31 +1,7 @@
1
1
  {
2
2
  "name": "next-use-contextual-routing",
3
3
  "description": "Generate Next.js contextual routing paths",
4
- "version": "3.1.0",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "type": "module",
9
- "files": [
10
- "dist"
11
- ],
12
- "scripts": {
13
- "clean": "rm -rf dist",
14
- "build": "npm run clean && tsc -p tsconfig.build.json",
15
- "preversion": "npm run prepare",
16
- "version": "git add package.json",
17
- "postversion": "git push && git push --tags",
18
- "prepare": "npx simple-git-hooks && npm run test:source && npm run build && npm run test:bundles",
19
- "test": "jest",
20
- "test:source": "npm t -- --coverage",
21
- "test:bundles": "es-check es5 --module './@(dist)/*.js'",
22
- "tag": "node ./scripts/tag.js",
23
- "format": "prettier --write \"**/*.{js,json,md}\"",
24
- "start": "npm run demo:start",
25
- "demo:start": "cd ./demo && next",
26
- "demo:build": "npm run build && cd ./demo && BUILD_TARGET=github-pages next build && BUILD_TARGET=github-pages next export",
27
- "demo:deploy": "npm run demo:build && touch demo/out/.nojekyll && gh-pages -d demo/out --dotfiles"
28
- },
4
+ "version": "4.0.0",
29
5
  "keywords": [
30
6
  "next",
31
7
  "next.js",
@@ -42,47 +18,57 @@
42
18
  },
43
19
  "author": "Andrea Carraro <me@andreacarraro.it>",
44
20
  "license": "ISC",
45
- "dependencies": {
46
- "qs-stringify": "^1.2.1"
21
+ "main": "dist/index.js",
22
+ "module": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "type": "module",
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "publishConfig": {
29
+ "access": "public"
30
+ },
31
+ "scripts": {
32
+ "clean": "rm -rf dist",
33
+ "build": "npm run clean && tsc -p tsconfig.build.json",
34
+ "preversion": "npm run prepare",
35
+ "version": "git add package.json",
36
+ "postversion": "git push && git push --tags",
37
+ "prepare": "npx simple-git-hooks && npm run source:check && npm run test -- --run && npm run build",
38
+ "test": "vitest --config ./vitest.config.mts",
39
+ "test:a": "vitest --config ./vitest.config.mts",
40
+ "tag": "node ./scripts/tag.js",
41
+ "prettier:check": "prettier . --check",
42
+ "prettier:fix": "npm run prettier:check -- --write",
43
+ "type:check": "tsc --noEmit",
44
+ "source:check": "npm run prettier:check && npm run type:check",
45
+ "source:fix": "npm run prettier:fix",
46
+ "start": "npm run demo:start",
47
+ "demo:start": "cd ./demo && next",
48
+ "demo:build": "npm run build && cd ./demo && BUILD_TARGET=github-pages next build && touch ./out/.nojekyll"
47
49
  },
48
50
  "devDependencies": {
49
51
  "@changesets/cli": "^2.27.7",
50
52
  "@testing-library/react": "^16.0.0",
51
- "@types/jest": "^29.2.3",
53
+ "@tsconfig/node20": "^20.1.4",
52
54
  "@types/react": "^18.0.25",
53
- "es-check": "^7.2.1",
54
- "gh-pages": "^3.1.0",
55
- "jest": "^29.3.1",
56
- "jest-environment-jsdom": "^29.3.1",
57
- "next": "^13.0.5",
55
+ "@vitest/coverage-v8": "^2.1.3",
56
+ "next": "^15.0.0",
58
57
  "prettier": "^3.3.2",
58
+ "qs-stringify": "^1.2.1",
59
59
  "react": "^18.2.0",
60
60
  "react-dom": "^18.2.0",
61
61
  "react-modal": "^3.16.1",
62
62
  "react-test-renderer": "^18.2.0",
63
63
  "simple-git-hooks": "^2.11.1",
64
- "ts-jest": "^29.0.3",
65
- "typescript": "^5.5.3"
64
+ "typescript": "^5.5.3",
65
+ "vitest": "^2.1.3"
66
66
  },
67
67
  "peerDependencies": {
68
- "next": "^13.0.0",
68
+ "next": "^15.0.0",
69
69
  "react": ">=18.0.0"
70
70
  },
71
- "jest": {
72
- "preset": "ts-jest/presets/js-with-ts",
73
- "testPathIgnorePatterns": [
74
- ".test-d\\.ts"
75
- ],
76
- "coveragePathIgnorePatterns": [
77
- "__tests__"
78
- ],
79
- "coverageReporters": [
80
- "text",
81
- "lcov"
82
- ],
83
- "testEnvironment": "jsdom"
84
- },
85
71
  "simple-git-hooks": {
86
- "pre-commit": "npm run test:source"
72
+ "pre-commit": "npm run prepare"
87
73
  }
88
74
  }