@react-foundry/router 0.1.9 → 0.2.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/dist/common.js +1 -2
- package/dist/dummy.js +10 -16
- package/dist/index.js +7 -13
- package/dist/is-active.js +3 -7
- package/dist/location.js +4 -9
- package/dist/next.js +15 -24
- package/dist/remix.js +7 -13
- package/package.json +14 -19
- package/dist/common.mjs +0 -1
- package/dist/dummy.mjs +0 -24
- package/dist/index.mjs +0 -7
- package/dist/is-active.mjs +0 -27
- package/dist/location.mjs +0 -6
- package/dist/next.mjs +0 -74
- package/dist/remix.mjs +0 -7
package/dist/common.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/dummy.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const is_active_1 = require("./is-active");
|
|
6
|
-
const location_1 = require("./location");
|
|
7
|
-
exports.needSuspense = false;
|
|
1
|
+
import { createElement as h } from 'react';
|
|
2
|
+
import { makeUseIsActive } from './is-active';
|
|
3
|
+
import { makeUseLocation } from './location';
|
|
4
|
+
export const needSuspense = false;
|
|
8
5
|
const _useLocation = () => ({
|
|
9
6
|
state: undefined,
|
|
10
7
|
key: '',
|
|
@@ -12,19 +9,16 @@ const _useLocation = () => ({
|
|
|
12
9
|
search: '',
|
|
13
10
|
hash: ''
|
|
14
11
|
});
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const useNavigate = () => () => undefined;
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
exports.useParams = useParams;
|
|
21
|
-
const Link = ({ to, preventScrollReset, replace, ...attrs }) => {
|
|
12
|
+
export const useLocation = makeUseLocation(_useLocation);
|
|
13
|
+
export const useIsActive = makeUseIsActive(useLocation);
|
|
14
|
+
export const useNavigate = () => () => undefined;
|
|
15
|
+
export const useParams = () => ({});
|
|
16
|
+
export const Link = ({ to, preventScrollReset, replace, ...attrs }) => {
|
|
22
17
|
const href = (typeof to === 'string'
|
|
23
18
|
? to
|
|
24
19
|
: (to.pathname || '') + (to.search || '') + (to.hash || ''));
|
|
25
|
-
return (
|
|
20
|
+
return h('a', {
|
|
26
21
|
...attrs,
|
|
27
22
|
href
|
|
28
23
|
});
|
|
29
24
|
};
|
|
30
|
-
exports.Link = Link;
|
package/dist/index.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
exports.useLocation = (0, location_1.makeUseLocation)(react_router_1.useLocation);
|
|
9
|
-
exports.useIsActive = (0, is_active_1.makeUseIsActive)(exports.useLocation);
|
|
10
|
-
var react_router_2 = require("react-router");
|
|
11
|
-
Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return react_router_2.Link; } });
|
|
12
|
-
Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return react_router_2.useNavigate; } });
|
|
13
|
-
Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return react_router_2.useParams; } });
|
|
1
|
+
import { useLocation as _useLocation } from 'react-router';
|
|
2
|
+
import { makeUseIsActive } from './is-active';
|
|
3
|
+
import { makeUseLocation } from './location';
|
|
4
|
+
export const needSuspense = false;
|
|
5
|
+
export const useLocation = makeUseLocation(_useLocation);
|
|
6
|
+
export const useIsActive = makeUseIsActive(useLocation);
|
|
7
|
+
export { Link, useNavigate, useParams } from 'react-router';
|
package/dist/is-active.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeUseIsActive = void 0;
|
|
4
|
-
const uri_1 = require("@react-foundry/uri");
|
|
1
|
+
import { URI } from '@react-foundry/uri';
|
|
5
2
|
const includes = (haystack, needle) => {
|
|
6
3
|
const subIncludes = (haystack, needle) => (Array.isArray(needle) ? (needle.length === haystack.length &&
|
|
7
4
|
needle.reduce((acc, cur, idx) => acc && subIncludes(haystack[idx], cur), true)) : (typeof needle === 'object' ? (typeof haystack === 'object' &&
|
|
8
5
|
Object.keys(needle).reduce((acc, cur) => acc && subIncludes(haystack[cur], needle[cur]), true)) : (needle === haystack)));
|
|
9
6
|
return subIncludes(haystack, needle);
|
|
10
7
|
};
|
|
11
|
-
const makeUseIsActive = (useLocation) => () => {
|
|
8
|
+
export const makeUseIsActive = (useLocation) => () => {
|
|
12
9
|
const location = useLocation();
|
|
13
10
|
const isActive = (href, exact = true) => {
|
|
14
|
-
const target =
|
|
11
|
+
const target = URI.parse(href, location.pathname);
|
|
15
12
|
const dir = (target.pathname.endsWith('/')
|
|
16
13
|
? target.pathname
|
|
17
14
|
: target.pathname + '/');
|
|
@@ -28,4 +25,3 @@ const makeUseIsActive = (useLocation) => () => {
|
|
|
28
25
|
};
|
|
29
26
|
return isActive;
|
|
30
27
|
};
|
|
31
|
-
exports.makeUseIsActive = makeUseIsActive;
|
package/dist/location.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.makeUseLocation = exports.enhanceLocation = void 0;
|
|
4
|
-
const uri_1 = require("@react-foundry/uri");
|
|
5
|
-
const enhanceLocation = (location) => ({
|
|
1
|
+
import { qsParse } from '@react-foundry/uri';
|
|
2
|
+
export const enhanceLocation = (location) => ({
|
|
6
3
|
...location,
|
|
7
|
-
query:
|
|
4
|
+
query: qsParse(location.search)
|
|
8
5
|
});
|
|
9
|
-
|
|
10
|
-
const makeUseLocation = (useLocation) => () => ((0, exports.enhanceLocation)(useLocation()));
|
|
11
|
-
exports.makeUseLocation = makeUseLocation;
|
|
6
|
+
export const makeUseLocation = (useLocation) => () => (enhanceLocation(useLocation()));
|
package/dist/next.js
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const react_1 = require("react");
|
|
8
|
-
const navigation_1 = require("next/navigation");
|
|
9
|
-
const link_1 = __importDefault(require("next/link"));
|
|
10
|
-
const is_active_1 = require("./is-active");
|
|
11
|
-
const location_1 = require("./location");
|
|
12
|
-
exports.needSuspense = true;
|
|
1
|
+
import { createElement as h } from 'react';
|
|
2
|
+
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
3
|
+
import _Link from 'next/link';
|
|
4
|
+
import { makeUseIsActive } from './is-active';
|
|
5
|
+
import { makeUseLocation } from './location';
|
|
6
|
+
export const needSuspense = true;
|
|
13
7
|
const _useLocation = () => {
|
|
14
|
-
const pathname =
|
|
15
|
-
const searchParams =
|
|
8
|
+
const pathname = usePathname();
|
|
9
|
+
const searchParams = useSearchParams();
|
|
16
10
|
const search = (searchParams.size
|
|
17
11
|
? '?' + searchParams.toString()
|
|
18
12
|
: '');
|
|
@@ -25,10 +19,10 @@ const _useLocation = () => {
|
|
|
25
19
|
};
|
|
26
20
|
return location;
|
|
27
21
|
};
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const useNavigate = () => {
|
|
31
|
-
const router =
|
|
22
|
+
export const useLocation = makeUseLocation(_useLocation);
|
|
23
|
+
export const useIsActive = makeUseIsActive(useLocation);
|
|
24
|
+
export const useNavigate = () => {
|
|
25
|
+
const router = useRouter();
|
|
32
26
|
const navigate = (to, options = {}) => {
|
|
33
27
|
if (typeof to === 'number') {
|
|
34
28
|
if (to === -1) {
|
|
@@ -52,7 +46,6 @@ const useNavigate = () => {
|
|
|
52
46
|
};
|
|
53
47
|
return navigate;
|
|
54
48
|
};
|
|
55
|
-
exports.useNavigate = useNavigate;
|
|
56
49
|
const prefetchMap = new Map([
|
|
57
50
|
[undefined, null],
|
|
58
51
|
['none', false],
|
|
@@ -60,7 +53,7 @@ const prefetchMap = new Map([
|
|
|
60
53
|
['render', true],
|
|
61
54
|
['viewport', true]
|
|
62
55
|
]);
|
|
63
|
-
const Link = ({ to, prefetch: _prefetch, preventScrollReset, replace, ...attrs }) => {
|
|
56
|
+
export const Link = ({ to, prefetch: _prefetch, preventScrollReset, replace, ...attrs }) => {
|
|
64
57
|
const href = (typeof to === 'string'
|
|
65
58
|
? to
|
|
66
59
|
: {
|
|
@@ -70,7 +63,7 @@ const Link = ({ to, prefetch: _prefetch, preventScrollReset, replace, ...attrs }
|
|
|
70
63
|
: undefined)
|
|
71
64
|
});
|
|
72
65
|
const prefetch = prefetchMap.get(_prefetch);
|
|
73
|
-
return (
|
|
66
|
+
return h(_Link, {
|
|
74
67
|
...attrs,
|
|
75
68
|
href,
|
|
76
69
|
prefetch,
|
|
@@ -78,6 +71,4 @@ const Link = ({ to, prefetch: _prefetch, preventScrollReset, replace, ...attrs }
|
|
|
78
71
|
scroll: !preventScrollReset
|
|
79
72
|
});
|
|
80
73
|
};
|
|
81
|
-
|
|
82
|
-
var navigation_2 = require("next/navigation");
|
|
83
|
-
Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return navigation_2.useParams; } });
|
|
74
|
+
export { useParams } from 'next/navigation';
|
package/dist/remix.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
exports.useLocation = (0, location_1.makeUseLocation)(react_1.useLocation);
|
|
9
|
-
exports.useIsActive = (0, is_active_1.makeUseIsActive)(exports.useLocation);
|
|
10
|
-
var react_2 = require("@remix-run/react");
|
|
11
|
-
Object.defineProperty(exports, "Link", { enumerable: true, get: function () { return react_2.Link; } });
|
|
12
|
-
Object.defineProperty(exports, "useNavigate", { enumerable: true, get: function () { return react_2.useNavigate; } });
|
|
13
|
-
Object.defineProperty(exports, "useParams", { enumerable: true, get: function () { return react_2.useParams; } });
|
|
1
|
+
import { useLocation as _useLocation } from '@remix-run/react';
|
|
2
|
+
import { makeUseIsActive } from './is-active';
|
|
3
|
+
import { makeUseLocation } from './location';
|
|
4
|
+
export const needSuspense = false;
|
|
5
|
+
export const useLocation = makeUseLocation(_useLocation);
|
|
6
|
+
export const useIsActive = makeUseIsActive(useLocation);
|
|
7
|
+
export { Link, useNavigate, useParams } from '@remix-run/react';
|
package/package.json
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-foundry/router",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "An abstraction layer over the routers from react-router and Next.js.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"exports": {
|
|
7
8
|
".": {
|
|
8
9
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"import": "./dist/index.
|
|
10
|
-
"
|
|
11
|
-
"default": "./dist/index.mjs"
|
|
10
|
+
"import": "./dist/index.js",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
12
|
},
|
|
13
13
|
"./dummy": {
|
|
14
14
|
"types": "./dist/dummy.d.ts",
|
|
15
|
-
"import": "./dist/dummy.
|
|
16
|
-
"
|
|
17
|
-
"default": "./dist/dummy.mjs"
|
|
15
|
+
"import": "./dist/dummy.js",
|
|
16
|
+
"default": "./dist/dummy.js"
|
|
18
17
|
},
|
|
19
18
|
"./next": {
|
|
20
19
|
"types": "./dist/next.d.ts",
|
|
21
|
-
"import": "./dist/next.
|
|
22
|
-
"
|
|
23
|
-
"default": "./dist/next.mjs"
|
|
20
|
+
"import": "./dist/next.js",
|
|
21
|
+
"default": "./dist/next.js"
|
|
24
22
|
},
|
|
25
23
|
"./remix": {
|
|
26
24
|
"types": "./dist/remix.d.ts",
|
|
27
|
-
"import": "./dist/remix.
|
|
28
|
-
"
|
|
29
|
-
"default": "./dist/remix.mjs"
|
|
25
|
+
"import": "./dist/remix.js",
|
|
26
|
+
"default": "./dist/remix.js"
|
|
30
27
|
}
|
|
31
28
|
},
|
|
32
29
|
"files": [
|
|
@@ -38,7 +35,7 @@
|
|
|
38
35
|
"node": ">=12.0.0"
|
|
39
36
|
},
|
|
40
37
|
"dependencies": {
|
|
41
|
-
"@react-foundry/uri": "^0.
|
|
38
|
+
"@react-foundry/uri": "^0.2.0"
|
|
42
39
|
},
|
|
43
40
|
"peerDependencies": {
|
|
44
41
|
"@remix-run/react": ">2.17",
|
|
@@ -61,17 +58,15 @@
|
|
|
61
58
|
"@types/react": "19.2.14",
|
|
62
59
|
"jest": "30.3.0",
|
|
63
60
|
"jest-environment-jsdom": "30.3.0",
|
|
64
|
-
"next": "16.2.
|
|
61
|
+
"next": "16.2.3",
|
|
65
62
|
"ts-jest": "29.4.9",
|
|
66
63
|
"typescript": "5.9.3"
|
|
67
64
|
},
|
|
68
65
|
"scripts": {
|
|
69
66
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest",
|
|
70
|
-
"build": "
|
|
71
|
-
"build:esm": "tsc -m es2022 && find dist -name '*.js' -exec sh -c 'mv \"$0\" \"${0%.js}.mjs\"' {} \\;",
|
|
72
|
-
"build:cjs": "tsc",
|
|
67
|
+
"build": "tsc",
|
|
73
68
|
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
74
69
|
},
|
|
75
|
-
"module": "dist/index.
|
|
70
|
+
"module": "dist/index.js",
|
|
76
71
|
"typings": "dist/index.d.ts"
|
|
77
72
|
}
|
package/dist/common.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/dummy.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'react';
|
|
2
|
-
import { makeUseIsActive } from './is-active';
|
|
3
|
-
import { makeUseLocation } from './location';
|
|
4
|
-
export const needSuspense = false;
|
|
5
|
-
const _useLocation = () => ({
|
|
6
|
-
state: undefined,
|
|
7
|
-
key: '',
|
|
8
|
-
pathname: '',
|
|
9
|
-
search: '',
|
|
10
|
-
hash: ''
|
|
11
|
-
});
|
|
12
|
-
export const useLocation = makeUseLocation(_useLocation);
|
|
13
|
-
export const useIsActive = makeUseIsActive(useLocation);
|
|
14
|
-
export const useNavigate = () => () => undefined;
|
|
15
|
-
export const useParams = () => ({});
|
|
16
|
-
export const Link = ({ to, preventScrollReset, replace, ...attrs }) => {
|
|
17
|
-
const href = (typeof to === 'string'
|
|
18
|
-
? to
|
|
19
|
-
: (to.pathname || '') + (to.search || '') + (to.hash || ''));
|
|
20
|
-
return h('a', {
|
|
21
|
-
...attrs,
|
|
22
|
-
href
|
|
23
|
-
});
|
|
24
|
-
};
|
package/dist/index.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { useLocation as _useLocation } from 'react-router';
|
|
2
|
-
import { makeUseIsActive } from './is-active';
|
|
3
|
-
import { makeUseLocation } from './location';
|
|
4
|
-
export const needSuspense = false;
|
|
5
|
-
export const useLocation = makeUseLocation(_useLocation);
|
|
6
|
-
export const useIsActive = makeUseIsActive(useLocation);
|
|
7
|
-
export { Link, useNavigate, useParams } from 'react-router';
|
package/dist/is-active.mjs
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { URI } from '@react-foundry/uri';
|
|
2
|
-
const includes = (haystack, needle) => {
|
|
3
|
-
const subIncludes = (haystack, needle) => (Array.isArray(needle) ? (needle.length === haystack.length &&
|
|
4
|
-
needle.reduce((acc, cur, idx) => acc && subIncludes(haystack[idx], cur), true)) : (typeof needle === 'object' ? (typeof haystack === 'object' &&
|
|
5
|
-
Object.keys(needle).reduce((acc, cur) => acc && subIncludes(haystack[cur], needle[cur]), true)) : (needle === haystack)));
|
|
6
|
-
return subIncludes(haystack, needle);
|
|
7
|
-
};
|
|
8
|
-
export const makeUseIsActive = (useLocation) => () => {
|
|
9
|
-
const location = useLocation();
|
|
10
|
-
const isActive = (href, exact = true) => {
|
|
11
|
-
const target = URI.parse(href, location.pathname);
|
|
12
|
-
const dir = (target.pathname.endsWith('/')
|
|
13
|
-
? target.pathname
|
|
14
|
-
: target.pathname + '/');
|
|
15
|
-
const pathStart = (target.pathname === '' ||
|
|
16
|
-
location.pathname.startsWith(dir));
|
|
17
|
-
const pathMatch = (target.pathname === '' ||
|
|
18
|
-
location.pathname === target.pathname);
|
|
19
|
-
const queryMatch = includes(location.query, target.query);
|
|
20
|
-
const activeExact = !!(pathMatch && queryMatch);
|
|
21
|
-
const active = (exact
|
|
22
|
-
? activeExact
|
|
23
|
-
: !!(activeExact || (pathStart && queryMatch)));
|
|
24
|
-
return active;
|
|
25
|
-
};
|
|
26
|
-
return isActive;
|
|
27
|
-
};
|
package/dist/location.mjs
DELETED
package/dist/next.mjs
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { createElement as h } from 'react';
|
|
2
|
-
import { usePathname, useRouter, useSearchParams } from 'next/navigation';
|
|
3
|
-
import _Link from 'next/link';
|
|
4
|
-
import { makeUseIsActive } from './is-active';
|
|
5
|
-
import { makeUseLocation } from './location';
|
|
6
|
-
export const needSuspense = true;
|
|
7
|
-
const _useLocation = () => {
|
|
8
|
-
const pathname = usePathname();
|
|
9
|
-
const searchParams = useSearchParams();
|
|
10
|
-
const search = (searchParams.size
|
|
11
|
-
? '?' + searchParams.toString()
|
|
12
|
-
: '');
|
|
13
|
-
const location = {
|
|
14
|
-
state: undefined,
|
|
15
|
-
key: '',
|
|
16
|
-
pathname,
|
|
17
|
-
search,
|
|
18
|
-
hash: ''
|
|
19
|
-
};
|
|
20
|
-
return location;
|
|
21
|
-
};
|
|
22
|
-
export const useLocation = makeUseLocation(_useLocation);
|
|
23
|
-
export const useIsActive = makeUseIsActive(useLocation);
|
|
24
|
-
export const useNavigate = () => {
|
|
25
|
-
const router = useRouter();
|
|
26
|
-
const navigate = (to, options = {}) => {
|
|
27
|
-
if (typeof to === 'number') {
|
|
28
|
-
if (to === -1) {
|
|
29
|
-
router.back();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
const href = (to === 'string'
|
|
34
|
-
? to
|
|
35
|
-
: to.toString());
|
|
36
|
-
const nextOptions = {
|
|
37
|
-
scroll: !options.preventScrollReset
|
|
38
|
-
};
|
|
39
|
-
if (options.replace) {
|
|
40
|
-
router.replace(href, nextOptions);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
router.push(href, nextOptions);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
return navigate;
|
|
48
|
-
};
|
|
49
|
-
const prefetchMap = new Map([
|
|
50
|
-
[undefined, null],
|
|
51
|
-
['none', false],
|
|
52
|
-
['intent', true],
|
|
53
|
-
['render', true],
|
|
54
|
-
['viewport', true]
|
|
55
|
-
]);
|
|
56
|
-
export const Link = ({ to, prefetch: _prefetch, preventScrollReset, replace, ...attrs }) => {
|
|
57
|
-
const href = (typeof to === 'string'
|
|
58
|
-
? to
|
|
59
|
-
: {
|
|
60
|
-
...to,
|
|
61
|
-
hash: (to.hash !== '#'
|
|
62
|
-
? to.hash
|
|
63
|
-
: undefined)
|
|
64
|
-
});
|
|
65
|
-
const prefetch = prefetchMap.get(_prefetch);
|
|
66
|
-
return h(_Link, {
|
|
67
|
-
...attrs,
|
|
68
|
-
href,
|
|
69
|
-
prefetch,
|
|
70
|
-
replace,
|
|
71
|
-
scroll: !preventScrollReset
|
|
72
|
-
});
|
|
73
|
-
};
|
|
74
|
-
export { useParams } from 'next/navigation';
|
package/dist/remix.mjs
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { useLocation as _useLocation } from '@remix-run/react';
|
|
2
|
-
import { makeUseIsActive } from './is-active';
|
|
3
|
-
import { makeUseLocation } from './location';
|
|
4
|
-
export const needSuspense = false;
|
|
5
|
-
export const useLocation = makeUseLocation(_useLocation);
|
|
6
|
-
export const useIsActive = makeUseIsActive(useLocation);
|
|
7
|
-
export { Link, useNavigate, useParams } from '@remix-run/react';
|