@molecule/app-routing-react-router 1.2.5 → 1.4.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 +203 -84
- package/dist/ListRouteNav.d.ts +52 -0
- package/dist/ListRouteNav.d.ts.map +1 -0
- package/dist/ListRouteNav.js +48 -0
- package/dist/ListRouteNav.js.map +1 -0
- package/dist/history.d.ts +80 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +188 -0
- package/dist/history.js.map +1 -0
- package/dist/hooks.d.ts +19 -14
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +113 -46
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +28 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/list-types.d.ts +7 -85
- package/dist/list-types.d.ts.map +1 -1
- package/dist/list-types.js +6 -0
- package/dist/list-types.js.map +1 -1
- package/dist/provider.d.ts +12 -3
- package/dist/provider.d.ts.map +1 -1
- package/dist/provider.js +51 -231
- package/dist/provider.js.map +1 -1
- package/dist/useListRoute.d.ts +6 -0
- package/dist/useListRoute.d.ts.map +1 -1
- package/dist/useListRoute.js +16 -162
- package/dist/useListRoute.js.map +1 -1
- package/dist/utilities.js +1 -1
- package/dist/utilities.js.map +1 -1
- package/package.json +11 -4
package/dist/list-types.d.ts
CHANGED
|
@@ -1,86 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** Value returned when neither URL source supplies a value; omitted from generated queries. */
|
|
9
|
-
defaultValue?: string;
|
|
10
|
-
}
|
|
11
|
-
/** A selectable list view, expressed in the app's own route contract. */
|
|
12
|
-
export interface ListRouteSelection {
|
|
13
|
-
/** Absolute route pattern, for example `/members/:member/saved`. */
|
|
14
|
-
path: string;
|
|
15
|
-
/** Query values identifying this view. An undefined value requires the key to be absent. */
|
|
16
|
-
query?: QueryParams;
|
|
17
|
-
/** A protected selection never loads before authentication is confirmed. */
|
|
18
|
-
requiresAuth?: boolean;
|
|
19
|
-
}
|
|
20
|
-
/** Authentication readiness for protected list selections. */
|
|
21
|
-
export interface ListRouteAuth {
|
|
22
|
-
/** The auth client's status. Unavailable is distinct from a signed-out session. */
|
|
23
|
-
status: 'loading' | 'authenticated' | 'unauthenticated' | 'unavailable';
|
|
24
|
-
/** App-owned sign-in URL. A signed-out protected visit replaces history with this URL. */
|
|
25
|
-
redirectTo: string;
|
|
26
|
-
}
|
|
27
|
-
/** URL-backed list state configuration; it neither invents nor rewrites the app's route contract. */
|
|
28
|
-
export interface ListRouteOptions<Filter extends string = string, Selection extends string = string> {
|
|
29
|
-
/** Fixed number of items per page; defaults to 20. */
|
|
30
|
-
pageSize?: number;
|
|
31
|
-
/** Query key for a 1-indexed page; defaults to `page`. Page one omits the key. */
|
|
32
|
-
pageParam?: string;
|
|
33
|
-
/** Route pattern for changing path-backed filters when no selections are configured. */
|
|
34
|
-
path?: string;
|
|
35
|
-
/** Filters and their URL sources. API-only filters do not belong here. */
|
|
36
|
-
filters?: Record<Filter, ListRouteFilter>;
|
|
37
|
-
/** Named views sharing a list. Both path variants and query variants are supported. */
|
|
38
|
-
selections?: Record<Selection, ListRouteSelection>;
|
|
39
|
-
/** Tie-breaker when multiple selections match, or fallback when none matches. */
|
|
40
|
-
defaultSelection?: NoInfer<Selection>;
|
|
41
|
-
/** Required when a selection is protected. Public views remain public as auth changes. */
|
|
42
|
-
auth?: ListRouteAuth;
|
|
43
|
-
}
|
|
44
|
-
/** A single atomic list navigation. Filter/selection changes reset page unless explicitly supplied. */
|
|
45
|
-
export interface ListRouteChange<Filter extends string = string, Selection extends string = string> {
|
|
46
|
-
/** Target page, starting at one. */
|
|
47
|
-
page?: number;
|
|
48
|
-
/** Patch of URL filter values. Undefined removes a query filter. */
|
|
49
|
-
filters?: Partial<Record<Filter, string | undefined>>;
|
|
50
|
-
/** Target view, resolved through its configured path and query values. */
|
|
51
|
-
selection?: Selection;
|
|
52
|
-
/** Optional path parameter changes, for example when opening a different member's saved view. */
|
|
53
|
-
params?: RouteParams;
|
|
54
|
-
}
|
|
55
|
-
/** Reactive list state and navigation, derived directly from React Router's current location. */
|
|
56
|
-
export interface ListRouteResult<Filter extends string = string, Selection extends string = string> {
|
|
57
|
-
/** Current 1-indexed page; malformed and non-positive URL values read as page one. */
|
|
58
|
-
page: number;
|
|
59
|
-
/** Configured items per page. */
|
|
60
|
-
pageSize: number;
|
|
61
|
-
/** Zero-indexed item offset for an API request. */
|
|
62
|
-
offset: number;
|
|
63
|
-
/** Current URL filter values, including values supplied by path parameters. */
|
|
64
|
-
filters: Record<Filter, string | undefined>;
|
|
65
|
-
/** Matching view, or the configured fallback. */
|
|
66
|
-
selection: Selection | undefined;
|
|
67
|
-
/** Decoded current path parameters, also usable as API-only filters. */
|
|
68
|
-
params: RouteParams;
|
|
69
|
-
/** False while a protected selection is awaiting auth, signed out, or unavailable. */
|
|
70
|
-
canLoad: boolean;
|
|
71
|
-
/** Readiness for the current view. A public view always stays ready. */
|
|
72
|
-
status: 'ready' | 'loading' | 'unauthenticated' | 'unavailable';
|
|
73
|
-
/** Sign-in destination while a signed-out protected view is being redirected. */
|
|
74
|
-
redirectTo: string | undefined;
|
|
75
|
-
/** Build a real link target, preserving the current pathname, unrelated query values and hash. */
|
|
76
|
-
href: (change?: ListRouteChange<Filter, Selection>) => string;
|
|
77
|
-
/** Navigate atomically. Location state is preserved unless options explicitly replace it. */
|
|
78
|
-
navigate: (change: ListRouteChange<Filter, Selection>, options?: NavigateOptions) => void;
|
|
79
|
-
/** Change only the page, retaining the current filters and view. */
|
|
80
|
-
setPage: (page: number, options?: NavigateOptions) => void;
|
|
81
|
-
/** Patch URL filters and return to page one. */
|
|
82
|
-
setFilters: (filters: Partial<Record<Filter, string | undefined>>, options?: NavigateOptions) => void;
|
|
83
|
-
/** Select a configured view at page one, preserving current route parameters. */
|
|
84
|
-
select: (selection: Selection, options?: NavigateOptions) => void;
|
|
85
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Types for URL-backed lists ({@link useListRoute}): the same types every framework's
|
|
3
|
+
* `useListRoute` uses, from `@molecule/app-routing`.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
export type { ListRouteAuth, ListRouteChange, ListRouteFilter, ListRouteOptions, ListRouteResult, ListRouteSelection, } from '@molecule/app-routing';
|
|
86
8
|
//# sourceMappingURL=list-types.d.ts.map
|
package/dist/list-types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-types.d.ts","sourceRoot":"","sources":["../src/list-types.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"list-types.d.ts","sourceRoot":"","sources":["../src/list-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACV,aAAa,EACb,eAAe,EACf,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,kBAAkB,GACnB,MAAM,uBAAuB,CAAA"}
|
package/dist/list-types.js
CHANGED
package/dist/list-types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-types.js","sourceRoot":"","sources":["../src/list-types.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"list-types.js","sourceRoot":"","sources":["../src/list-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG"}
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,15 +1,25 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React Router (v7/v8) provider implementation.
|
|
3
3
|
*
|
|
4
|
+
* `createReactRouter` is `@molecule/app-routing`'s `createHistoryRouter` over the config
|
|
5
|
+
* snapshot: navigation, guards, query/hash helpers, named routes and matching all come
|
|
6
|
+
* from the shared core, so this bond behaves like every other routing bond.
|
|
7
|
+
*
|
|
4
8
|
* @module
|
|
5
9
|
*/
|
|
6
10
|
import type { ReactRouterConfig, Router } from './types.js';
|
|
7
11
|
/**
|
|
8
|
-
* Creates a React Router adapter that implements the molecule Router interface
|
|
12
|
+
* Creates a React Router adapter that implements the molecule Router interface over a
|
|
13
|
+
* config snapshot: the `navigate` function, `location` and `params` of one render. The
|
|
14
|
+
* snapshot never changes, so every read answers for that render — the hooks
|
|
15
|
+
* (`MoleculeRouterProvider`, `useMoleculeRouter`) build the live router instead, one
|
|
16
|
+
* that follows React Router for its whole life. Navigation runs React Router's
|
|
17
|
+
* `navigate`, falling back to a full-page `window.location` navigation when no
|
|
18
|
+
* `navigate` was given (the hook-less `provider`).
|
|
9
19
|
*
|
|
10
20
|
* @example
|
|
11
21
|
* ```tsx
|
|
12
|
-
* import { useNavigate, useLocation, useParams
|
|
22
|
+
* import { useNavigate, useLocation, useParams } from 'react-router'
|
|
13
23
|
* import { createReactRouter, setRouter } from '@molecule/app-routing-react-router'
|
|
14
24
|
* import { useEffect, useMemo } from 'react'
|
|
15
25
|
*
|
|
@@ -17,7 +27,6 @@ import type { ReactRouterConfig, Router } from './types.js';
|
|
|
17
27
|
* const navigate = useNavigate()
|
|
18
28
|
* const location = useLocation()
|
|
19
29
|
* const params = useParams()
|
|
20
|
-
* const [searchParams] = useSearchParams()
|
|
21
30
|
*
|
|
22
31
|
* const router = useMemo(() => createReactRouter({
|
|
23
32
|
* navigate,
|
package/dist/provider.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAMH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAkD3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,iBAAiB,GAAI,SAAQ,iBAAsB,KAAG,MAGhE,CAAA;AAEH;;;GAGG;AACH,eAAO,MAAM,QAAQ,QAAsB,CAAA"}
|
package/dist/provider.js
CHANGED
|
@@ -1,16 +1,62 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React Router (v7/v8) provider implementation.
|
|
3
3
|
*
|
|
4
|
+
* `createReactRouter` is `@molecule/app-routing`'s `createHistoryRouter` over the config
|
|
5
|
+
* snapshot: navigation, guards, query/hash helpers, named routes and matching all come
|
|
6
|
+
* from the shared core, so this bond behaves like every other routing bond.
|
|
7
|
+
*
|
|
4
8
|
* @module
|
|
5
9
|
*/
|
|
6
|
-
import { I18nError } from '@molecule/app-i18n';
|
|
7
|
-
import {
|
|
10
|
+
import { I18nError, t } from '@molecule/app-i18n';
|
|
11
|
+
import { createHistoryRouter } from '@molecule/app-routing';
|
|
12
|
+
import { createReactRouterSnapshotHistory } from './history.js';
|
|
13
|
+
/**
|
|
14
|
+
* The message the core's named routes throw with for a missing name, as this exact
|
|
15
|
+
* `t()` call renders it. Comparing against the same call the core makes keeps the
|
|
16
|
+
* detection exact in every locale.
|
|
17
|
+
*
|
|
18
|
+
* @param name - The route name that was looked up.
|
|
19
|
+
* @returns The interpolated route-not-found message.
|
|
20
|
+
*/
|
|
21
|
+
const routeNotFoundMessage = (name) => t('routing.error.routeNotFound', { name }, { defaultValue: 'Route "{{name}}" not found' });
|
|
22
|
+
/**
|
|
23
|
+
* Rethrows the core's route-not-found `Error` as the bond's `I18nError`, so the key and
|
|
24
|
+
* values travel with the error for re-translation. The core owns the named-route logic;
|
|
25
|
+
* only the error type is this bond's contract.
|
|
26
|
+
*
|
|
27
|
+
* @param router - The router `createHistoryRouter` built.
|
|
28
|
+
* @returns The same router with the named-route methods rethrowing `I18nError`.
|
|
29
|
+
*/
|
|
30
|
+
const withI18nRouteErrors = (router) => {
|
|
31
|
+
const generatePath = router.generatePath.bind(router);
|
|
32
|
+
const navigateTo = router.navigateTo.bind(router);
|
|
33
|
+
const rethrowNamedRouteError = (name, action) => {
|
|
34
|
+
try {
|
|
35
|
+
return action();
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
if (error instanceof Error && error.message === routeNotFoundMessage(name)) {
|
|
39
|
+
throw new I18nError('routing.error.routeNotFound', { name }, 'Route "{{name}}" not found', error);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
router.generatePath = (name, routeParams, query) => rethrowNamedRouteError(name, () => generatePath(name, routeParams, query));
|
|
45
|
+
router.navigateTo = (name, routeParams, query, options) => rethrowNamedRouteError(name, () => navigateTo(name, routeParams, query, options));
|
|
46
|
+
return router;
|
|
47
|
+
};
|
|
8
48
|
/**
|
|
9
|
-
* Creates a React Router adapter that implements the molecule Router interface
|
|
49
|
+
* Creates a React Router adapter that implements the molecule Router interface over a
|
|
50
|
+
* config snapshot: the `navigate` function, `location` and `params` of one render. The
|
|
51
|
+
* snapshot never changes, so every read answers for that render — the hooks
|
|
52
|
+
* (`MoleculeRouterProvider`, `useMoleculeRouter`) build the live router instead, one
|
|
53
|
+
* that follows React Router for its whole life. Navigation runs React Router's
|
|
54
|
+
* `navigate`, falling back to a full-page `window.location` navigation when no
|
|
55
|
+
* `navigate` was given (the hook-less `provider`).
|
|
10
56
|
*
|
|
11
57
|
* @example
|
|
12
58
|
* ```tsx
|
|
13
|
-
* import { useNavigate, useLocation, useParams
|
|
59
|
+
* import { useNavigate, useLocation, useParams } from 'react-router'
|
|
14
60
|
* import { createReactRouter, setRouter } from '@molecule/app-routing-react-router'
|
|
15
61
|
* import { useEffect, useMemo } from 'react'
|
|
16
62
|
*
|
|
@@ -18,7 +64,6 @@ import { generatePath, matchPath, parseSearchParams, stringifyQuery } from './ut
|
|
|
18
64
|
* const navigate = useNavigate()
|
|
19
65
|
* const location = useLocation()
|
|
20
66
|
* const params = useParams()
|
|
21
|
-
* const [searchParams] = useSearchParams()
|
|
22
67
|
*
|
|
23
68
|
* const router = useMemo(() => createReactRouter({
|
|
24
69
|
* navigate,
|
|
@@ -36,232 +81,7 @@ import { generatePath, matchPath, parseSearchParams, stringifyQuery } from './ut
|
|
|
36
81
|
* @param config - Configuration with React Router's `navigate` function, `location`, `params`, and optional `routes`.
|
|
37
82
|
* @returns A molecule `Router` with navigation, guards, query/hash management, and route matching.
|
|
38
83
|
*/
|
|
39
|
-
export const createReactRouter = (config = {}) => {
|
|
40
|
-
const { navigate: navigateFn, location: locationObj, params = {}, routes = [] } = config;
|
|
41
|
-
let registeredRoutes = [...routes];
|
|
42
|
-
const listeners = new Set();
|
|
43
|
-
const guards = [];
|
|
44
|
-
const namedRoutes = new Map();
|
|
45
|
-
// Index named routes
|
|
46
|
-
const indexRoutes = (routeList, prefix = '') => {
|
|
47
|
-
for (const route of routeList) {
|
|
48
|
-
const fullPath = prefix + route.path;
|
|
49
|
-
if (route.name) {
|
|
50
|
-
namedRoutes.set(route.name, { ...route, path: fullPath });
|
|
51
|
-
}
|
|
52
|
-
if (route.children) {
|
|
53
|
-
indexRoutes(route.children, fullPath);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
indexRoutes(routes);
|
|
58
|
-
// Build current location
|
|
59
|
-
const getCurrentLocation = () => {
|
|
60
|
-
if (locationObj) {
|
|
61
|
-
return {
|
|
62
|
-
pathname: locationObj.pathname,
|
|
63
|
-
search: locationObj.search,
|
|
64
|
-
hash: locationObj.hash,
|
|
65
|
-
state: locationObj.state,
|
|
66
|
-
key: locationObj.key,
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
if (typeof window !== 'undefined') {
|
|
70
|
-
return {
|
|
71
|
-
pathname: window.location.pathname,
|
|
72
|
-
search: window.location.search,
|
|
73
|
-
hash: window.location.hash,
|
|
74
|
-
key: Math.random().toString(36).slice(2),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
pathname: '/',
|
|
79
|
-
search: '',
|
|
80
|
-
hash: '',
|
|
81
|
-
key: Math.random().toString(36).slice(2),
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
const normalizeParams = (p) => {
|
|
85
|
-
const result = {};
|
|
86
|
-
for (const [key, value] of Object.entries(p)) {
|
|
87
|
-
if (value !== undefined) {
|
|
88
|
-
result[key] = value;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return result;
|
|
92
|
-
};
|
|
93
|
-
const runGuards = async (to, from) => {
|
|
94
|
-
for (const guard of guards) {
|
|
95
|
-
const result = await guard(to, from);
|
|
96
|
-
if (result !== undefined && result !== true) {
|
|
97
|
-
return result;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
};
|
|
102
|
-
const notify = (action) => {
|
|
103
|
-
const location = getCurrentLocation();
|
|
104
|
-
listeners.forEach((listener) => listener(location, action));
|
|
105
|
-
};
|
|
106
|
-
const doNavigate = async (path, options = {}) => {
|
|
107
|
-
const { replace = false, preserveQuery, preserveHash, state } = options;
|
|
108
|
-
const currentLocation = getCurrentLocation();
|
|
109
|
-
let fullPath = path;
|
|
110
|
-
if (preserveQuery && currentLocation.search) {
|
|
111
|
-
fullPath += currentLocation.search;
|
|
112
|
-
}
|
|
113
|
-
if (preserveHash && currentLocation.hash) {
|
|
114
|
-
fullPath += currentLocation.hash;
|
|
115
|
-
}
|
|
116
|
-
const newLocation = {
|
|
117
|
-
pathname: fullPath.split('?')[0].split('#')[0],
|
|
118
|
-
search: fullPath.includes('?') ? `?${fullPath.split('?')[1].split('#')[0]}` : '',
|
|
119
|
-
hash: fullPath.includes('#') ? `#${fullPath.split('#')[1]}` : '',
|
|
120
|
-
state,
|
|
121
|
-
key: Math.random().toString(36).slice(2),
|
|
122
|
-
};
|
|
123
|
-
const guardResult = await runGuards(newLocation, currentLocation);
|
|
124
|
-
if (guardResult === false)
|
|
125
|
-
return;
|
|
126
|
-
if (typeof guardResult === 'string') {
|
|
127
|
-
doNavigate(guardResult, { replace: true });
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
if (typeof guardResult === 'object' && 'path' in guardResult) {
|
|
131
|
-
doNavigate(guardResult.path, { replace: guardResult.replace });
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (navigateFn) {
|
|
135
|
-
navigateFn(fullPath, { replace, state });
|
|
136
|
-
}
|
|
137
|
-
else if (typeof window !== 'undefined') {
|
|
138
|
-
// Fallback to window.location
|
|
139
|
-
if (replace) {
|
|
140
|
-
window.location.replace(fullPath);
|
|
141
|
-
}
|
|
142
|
-
else {
|
|
143
|
-
window.location.href = fullPath;
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
notify(replace ? 'replace' : 'push');
|
|
147
|
-
};
|
|
148
|
-
const router = {
|
|
149
|
-
getLocation: getCurrentLocation,
|
|
150
|
-
getParams() {
|
|
151
|
-
return normalizeParams(params);
|
|
152
|
-
},
|
|
153
|
-
getQuery: () => {
|
|
154
|
-
const location = getCurrentLocation();
|
|
155
|
-
const searchParams = new URLSearchParams(location.search);
|
|
156
|
-
return parseSearchParams(searchParams);
|
|
157
|
-
},
|
|
158
|
-
getQueryParam: (key) => {
|
|
159
|
-
const location = getCurrentLocation();
|
|
160
|
-
const searchParams = new URLSearchParams(location.search);
|
|
161
|
-
return searchParams.get(key) ?? undefined;
|
|
162
|
-
},
|
|
163
|
-
getHash: () => getCurrentLocation().hash,
|
|
164
|
-
navigate: doNavigate,
|
|
165
|
-
navigateTo(name, routeParams, query, options) {
|
|
166
|
-
const route = namedRoutes.get(name);
|
|
167
|
-
if (!route) {
|
|
168
|
-
throw new I18nError('routing.error.routeNotFound', { name }, `Route "${name}" not found`);
|
|
169
|
-
}
|
|
170
|
-
let path = generatePath(route.path, routeParams);
|
|
171
|
-
if (query) {
|
|
172
|
-
path += stringifyQuery(query);
|
|
173
|
-
}
|
|
174
|
-
doNavigate(path, options);
|
|
175
|
-
},
|
|
176
|
-
back() {
|
|
177
|
-
if (navigateFn) {
|
|
178
|
-
navigateFn(-1);
|
|
179
|
-
}
|
|
180
|
-
else if (typeof window !== 'undefined') {
|
|
181
|
-
window.history.back();
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
forward() {
|
|
185
|
-
if (navigateFn) {
|
|
186
|
-
navigateFn(1);
|
|
187
|
-
}
|
|
188
|
-
else if (typeof window !== 'undefined') {
|
|
189
|
-
window.history.forward();
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
go(delta) {
|
|
193
|
-
if (navigateFn) {
|
|
194
|
-
navigateFn(delta);
|
|
195
|
-
}
|
|
196
|
-
else if (typeof window !== 'undefined') {
|
|
197
|
-
window.history.go(delta);
|
|
198
|
-
}
|
|
199
|
-
},
|
|
200
|
-
setQuery(query, options) {
|
|
201
|
-
const location = getCurrentLocation();
|
|
202
|
-
const path = location.pathname + stringifyQuery(query) + location.hash;
|
|
203
|
-
doNavigate(path, options);
|
|
204
|
-
},
|
|
205
|
-
setQueryParam(key, value, options) {
|
|
206
|
-
const query = this.getQuery();
|
|
207
|
-
if (value === undefined) {
|
|
208
|
-
delete query[key];
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
query[key] = value;
|
|
212
|
-
}
|
|
213
|
-
this.setQuery(query, options);
|
|
214
|
-
},
|
|
215
|
-
setHash(hash, options) {
|
|
216
|
-
const location = getCurrentLocation();
|
|
217
|
-
const normalizedHash = hash.startsWith('#') ? hash : `#${hash}`;
|
|
218
|
-
const path = location.pathname + location.search + normalizedHash;
|
|
219
|
-
doNavigate(path, options);
|
|
220
|
-
},
|
|
221
|
-
isActive(path, exact) {
|
|
222
|
-
const location = getCurrentLocation();
|
|
223
|
-
const match = matchPath(path, location.pathname, exact);
|
|
224
|
-
return match !== null;
|
|
225
|
-
},
|
|
226
|
-
matchPath(pattern, pathToMatch) {
|
|
227
|
-
return matchPath(pattern, pathToMatch);
|
|
228
|
-
},
|
|
229
|
-
generatePath(name, routeParams, query) {
|
|
230
|
-
const route = namedRoutes.get(name);
|
|
231
|
-
if (!route) {
|
|
232
|
-
throw new I18nError('routing.error.routeNotFound', { name }, `Route "${name}" not found`);
|
|
233
|
-
}
|
|
234
|
-
let path = generatePath(route.path, routeParams);
|
|
235
|
-
if (query) {
|
|
236
|
-
path += stringifyQuery(query);
|
|
237
|
-
}
|
|
238
|
-
return path;
|
|
239
|
-
},
|
|
240
|
-
subscribe(listener) {
|
|
241
|
-
listeners.add(listener);
|
|
242
|
-
return () => listeners.delete(listener);
|
|
243
|
-
},
|
|
244
|
-
addGuard(guard) {
|
|
245
|
-
guards.push(guard);
|
|
246
|
-
return () => {
|
|
247
|
-
const index = guards.indexOf(guard);
|
|
248
|
-
if (index !== -1) {
|
|
249
|
-
guards.splice(index, 1);
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
},
|
|
253
|
-
registerRoutes(newRoutes) {
|
|
254
|
-
registeredRoutes = [...registeredRoutes, ...newRoutes];
|
|
255
|
-
indexRoutes(newRoutes);
|
|
256
|
-
},
|
|
257
|
-
getRoutes: () => registeredRoutes,
|
|
258
|
-
destroy() {
|
|
259
|
-
listeners.clear();
|
|
260
|
-
guards.length = 0;
|
|
261
|
-
},
|
|
262
|
-
};
|
|
263
|
-
return router;
|
|
264
|
-
};
|
|
84
|
+
export const createReactRouter = (config = {}) => withI18nRouteErrors(createHistoryRouter(createReactRouterSnapshotHistory(config), { routes: config.routes }));
|
|
265
85
|
/**
|
|
266
86
|
* Default React Router provider (basic, no hooks). For full functionality, use
|
|
267
87
|
* `createReactRouter` with `useNavigate`/`useLocation`/`useParams`.
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACjD,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAA;AAE3D,OAAO,EAAE,gCAAgC,EAAE,MAAM,cAAc,CAAA;AAG/D;;;;;;;GAOG;AACH,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAU,EAAE,CACpD,CAAC,CAAC,6BAA6B,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,YAAY,EAAE,4BAA4B,EAAE,CAAC,CAAA;AAE5F;;;;;;;GAOG;AACH,MAAM,mBAAmB,GAAG,CAAC,MAAc,EAAU,EAAE;IACrD,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IACrD,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;IAEjD,MAAM,sBAAsB,GAAG,CAAI,IAAY,EAAE,MAAe,EAAK,EAAE;QACrE,IAAI,CAAC;YACH,OAAO,MAAM,EAAE,CAAA;QACjB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,OAAO,KAAK,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC3E,MAAM,IAAI,SAAS,CACjB,6BAA6B,EAC7B,EAAE,IAAI,EAAE,EACR,4BAA4B,EAC5B,KAAK,CACN,CAAA;YACH,CAAC;YACD,MAAM,KAAK,CAAA;QACb,CAAC;IACH,CAAC,CAAA;IAED,MAAM,CAAC,YAAY,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,EAAE,CACjD,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC,CAAA;IAE5E,MAAM,CAAC,UAAU,GAAG,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CACxD,sBAAsB,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,WAAW,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC,CAAA;IAEnF,OAAO,MAAM,CAAA;AACf,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,SAA4B,EAAE,EAAU,EAAE,CAC1E,mBAAmB,CACjB,mBAAmB,CAAC,gCAAgC,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CACzF,CAAA;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,EAAE,CAAA"}
|
package/dist/useListRoute.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `useListRoute` over React Router: the list rules come from `@molecule/app-routing`'s
|
|
3
|
+
* `resolveListRoute`, which every framework's `useListRoute` shares.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
1
7
|
import type { ListRouteOptions, ListRouteResult } from './list-types.js';
|
|
2
8
|
/**
|
|
3
9
|
* Own URL-backed pagination, filters and selected views without mirrored state or navigation effects.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useListRoute.d.ts","sourceRoot":"","sources":["../src/useListRoute.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useListRoute.d.ts","sourceRoot":"","sources":["../src/useListRoute.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,OAAO,KAAK,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAExE;;;;;;;;;;GAUG;AACH,wBAAgB,YAAY,CAAC,MAAM,SAAS,MAAM,GAAG,MAAM,EAAE,SAAS,SAAS,MAAM,GAAG,MAAM,EAC5F,OAAO,GAAE,gBAAgB,CAAC,MAAM,EAAE,SAAS,CAAM,GAChD,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,CAiBpC"}
|