next-use-contextual-routing 3.2.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.
- package/README.md +1 -0
- package/dist/index.js +10 -16
- package/package.json +31 -47
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { useRouter } from 'next/router.js';
|
|
3
|
-
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
25
|
+
const returnHref = returnHrefQueryParam !== null && returnHrefQueryParam !== void 0 ? returnHrefQueryParam : router.asPath;
|
|
27
26
|
// @NOTE JSON.stringify might be replaced with any hashing solution
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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": "
|
|
4
|
+
"version": "4.0.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,15 +25,18 @@
|
|
|
9
25
|
"files": [
|
|
10
26
|
"dist"
|
|
11
27
|
],
|
|
28
|
+
"publishConfig": {
|
|
29
|
+
"access": "public"
|
|
30
|
+
},
|
|
12
31
|
"scripts": {
|
|
13
32
|
"clean": "rm -rf dist",
|
|
14
33
|
"build": "npm run clean && tsc -p tsconfig.build.json",
|
|
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
|
|
19
|
-
"test": "
|
|
20
|
-
"test:
|
|
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",
|
|
21
40
|
"tag": "node ./scripts/tag.js",
|
|
22
41
|
"prettier:check": "prettier . --check",
|
|
23
42
|
"prettier:fix": "npm run prettier:check -- --write",
|
|
@@ -28,63 +47,28 @@
|
|
|
28
47
|
"demo:start": "cd ./demo && next",
|
|
29
48
|
"demo:build": "npm run build && cd ./demo && BUILD_TARGET=github-pages next build && touch ./out/.nojekyll"
|
|
30
49
|
},
|
|
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
50
|
"devDependencies": {
|
|
51
51
|
"@changesets/cli": "^2.27.7",
|
|
52
52
|
"@testing-library/react": "^16.0.0",
|
|
53
|
-
"@
|
|
53
|
+
"@tsconfig/node20": "^20.1.4",
|
|
54
54
|
"@types/react": "^18.0.25",
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"jest-environment-jsdom": "^29.3.1",
|
|
58
|
-
"next": "^14.2.4",
|
|
59
|
-
"next-13": "npm:next@^13.5.6",
|
|
55
|
+
"@vitest/coverage-v8": "^2.1.3",
|
|
56
|
+
"next": "^15.0.0",
|
|
60
57
|
"prettier": "^3.3.2",
|
|
58
|
+
"qs-stringify": "^1.2.1",
|
|
61
59
|
"react": "^18.2.0",
|
|
62
60
|
"react-dom": "^18.2.0",
|
|
63
61
|
"react-modal": "^3.16.1",
|
|
64
62
|
"react-test-renderer": "^18.2.0",
|
|
65
63
|
"simple-git-hooks": "^2.11.1",
|
|
66
|
-
"
|
|
67
|
-
"
|
|
64
|
+
"typescript": "^5.5.3",
|
|
65
|
+
"vitest": "^2.1.3"
|
|
68
66
|
},
|
|
69
67
|
"peerDependencies": {
|
|
70
|
-
"next": "^
|
|
68
|
+
"next": "^15.0.0",
|
|
71
69
|
"react": ">=18.0.0"
|
|
72
70
|
},
|
|
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
71
|
"simple-git-hooks": {
|
|
88
|
-
"pre-commit": "npm run
|
|
72
|
+
"pre-commit": "npm run prepare"
|
|
89
73
|
}
|
|
90
74
|
}
|