@molecule/app-routing-react-router 1.1.3 → 1.2.1
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 +179 -112
- package/dist/dom.d.ts +50 -0
- package/dist/dom.d.ts.map +1 -0
- package/dist/dom.js +37 -0
- package/dist/dom.js.map +1 -0
- package/dist/hooks.d.ts +22 -3
- package/dist/hooks.d.ts.map +1 -1
- package/dist/hooks.js +79 -3
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +15 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -6
- package/dist/index.js.map +1 -1
- package/dist/lazyPage.d.ts +57 -0
- package/dist/lazyPage.d.ts.map +1 -0
- package/dist/lazyPage.js +62 -0
- package/dist/lazyPage.js.map +1 -0
- package/dist/routers.d.ts +102 -0
- package/dist/routers.d.ts.map +1 -0
- package/dist/routers.js +86 -0
- package/dist/routers.js.map +1 -0
- package/package.json +27 -2
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
|
|
|
3
3
|
Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
|
|
4
4
|
Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
|
|
5
5
|
To change this document, edit the module-level JSDoc in src/index.ts.
|
|
6
|
-
Generated: 2026-
|
|
6
|
+
Generated: 2026-11-01T08:49:45.245Z
|
|
7
7
|
-->
|
|
8
8
|
|
|
9
9
|
# @molecule/app-routing-react-router
|
|
@@ -26,8 +26,8 @@ It works under ordinary `BrowserRouter` without a data router or an extra provid
|
|
|
26
26
|
## Quick Start
|
|
27
27
|
|
|
28
28
|
```tsx
|
|
29
|
-
import {
|
|
30
|
-
import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
29
|
+
import { Routes, Route } from 'react-router'
|
|
30
|
+
import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
31
31
|
|
|
32
32
|
function App() {
|
|
33
33
|
// MoleculeRouterProvider bonds the adapter automatically (calls setRouter in an
|
|
@@ -160,7 +160,7 @@ const topics = useListRoute({
|
|
|
160
160
|
## Installation
|
|
161
161
|
|
|
162
162
|
```bash
|
|
163
|
-
npm install @molecule/app-routing-react-router @molecule/app-i18n @molecule/app-routing react react-router
|
|
163
|
+
npm install @molecule/app-routing-react-router @molecule/app-i18n @molecule/app-routing react react-dom react-router
|
|
164
164
|
npm install -D @types/react
|
|
165
165
|
```
|
|
166
166
|
|
|
@@ -191,6 +191,17 @@ interface MoleculeRouterProviderProps {
|
|
|
191
191
|
}
|
|
192
192
|
```
|
|
193
193
|
|
|
194
|
+
#### `LazyPageOptions`
|
|
195
|
+
|
|
196
|
+
Options for {@link lazyPage}.
|
|
197
|
+
|
|
198
|
+
```typescript
|
|
199
|
+
interface LazyPageOptions {
|
|
200
|
+
/** What the page's area shows while its code loads. Defaults to nothing. */
|
|
201
|
+
fallback?: ReactNode
|
|
202
|
+
}
|
|
203
|
+
```
|
|
204
|
+
|
|
194
205
|
#### `ListRouteFilter`
|
|
195
206
|
|
|
196
207
|
Where a list filter lives in the URL. Path values take precedence over query values.
|
|
@@ -498,111 +509,6 @@ interface RouteDefinition {
|
|
|
498
509
|
}
|
|
499
510
|
```
|
|
500
511
|
|
|
501
|
-
#### `Router`
|
|
502
|
-
|
|
503
|
-
Client-side router providing navigation, guards, route matching, and history control.
|
|
504
|
-
|
|
505
|
-
All routing providers must implement this interface.
|
|
506
|
-
|
|
507
|
-
```typescript
|
|
508
|
-
interface Router {
|
|
509
|
-
/**
|
|
510
|
-
* Returns the current route location (pathname, search, hash, state).
|
|
511
|
-
*/
|
|
512
|
-
getLocation(): RouteLocation
|
|
513
|
-
/**
|
|
514
|
-
* Gets the current route params.
|
|
515
|
-
*/
|
|
516
|
-
getParams<T extends RouteParams = RouteParams>(): T
|
|
517
|
-
/**
|
|
518
|
-
* Gets the current query params.
|
|
519
|
-
*/
|
|
520
|
-
getQuery(): QueryParams
|
|
521
|
-
/**
|
|
522
|
-
* Gets a specific query parameter.
|
|
523
|
-
*/
|
|
524
|
-
getQueryParam(key: string): string | undefined
|
|
525
|
-
/**
|
|
526
|
-
* Gets the current hash.
|
|
527
|
-
*/
|
|
528
|
-
getHash(): string
|
|
529
|
-
/**
|
|
530
|
-
* Navigates to a path.
|
|
531
|
-
*/
|
|
532
|
-
navigate(path: string, options?: NavigateOptions): void
|
|
533
|
-
/**
|
|
534
|
-
* Navigates to a named route.
|
|
535
|
-
*/
|
|
536
|
-
navigateTo(
|
|
537
|
-
name: string,
|
|
538
|
-
params?: RouteParams,
|
|
539
|
-
query?: QueryParams,
|
|
540
|
-
options?: NavigateOptions,
|
|
541
|
-
): void
|
|
542
|
-
/**
|
|
543
|
-
* Goes back in history.
|
|
544
|
-
*/
|
|
545
|
-
back(): void
|
|
546
|
-
/**
|
|
547
|
-
* Goes forward in history.
|
|
548
|
-
*/
|
|
549
|
-
forward(): void
|
|
550
|
-
/**
|
|
551
|
-
* Goes to a specific point in history.
|
|
552
|
-
*/
|
|
553
|
-
go(delta: number): void
|
|
554
|
-
/**
|
|
555
|
-
* Updates the current query params.
|
|
556
|
-
*/
|
|
557
|
-
setQuery(params: QueryParams, options?: NavigateOptions): void
|
|
558
|
-
/**
|
|
559
|
-
* Updates a specific query parameter.
|
|
560
|
-
*/
|
|
561
|
-
setQueryParam(key: string, value: string | undefined, options?: NavigateOptions): void
|
|
562
|
-
/**
|
|
563
|
-
* Updates the current hash.
|
|
564
|
-
*/
|
|
565
|
-
setHash(hash: string, options?: NavigateOptions): void
|
|
566
|
-
/**
|
|
567
|
-
* Checks if a path matches the current location.
|
|
568
|
-
*
|
|
569
|
-
* @returns `true` if the path matches the current route.
|
|
570
|
-
*/
|
|
571
|
-
isActive(path: string, exact?: boolean): boolean
|
|
572
|
-
/**
|
|
573
|
-
* Matches a path pattern against a pathname.
|
|
574
|
-
*/
|
|
575
|
-
matchPath<Params extends RouteParams = RouteParams>(
|
|
576
|
-
pattern: string,
|
|
577
|
-
pathname: string,
|
|
578
|
-
): RouteMatch<Params> | null
|
|
579
|
-
/**
|
|
580
|
-
* Generates a URL from a named route.
|
|
581
|
-
*/
|
|
582
|
-
generatePath(name: string, params?: RouteParams, query?: QueryParams): string
|
|
583
|
-
/**
|
|
584
|
-
* Subscribes to route changes.
|
|
585
|
-
*/
|
|
586
|
-
subscribe(listener: RouteChangeListener): () => void
|
|
587
|
-
/**
|
|
588
|
-
* Adds a navigation guard.
|
|
589
|
-
*/
|
|
590
|
-
addGuard(guard: NavigationGuard): () => void
|
|
591
|
-
/**
|
|
592
|
-
* Registers route definitions.
|
|
593
|
-
*/
|
|
594
|
-
registerRoutes(routes: RouteDefinition[]): void
|
|
595
|
-
/**
|
|
596
|
-
* Gets all registered routes.
|
|
597
|
-
*/
|
|
598
|
-
getRoutes(): RouteDefinition[]
|
|
599
|
-
/**
|
|
600
|
-
* Destroys the router.
|
|
601
|
-
*/
|
|
602
|
-
destroy(): void
|
|
603
|
-
}
|
|
604
|
-
```
|
|
605
|
-
|
|
606
512
|
#### `RouterConfig`
|
|
607
513
|
|
|
608
514
|
Configuration options for creating a router instance.
|
|
@@ -626,6 +532,62 @@ interface RouterConfig {
|
|
|
626
532
|
|
|
627
533
|
### Types
|
|
628
534
|
|
|
535
|
+
#### `LazyLoadableComponent`
|
|
536
|
+
|
|
537
|
+
Any component `React.lazy` can load.
|
|
538
|
+
|
|
539
|
+
```typescript
|
|
540
|
+
type LazyLoadableComponent = Awaited<ReturnType<Parameters<typeof lazy>[0]>>['default']
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
#### `BrowserRouterProps`
|
|
544
|
+
|
|
545
|
+
Props for {@link BrowserRouter}, with transitions permanently disabled.
|
|
546
|
+
|
|
547
|
+
```typescript
|
|
548
|
+
type BrowserRouterProps = Omit<ReactRouterBrowserRouterProps, 'useTransitions'>
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
#### `HashRouterProps`
|
|
552
|
+
|
|
553
|
+
Props for {@link HashRouter}, with transitions permanently disabled.
|
|
554
|
+
|
|
555
|
+
```typescript
|
|
556
|
+
type HashRouterProps = Omit<ReactRouterHashRouterProps, 'useTransitions'>
|
|
557
|
+
```
|
|
558
|
+
|
|
559
|
+
#### `MemoryRouterProps`
|
|
560
|
+
|
|
561
|
+
Props for {@link MemoryRouter}, with transitions permanently disabled.
|
|
562
|
+
|
|
563
|
+
```typescript
|
|
564
|
+
type MemoryRouterProps = Omit<ReactRouterMemoryRouterProps, 'useTransitions'>
|
|
565
|
+
```
|
|
566
|
+
|
|
567
|
+
#### `HistoryRouterProps`
|
|
568
|
+
|
|
569
|
+
Props for {@link unstable_HistoryRouter}, with transitions permanently disabled.
|
|
570
|
+
|
|
571
|
+
```typescript
|
|
572
|
+
type HistoryRouterProps = Omit<ReactRouterHistoryRouterProps, 'useTransitions'>
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
#### `RouterProps`
|
|
576
|
+
|
|
577
|
+
Props for {@link Router}, with transitions permanently disabled.
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
type RouterProps = Omit<ReactRouterProps, 'useTransitions'>
|
|
581
|
+
```
|
|
582
|
+
|
|
583
|
+
#### `RouterProviderProps`
|
|
584
|
+
|
|
585
|
+
Props for {@link RouterProvider}, with transitions permanently disabled.
|
|
586
|
+
|
|
587
|
+
```typescript
|
|
588
|
+
type RouterProviderProps = Omit<ReactRouterProviderProps, 'useTransitions'>
|
|
589
|
+
```
|
|
590
|
+
|
|
629
591
|
#### `RouteParams`
|
|
630
592
|
|
|
631
593
|
URL path parameter key-value map extracted from dynamic route segments (e.g. `{ id: '123' }`).
|
|
@@ -744,6 +706,50 @@ function useMoleculeQuery(): QueryParams
|
|
|
744
706
|
|
|
745
707
|
**Returns:** Query params object
|
|
746
708
|
|
|
709
|
+
#### `useConsumedSearchParam(name)`
|
|
710
|
+
|
|
711
|
+
Consume a credential query parameter into component state and remove only that parameter from
|
|
712
|
+
the address through React Router. The value survives local rerenders, StrictMode, failed-submit
|
|
713
|
+
retries and later query-only navigation; a newly arriving value on the same mounted route is
|
|
714
|
+
consumed too. Path, hash, unrelated query values and router location state are retained.
|
|
715
|
+
|
|
716
|
+
React Router owns the URL replacement, so `useLocation()` and `window.location` agree. A
|
|
717
|
+
metadata-only history merge retains unrelated pre-existing top-level state fields that React
|
|
718
|
+
Router does not model; it never changes the URL or the router's `usr`/`key`/`idx` fields.
|
|
719
|
+
|
|
720
|
+
```typescript
|
|
721
|
+
function useConsumedSearchParam(name: string): readonly [string, Dispatch<SetStateAction<string>>]
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
- `name` — The credential query key to consume, for example `token` or `code`.
|
|
725
|
+
|
|
726
|
+
**Returns:** The consumed value and its state setter; the value is empty before first consumption.
|
|
727
|
+
|
|
728
|
+
#### `lazyPage(load, options)`
|
|
729
|
+
|
|
730
|
+
Load a route's page on demand, inside a Suspense boundary that belongs to the page.
|
|
731
|
+
|
|
732
|
+
Use it instead of `React.lazy` for every page a `<Route>` renders. Navigating to a
|
|
733
|
+
page whose code has not loaded yet then replaces the previous page at once: the
|
|
734
|
+
previous page unmounts and the new page's own boundary shows `fallback` until its
|
|
735
|
+
code arrives. With `React.lazy` under one shared `<Suspense>` around `<Routes>`,
|
|
736
|
+
React keeps the previous page mounted (hidden) behind that boundary's fallback, so
|
|
737
|
+
the URL already names the new page while the old page's content is still in the
|
|
738
|
+
DOM, and a check such as `getByRole('heading')` finds the old page's headings.
|
|
739
|
+
Layout routes (an app shell around `<Outlet />`) stay mounted either way.
|
|
740
|
+
|
|
741
|
+
```typescript
|
|
742
|
+
function lazyPage<Page extends LazyLoadableComponent>(
|
|
743
|
+
load: () => Promise<{ default: Page }>,
|
|
744
|
+
options?: LazyPageOptions,
|
|
745
|
+
): ComponentType<NonNullable<ComponentProps<Page>>>
|
|
746
|
+
```
|
|
747
|
+
|
|
748
|
+
- `load` — Loads the page module, as for `React.lazy`: `() => import('./pages/Article.js').then((m) => ({ default: m.Article }))`.
|
|
749
|
+
- `options` — Optional `fallback` shown in the page's area while its code loads.
|
|
750
|
+
|
|
751
|
+
**Returns:** A component to use as a route's element: `<Route path="/article/:slug" element={<Article />} />`. Its props are the page's own, without the `undefined` an optional props parameter (`function Draft({ initial }: DraftProps = {})`) adds: a component type carrying it is not a valid JSX element type wherever React's types resolve from a second copy.
|
|
752
|
+
|
|
747
753
|
#### `createReactRouter(config)`
|
|
748
754
|
|
|
749
755
|
Creates a React Router adapter that implements the molecule Router interface.
|
|
@@ -756,6 +762,58 @@ function createReactRouter(config?: ReactRouterConfig): Router
|
|
|
756
762
|
|
|
757
763
|
**Returns:** A molecule `Router` with navigation, guards, query/hash management, and route matching.
|
|
758
764
|
|
|
765
|
+
#### `BrowserRouter(props)`
|
|
766
|
+
|
|
767
|
+
Browser router that commits the URL and rendered page together.
|
|
768
|
+
|
|
769
|
+
```typescript
|
|
770
|
+
function BrowserRouter(props: BrowserRouterProps): JSX.Element
|
|
771
|
+
```
|
|
772
|
+
|
|
773
|
+
#### `HashRouter(props)`
|
|
774
|
+
|
|
775
|
+
Hash router that commits the URL and rendered page together.
|
|
776
|
+
|
|
777
|
+
```typescript
|
|
778
|
+
function HashRouter(props: HashRouterProps): JSX.Element
|
|
779
|
+
```
|
|
780
|
+
|
|
781
|
+
#### `MemoryRouter(props)`
|
|
782
|
+
|
|
783
|
+
In-memory router that commits its location and rendered page together.
|
|
784
|
+
|
|
785
|
+
```typescript
|
|
786
|
+
function MemoryRouter(props: MemoryRouterProps): JSX.Element
|
|
787
|
+
```
|
|
788
|
+
|
|
789
|
+
#### `Router(props)`
|
|
790
|
+
|
|
791
|
+
Low-level router that commits its location and rendered page together.
|
|
792
|
+
|
|
793
|
+
```typescript
|
|
794
|
+
function Router(props: RouterProps): JSX.Element
|
|
795
|
+
```
|
|
796
|
+
|
|
797
|
+
#### `RouterProvider(props)`
|
|
798
|
+
|
|
799
|
+
Data-router provider that commits the URL and rendered page together.
|
|
800
|
+
|
|
801
|
+
This is React Router's renderer-neutral provider. In a DOM app, import
|
|
802
|
+
`RouterProvider` from `@molecule/app-routing-react-router/dom` instead, which
|
|
803
|
+
supplies `react-dom`'s `flushSync` the way `react-router/dom` does.
|
|
804
|
+
|
|
805
|
+
```typescript
|
|
806
|
+
function RouterProvider(props: RouterProviderProps): JSX.Element
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
#### `unstable_HistoryRouter(props)`
|
|
810
|
+
|
|
811
|
+
History router that commits the URL and rendered page together.
|
|
812
|
+
|
|
813
|
+
```typescript
|
|
814
|
+
function unstable_HistoryRouter(props: HistoryRouterProps): JSX.Element
|
|
815
|
+
```
|
|
816
|
+
|
|
759
817
|
#### `useListRoute(options)`
|
|
760
818
|
|
|
761
819
|
Own URL-backed pagination, filters and selected views without mirrored state or navigation effects.
|
|
@@ -896,6 +954,7 @@ Peer dependencies:
|
|
|
896
954
|
- `@molecule/app-i18n` ^1.0.1
|
|
897
955
|
- `@molecule/app-routing` ^1.0.1
|
|
898
956
|
- `react` ^18.0.0 || ^19.0.0
|
|
957
|
+
- `react-dom` ^18.0.0 || ^19.0.0
|
|
899
958
|
- `react-router` ^7.0.0 || ^8.0.0
|
|
900
959
|
|
|
901
960
|
### Runtime Dependencies
|
|
@@ -903,6 +962,7 @@ Peer dependencies:
|
|
|
903
962
|
- `@molecule/app-i18n`
|
|
904
963
|
- `@molecule/app-routing`
|
|
905
964
|
- `react`
|
|
965
|
+
- `react-dom`
|
|
906
966
|
- `react-router`
|
|
907
967
|
|
|
908
968
|
- `useListRoute` derives state from the URL on every render, including Back/Forward.
|
|
@@ -927,6 +987,13 @@ Peer dependencies:
|
|
|
927
987
|
no-hooks fallback (empty params, `window.location.href` navigation). Use
|
|
928
988
|
`MoleculeRouterProvider` (or `createReactRouter` with hook values) instead.
|
|
929
989
|
- The provider must live INSIDE `<BrowserRouter>` (it calls React Router hooks).
|
|
930
|
-
- **Import from
|
|
931
|
-
|
|
932
|
-
(`
|
|
990
|
+
- **Import router components from this bond, never directly from React Router.**
|
|
991
|
+
Its wrappers turn transitions off, so a navigation renders the new route in the
|
|
992
|
+
same commit as the URL change. Import non-router APIs (`Routes`, `Route`, `Link`,
|
|
993
|
+
hooks) from `'react-router'`. A DOM data router's `RouterProvider` and the
|
|
994
|
+
framework-mode `HydratedRouter` come from `@molecule/app-routing-react-router/dom`.
|
|
995
|
+
- **Declare pages loaded on demand with `lazyPage`, not `React.lazy`.** Each page then
|
|
996
|
+
has a Suspense boundary of its own, so navigating to a page whose code is still
|
|
997
|
+
loading removes the previous page at once. Under one shared `<Suspense>` around
|
|
998
|
+
`<Routes>`, React keeps the previous page mounted (hidden) until the new code
|
|
999
|
+
arrives, while the URL already names the new page.
|
package/dist/dom.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* DOM routers with transitions turned off: the data-router provider and the
|
|
3
|
+
* framework-mode hydrated router.
|
|
4
|
+
*
|
|
5
|
+
* Imported from `@molecule/app-routing-react-router/dom`, kept apart from the main
|
|
6
|
+
* entry because `react-router/dom` needs `react-dom`, which the main entry does not.
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import type { ComponentProps, JSX } from 'react';
|
|
11
|
+
import { HydratedRouter as ReactRouterHydratedRouter, type RouterProviderProps as ReactRouterDomProviderProps } from 'react-router/dom';
|
|
12
|
+
/** Props for the DOM {@link RouterProvider}, with transitions permanently disabled. */
|
|
13
|
+
export type RouterProviderProps = Omit<ReactRouterDomProviderProps, 'useTransitions'>;
|
|
14
|
+
/**
|
|
15
|
+
* Props for {@link HydratedRouter}, with transitions permanently disabled. Read from the
|
|
16
|
+
* component itself because `react-router/dom` 7.0.0 exports no `HydratedRouterProps`
|
|
17
|
+
* type, and this package supports every 7.x release.
|
|
18
|
+
*/
|
|
19
|
+
export type HydratedRouterProps = Omit<ComponentProps<typeof ReactRouterHydratedRouter>, 'useTransitions'>;
|
|
20
|
+
/**
|
|
21
|
+
* DOM data-router provider (`react-router/dom`'s, which supplies `react-dom`'s
|
|
22
|
+
* `flushSync`) that renders each navigation in the same commit as the URL change.
|
|
23
|
+
*
|
|
24
|
+
* @param props - The provider's props, without `useTransitions`.
|
|
25
|
+
* @returns React Router's DOM provider with `useTransitions={false}`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { createBrowserRouter } from 'react-router'
|
|
30
|
+
* import { RouterProvider } from '@molecule/app-routing-react-router/dom'
|
|
31
|
+
*
|
|
32
|
+
* const app = <RouterProvider router={createBrowserRouter(routes)} />
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function RouterProvider(props: RouterProviderProps): JSX.Element;
|
|
36
|
+
/**
|
|
37
|
+
* Framework-mode hydrated router that commits the URL and rendered page together.
|
|
38
|
+
*
|
|
39
|
+
* @param props - The hydrated router's props, without `useTransitions`.
|
|
40
|
+
* @returns React Router's `HydratedRouter` with `useTransitions={false}`.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```tsx
|
|
44
|
+
* import { HydratedRouter } from '@molecule/app-routing-react-router/dom'
|
|
45
|
+
*
|
|
46
|
+
* const app = <HydratedRouter />
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare function HydratedRouter(props: HydratedRouterProps): JSX.Element;
|
|
50
|
+
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../src/dom.tsx"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,GAAG,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,EACL,cAAc,IAAI,yBAAyB,EAE3C,KAAK,mBAAmB,IAAI,2BAA2B,EACxD,MAAM,kBAAkB,CAAA;AAEzB,uFAAuF;AACvF,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,2BAA2B,EAAE,gBAAgB,CAAC,CAAA;AAErF;;;;GAIG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CACpC,cAAc,CAAC,OAAO,yBAAyB,CAAC,EAChD,gBAAgB,CACjB,CAAA;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAEtE;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAEtE"}
|
package/dist/dom.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { HydratedRouter as ReactRouterHydratedRouter, RouterProvider as ReactRouterDomProvider, } from 'react-router/dom';
|
|
3
|
+
/**
|
|
4
|
+
* DOM data-router provider (`react-router/dom`'s, which supplies `react-dom`'s
|
|
5
|
+
* `flushSync`) that renders each navigation in the same commit as the URL change.
|
|
6
|
+
*
|
|
7
|
+
* @param props - The provider's props, without `useTransitions`.
|
|
8
|
+
* @returns React Router's DOM provider with `useTransitions={false}`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { createBrowserRouter } from 'react-router'
|
|
13
|
+
* import { RouterProvider } from '@molecule/app-routing-react-router/dom'
|
|
14
|
+
*
|
|
15
|
+
* const app = <RouterProvider router={createBrowserRouter(routes)} />
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export function RouterProvider(props) {
|
|
19
|
+
return _jsx(ReactRouterDomProvider, { ...props, useTransitions: false });
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Framework-mode hydrated router that commits the URL and rendered page together.
|
|
23
|
+
*
|
|
24
|
+
* @param props - The hydrated router's props, without `useTransitions`.
|
|
25
|
+
* @returns React Router's `HydratedRouter` with `useTransitions={false}`.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* import { HydratedRouter } from '@molecule/app-routing-react-router/dom'
|
|
30
|
+
*
|
|
31
|
+
* const app = <HydratedRouter />
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function HydratedRouter(props) {
|
|
35
|
+
return _jsx(ReactRouterHydratedRouter, { ...props, useTransitions: false });
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=dom.js.map
|
package/dist/dom.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dom.js","sourceRoot":"","sources":["../src/dom.tsx"],"names":[],"mappings":";AAWA,OAAO,EACL,cAAc,IAAI,yBAAyB,EAC3C,cAAc,IAAI,sBAAsB,GAEzC,MAAM,kBAAkB,CAAA;AAezB;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,OAAO,KAAC,sBAAsB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AACrE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,OAAO,KAAC,yBAAyB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AACxE,CAAC"}
|
package/dist/hooks.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* @module
|
|
5
5
|
*/
|
|
6
|
-
import React, { type ReactNode } from 'react';
|
|
6
|
+
import React, { type Dispatch, type ReactNode, type SetStateAction } from 'react';
|
|
7
7
|
import type { QueryParams, RouteDefinition, Router } from './types.js';
|
|
8
8
|
/**
|
|
9
9
|
* Provider props.
|
|
@@ -39,8 +39,8 @@ export interface MoleculeRouterProviderProps {
|
|
|
39
39
|
* @returns The rendered provider wrapping children with the router context.
|
|
40
40
|
* @example
|
|
41
41
|
* ```tsx
|
|
42
|
-
* import {
|
|
43
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
42
|
+
* import { Routes, Route } from 'react-router'
|
|
43
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
44
44
|
*
|
|
45
45
|
* function App() {
|
|
46
46
|
* // Bonds automatically — molecule packages' navigate() now drive React Router.
|
|
@@ -130,4 +130,23 @@ export declare function useMoleculeNavigate(): Router['navigate'];
|
|
|
130
130
|
* ```
|
|
131
131
|
*/
|
|
132
132
|
export declare function useMoleculeQuery(): QueryParams;
|
|
133
|
+
/**
|
|
134
|
+
* Consume a credential query parameter into component state and remove only that parameter from
|
|
135
|
+
* the address through React Router. The value survives local rerenders, StrictMode, failed-submit
|
|
136
|
+
* retries and later query-only navigation; a newly arriving value on the same mounted route is
|
|
137
|
+
* consumed too. Path, hash, unrelated query values and router location state are retained.
|
|
138
|
+
*
|
|
139
|
+
* React Router owns the URL replacement, so `useLocation()` and `window.location` agree. A
|
|
140
|
+
* metadata-only history merge retains unrelated pre-existing top-level state fields that React
|
|
141
|
+
* Router does not model; it never changes the URL or the router's `usr`/`key`/`idx` fields.
|
|
142
|
+
*
|
|
143
|
+
* @param name - The credential query key to consume, for example `token` or `code`.
|
|
144
|
+
* @returns The consumed value and its state setter; the value is empty before first consumption.
|
|
145
|
+
* @example
|
|
146
|
+
* ```tsx
|
|
147
|
+
* const [resetToken] = useConsumedSearchParam('token')
|
|
148
|
+
* // The form submits resetToken after the address no longer contains it.
|
|
149
|
+
* ```
|
|
150
|
+
*/
|
|
151
|
+
export declare function useConsumedSearchParam(name: string): readonly [string, Dispatch<SetStateAction<string>>];
|
|
133
152
|
//# sourceMappingURL=hooks.d.ts.map
|
package/dist/hooks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,
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time";
|
|
|
4
4
|
*
|
|
5
5
|
* @module
|
|
6
6
|
*/
|
|
7
|
-
import { createContext, useContext, useEffect, useMemo } from 'react';
|
|
7
|
+
import { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState, } from 'react';
|
|
8
8
|
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router';
|
|
9
9
|
import { t } from '@molecule/app-i18n';
|
|
10
10
|
import { setRouter } from '@molecule/app-routing';
|
|
@@ -30,8 +30,8 @@ const MoleculeRouterContext = createContext(null);
|
|
|
30
30
|
* @returns The rendered provider wrapping children with the router context.
|
|
31
31
|
* @example
|
|
32
32
|
* ```tsx
|
|
33
|
-
* import {
|
|
34
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
33
|
+
* import { Routes, Route } from 'react-router'
|
|
34
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
35
35
|
*
|
|
36
36
|
* function App() {
|
|
37
37
|
* // Bonds automatically — molecule packages' navigate() now drive React Router.
|
|
@@ -167,4 +167,80 @@ export function useMoleculeQuery() {
|
|
|
167
167
|
// Re-evaluate when search changes
|
|
168
168
|
return useMemo(() => router.getQuery(), [router, location.search]);
|
|
169
169
|
}
|
|
170
|
+
/**
|
|
171
|
+
* Consume a credential query parameter into component state and remove only that parameter from
|
|
172
|
+
* the address through React Router. The value survives local rerenders, StrictMode, failed-submit
|
|
173
|
+
* retries and later query-only navigation; a newly arriving value on the same mounted route is
|
|
174
|
+
* consumed too. Path, hash, unrelated query values and router location state are retained.
|
|
175
|
+
*
|
|
176
|
+
* React Router owns the URL replacement, so `useLocation()` and `window.location` agree. A
|
|
177
|
+
* metadata-only history merge retains unrelated pre-existing top-level state fields that React
|
|
178
|
+
* Router does not model; it never changes the URL or the router's `usr`/`key`/`idx` fields.
|
|
179
|
+
*
|
|
180
|
+
* @param name - The credential query key to consume, for example `token` or `code`.
|
|
181
|
+
* @returns The consumed value and its state setter; the value is empty before first consumption.
|
|
182
|
+
* @example
|
|
183
|
+
* ```tsx
|
|
184
|
+
* const [resetToken] = useConsumedSearchParam('token')
|
|
185
|
+
* // The form submits resetToken after the address no longer contains it.
|
|
186
|
+
* ```
|
|
187
|
+
*/
|
|
188
|
+
export function useConsumedSearchParam(name) {
|
|
189
|
+
const location = useLocation();
|
|
190
|
+
const navigate = useNavigate();
|
|
191
|
+
const current = new URLSearchParams(location.search).get(name) ?? '';
|
|
192
|
+
const [consumed, setConsumed] = useState(current);
|
|
193
|
+
const consumedByEntry = useRef(new Map());
|
|
194
|
+
const pending = useRef(undefined);
|
|
195
|
+
const latest = useRef(consumed);
|
|
196
|
+
latest.current = consumed;
|
|
197
|
+
const updateConsumed = useCallback((action) => {
|
|
198
|
+
setConsumed((previous) => {
|
|
199
|
+
const next = typeof action === 'function' ? action(previous) : action;
|
|
200
|
+
consumedByEntry.current.set(location.key, next);
|
|
201
|
+
return next;
|
|
202
|
+
});
|
|
203
|
+
}, [location.key]);
|
|
204
|
+
useEffect(() => {
|
|
205
|
+
const params = new URLSearchParams(location.search);
|
|
206
|
+
if (!params.has(name)) {
|
|
207
|
+
const pendingValue = pending.current;
|
|
208
|
+
if (pendingValue !== undefined) {
|
|
209
|
+
consumedByEntry.current.set(location.key, pendingValue);
|
|
210
|
+
pending.current = undefined;
|
|
211
|
+
}
|
|
212
|
+
else if (consumedByEntry.current.has(location.key)) {
|
|
213
|
+
setConsumed(consumedByEntry.current.get(location.key) ?? '');
|
|
214
|
+
}
|
|
215
|
+
else if (latest.current) {
|
|
216
|
+
// Query-only navigation creates a new key but not a new credential link.
|
|
217
|
+
consumedByEntry.current.set(location.key, latest.current);
|
|
218
|
+
}
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const value = params.get(name) ?? '';
|
|
222
|
+
pending.current = value;
|
|
223
|
+
setConsumed(value);
|
|
224
|
+
params.delete(name);
|
|
225
|
+
const search = params.toString();
|
|
226
|
+
const previousHistoryState = typeof window === 'undefined' ? undefined : window.history.state;
|
|
227
|
+
navigate({
|
|
228
|
+
pathname: location.pathname,
|
|
229
|
+
search: search ? `?${search}` : '',
|
|
230
|
+
hash: location.hash,
|
|
231
|
+
}, { replace: true, state: location.state });
|
|
232
|
+
if (previousHistoryState !== null &&
|
|
233
|
+
typeof previousHistoryState === 'object' &&
|
|
234
|
+
typeof window !== 'undefined') {
|
|
235
|
+
const retained = Object.fromEntries(Object.entries(previousHistoryState).filter(([key]) => !['usr', 'key', 'idx', 'masked'].includes(key)));
|
|
236
|
+
if (Object.keys(retained).length > 0) {
|
|
237
|
+
window.history.replaceState({ ...retained, ...window.history.state }, '', window.location.href);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}, [location, navigate, name]);
|
|
241
|
+
return [
|
|
242
|
+
current || (consumedByEntry.current.get(location.key) ?? consumed),
|
|
243
|
+
updateConsumed,
|
|
244
|
+
];
|
|
245
|
+
}
|
|
170
246
|
//# sourceMappingURL=hooks.js.map
|
package/dist/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAc,
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../src/hooks.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAc,EACZ,aAAa,EAIb,WAAW,EACX,UAAU,EACV,SAAS,EACT,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAA;AACd,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEnF,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGjD;;GAEG;AACH,MAAM,qBAAqB,GAAG,a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,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAC1D,CACF,CAAA;YACD,IAAI,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACrC,MAAM,CAAC,OAAO,CAAC,YAAY,CACzB,EAAE,GAAG,QAAQ,EAAE,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,EACxC,EAAE,EACF,MAAM,CAAC,QAAQ,CAAC,IAAI,CACrB,CAAA;YACH,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC,CAAA;IAE9B,OAAO;QACL,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,QAAQ,CAAC;QAClE,cAAc;KACN,CAAA;AACZ,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```tsx
|
|
15
|
-
* import {
|
|
16
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
15
|
+
* import { Routes, Route } from 'react-router'
|
|
16
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
17
17
|
*
|
|
18
18
|
* function App() {
|
|
19
19
|
* // MoleculeRouterProvider bonds the adapter automatically (calls setRouter in an
|
|
@@ -136,16 +136,25 @@
|
|
|
136
136
|
* no-hooks fallback (empty params, `window.location.href` navigation). Use
|
|
137
137
|
* `MoleculeRouterProvider` (or `createReactRouter` with hook values) instead.
|
|
138
138
|
* - The provider must live INSIDE `<BrowserRouter>` (it calls React Router hooks).
|
|
139
|
-
* - **Import from
|
|
140
|
-
*
|
|
141
|
-
* (`
|
|
139
|
+
* - **Import router components from this bond, never directly from React Router.**
|
|
140
|
+
* Its wrappers turn transitions off, so a navigation renders the new route in the
|
|
141
|
+
* same commit as the URL change. Import non-router APIs (`Routes`, `Route`, `Link`,
|
|
142
|
+
* hooks) from `'react-router'`. A DOM data router's `RouterProvider` and the
|
|
143
|
+
* framework-mode `HydratedRouter` come from `@molecule/app-routing-react-router/dom`.
|
|
144
|
+
* - **Declare pages loaded on demand with `lazyPage`, not `React.lazy`.** Each page then
|
|
145
|
+
* has a Suspense boundary of its own, so navigating to a page whose code is still
|
|
146
|
+
* loading removes the previous page at once. Under one shared `<Suspense>` around
|
|
147
|
+
* `<Routes>`, React keeps the previous page mounted (hidden) until the new code
|
|
148
|
+
* arrives, while the URL already names the new page.
|
|
142
149
|
*
|
|
143
150
|
* @module @molecule/app-routing-react-router
|
|
144
151
|
*/
|
|
145
152
|
export * from './hooks.js';
|
|
153
|
+
export * from './lazyPage.js';
|
|
146
154
|
export * from './list-types.js';
|
|
147
155
|
export * from './provider.js';
|
|
148
|
-
export * from './
|
|
156
|
+
export * from './routers.js';
|
|
157
|
+
export type { GuardResult, NavigateOptions, NavigationGuard, QueryParams, ReactRouterConfig, ReactRouterHooks, RouteChangeListener, RouteDefinition, RouteLocation, RouteMatch, RouteParams, RouterConfig, } from './types.js';
|
|
149
158
|
export * from './useListRoute.js';
|
|
150
159
|
export * from './utilities.js';
|
|
151
160
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsJG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,YAAY,EACV,WAAW,EACX,eAAe,EACf,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,GACb,MAAM,YAAY,CAAA;AACnB,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -12,8 +12,8 @@
|
|
|
12
12
|
*
|
|
13
13
|
* @example
|
|
14
14
|
* ```tsx
|
|
15
|
-
* import {
|
|
16
|
-
* import { MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
15
|
+
* import { Routes, Route } from 'react-router'
|
|
16
|
+
* import { BrowserRouter, MoleculeRouterProvider } from '@molecule/app-routing-react-router'
|
|
17
17
|
*
|
|
18
18
|
* function App() {
|
|
19
19
|
* // MoleculeRouterProvider bonds the adapter automatically (calls setRouter in an
|
|
@@ -136,16 +136,24 @@
|
|
|
136
136
|
* no-hooks fallback (empty params, `window.location.href` navigation). Use
|
|
137
137
|
* `MoleculeRouterProvider` (or `createReactRouter` with hook values) instead.
|
|
138
138
|
* - The provider must live INSIDE `<BrowserRouter>` (it calls React Router hooks).
|
|
139
|
-
* - **Import from
|
|
140
|
-
*
|
|
141
|
-
* (`
|
|
139
|
+
* - **Import router components from this bond, never directly from React Router.**
|
|
140
|
+
* Its wrappers turn transitions off, so a navigation renders the new route in the
|
|
141
|
+
* same commit as the URL change. Import non-router APIs (`Routes`, `Route`, `Link`,
|
|
142
|
+
* hooks) from `'react-router'`. A DOM data router's `RouterProvider` and the
|
|
143
|
+
* framework-mode `HydratedRouter` come from `@molecule/app-routing-react-router/dom`.
|
|
144
|
+
* - **Declare pages loaded on demand with `lazyPage`, not `React.lazy`.** Each page then
|
|
145
|
+
* has a Suspense boundary of its own, so navigating to a page whose code is still
|
|
146
|
+
* loading removes the previous page at once. Under one shared `<Suspense>` around
|
|
147
|
+
* `<Routes>`, React keeps the previous page mounted (hidden) until the new code
|
|
148
|
+
* arrives, while the URL already names the new page.
|
|
142
149
|
*
|
|
143
150
|
* @module @molecule/app-routing-react-router
|
|
144
151
|
*/
|
|
145
152
|
export * from './hooks.js';
|
|
153
|
+
export * from './lazyPage.js';
|
|
146
154
|
export * from './list-types.js';
|
|
147
155
|
export * from './provider.js';
|
|
148
|
-
export * from './
|
|
156
|
+
export * from './routers.js';
|
|
149
157
|
export * from './useListRoute.js';
|
|
150
158
|
export * from './utilities.js';
|
|
151
159
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsJG;AAEH,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAe5B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route pages loaded on demand, each inside a Suspense boundary of its own.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type ComponentProps, type ComponentType, lazy, type ReactNode } from 'react';
|
|
7
|
+
/** Any component `React.lazy` can load. */
|
|
8
|
+
export type LazyLoadableComponent = Awaited<ReturnType<Parameters<typeof lazy>[0]>>['default'];
|
|
9
|
+
/** Options for {@link lazyPage}. */
|
|
10
|
+
export interface LazyPageOptions {
|
|
11
|
+
/** What the page's area shows while its code loads. Defaults to nothing. */
|
|
12
|
+
fallback?: ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Load a route's page on demand, inside a Suspense boundary that belongs to the page.
|
|
16
|
+
*
|
|
17
|
+
* Use it instead of `React.lazy` for every page a `<Route>` renders. Navigating to a
|
|
18
|
+
* page whose code has not loaded yet then replaces the previous page at once: the
|
|
19
|
+
* previous page unmounts and the new page's own boundary shows `fallback` until its
|
|
20
|
+
* code arrives. With `React.lazy` under one shared `<Suspense>` around `<Routes>`,
|
|
21
|
+
* React keeps the previous page mounted (hidden) behind that boundary's fallback, so
|
|
22
|
+
* the URL already names the new page while the old page's content is still in the
|
|
23
|
+
* DOM, and a check such as `getByRole('heading')` finds the old page's headings.
|
|
24
|
+
* Layout routes (an app shell around `<Outlet />`) stay mounted either way.
|
|
25
|
+
*
|
|
26
|
+
* @param load - Loads the page module, as for `React.lazy`:
|
|
27
|
+
* `() => import('./pages/Article.js').then((m) => ({ default: m.Article }))`.
|
|
28
|
+
* @param options - Optional `fallback` shown in the page's area while its code loads.
|
|
29
|
+
* @returns A component to use as a route's element: `<Route path="/article/:slug" element={<Article />} />`.
|
|
30
|
+
* Its props are the page's own, without the `undefined` an optional props parameter
|
|
31
|
+
* (`function Draft({ initial }: DraftProps = {})`) adds: a component type carrying it is
|
|
32
|
+
* not a valid JSX element type wherever React's types resolve from a second copy.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import { Route, Routes } from 'react-router'
|
|
37
|
+
* import { BrowserRouter, lazyPage } from '@molecule/app-routing-react-router'
|
|
38
|
+
*
|
|
39
|
+
* const Home = lazyPage(() => import('./pages/Home.js').then((m) => ({ default: m.Home })))
|
|
40
|
+
* const Article = lazyPage(() =>
|
|
41
|
+
* import('./pages/Article.js').then((m) => ({ default: m.Article })),
|
|
42
|
+
* )
|
|
43
|
+
*
|
|
44
|
+
* const app = (
|
|
45
|
+
* <BrowserRouter>
|
|
46
|
+
* <Routes>
|
|
47
|
+
* <Route path="/" element={<Home />} />
|
|
48
|
+
* <Route path="/article/:slug" element={<Article />} />
|
|
49
|
+
* </Routes>
|
|
50
|
+
* </BrowserRouter>
|
|
51
|
+
* )
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function lazyPage<Page extends LazyLoadableComponent>(load: () => Promise<{
|
|
55
|
+
default: Page;
|
|
56
|
+
}>, options?: LazyPageOptions): ComponentType<NonNullable<ComponentProps<Page>>>;
|
|
57
|
+
//# sourceMappingURL=lazyPage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyPage.d.ts","sourceRoot":"","sources":["../src/lazyPage.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,aAAa,EAElB,IAAI,EACJ,KAAK,SAAS,EAEf,MAAM,OAAO,CAAA;AAEd,2CAA2C;AAC3C,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;AAE9F,oCAAoC;AACpC,MAAM,WAAW,eAAe;IAC9B,4EAA4E;IAC5E,QAAQ,CAAC,EAAE,SAAS,CAAA;CACrB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,wBAAgB,QAAQ,CAAC,IAAI,SAAS,qBAAqB,EACzD,IAAI,EAAE,MAAM,OAAO,CAAC;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAAC,EACtC,OAAO,GAAE,eAAoB,GAC5B,aAAa,CAAC,WAAW,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAiBlD"}
|
package/dist/lazyPage.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Route pages loaded on demand, each inside a Suspense boundary of its own.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { lazy, Suspense, } from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* Load a route's page on demand, inside a Suspense boundary that belongs to the page.
|
|
10
|
+
*
|
|
11
|
+
* Use it instead of `React.lazy` for every page a `<Route>` renders. Navigating to a
|
|
12
|
+
* page whose code has not loaded yet then replaces the previous page at once: the
|
|
13
|
+
* previous page unmounts and the new page's own boundary shows `fallback` until its
|
|
14
|
+
* code arrives. With `React.lazy` under one shared `<Suspense>` around `<Routes>`,
|
|
15
|
+
* React keeps the previous page mounted (hidden) behind that boundary's fallback, so
|
|
16
|
+
* the URL already names the new page while the old page's content is still in the
|
|
17
|
+
* DOM, and a check such as `getByRole('heading')` finds the old page's headings.
|
|
18
|
+
* Layout routes (an app shell around `<Outlet />`) stay mounted either way.
|
|
19
|
+
*
|
|
20
|
+
* @param load - Loads the page module, as for `React.lazy`:
|
|
21
|
+
* `() => import('./pages/Article.js').then((m) => ({ default: m.Article }))`.
|
|
22
|
+
* @param options - Optional `fallback` shown in the page's area while its code loads.
|
|
23
|
+
* @returns A component to use as a route's element: `<Route path="/article/:slug" element={<Article />} />`.
|
|
24
|
+
* Its props are the page's own, without the `undefined` an optional props parameter
|
|
25
|
+
* (`function Draft({ initial }: DraftProps = {})`) adds: a component type carrying it is
|
|
26
|
+
* not a valid JSX element type wherever React's types resolve from a second copy.
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* ```tsx
|
|
30
|
+
* import { Route, Routes } from 'react-router'
|
|
31
|
+
* import { BrowserRouter, lazyPage } from '@molecule/app-routing-react-router'
|
|
32
|
+
*
|
|
33
|
+
* const Home = lazyPage(() => import('./pages/Home.js').then((m) => ({ default: m.Home })))
|
|
34
|
+
* const Article = lazyPage(() =>
|
|
35
|
+
* import('./pages/Article.js').then((m) => ({ default: m.Article })),
|
|
36
|
+
* )
|
|
37
|
+
*
|
|
38
|
+
* const app = (
|
|
39
|
+
* <BrowserRouter>
|
|
40
|
+
* <Routes>
|
|
41
|
+
* <Route path="/" element={<Home />} />
|
|
42
|
+
* <Route path="/article/:slug" element={<Article />} />
|
|
43
|
+
* </Routes>
|
|
44
|
+
* </BrowserRouter>
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export function lazyPage(load, options = {}) {
|
|
49
|
+
const Loaded = lazy(load);
|
|
50
|
+
const fallback = options.fallback ?? null;
|
|
51
|
+
/**
|
|
52
|
+
* The page inside its own Suspense boundary.
|
|
53
|
+
*
|
|
54
|
+
* @param props - The page's props, passed through.
|
|
55
|
+
* @returns The page, or `fallback` while its code loads.
|
|
56
|
+
*/
|
|
57
|
+
function LazyPage(props) {
|
|
58
|
+
return (_jsx(Suspense, { fallback: fallback, children: _jsx(Loaded, { ...props }) }));
|
|
59
|
+
}
|
|
60
|
+
return LazyPage;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=lazyPage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazyPage.js","sourceRoot":"","sources":["../src/lazyPage.tsx"],"names":[],"mappings":";AAAA;;;;GAIG;AAEH,OAAO,EAIL,IAAI,EAEJ,QAAQ,GACT,MAAM,OAAO,CAAA;AAWd;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AACH,MAAM,UAAU,QAAQ,CACtB,IAAsC,EACtC,UAA2B,EAAE;IAE7B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;IACzB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAA;IACzC;;;;;OAKG;IACH,SAAS,QAAQ,CAAC,KAAwC;QACxD,OAAO,CACL,KAAC,QAAQ,IAAC,QAAQ,EAAE,QAAQ,YAC1B,KAAC,MAAM,OAAK,KAAK,GAAI,GACZ,CACZ,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React Router components with transitions turned off.
|
|
3
|
+
*
|
|
4
|
+
* Each wrapper renders React Router's own router with `useTransitions={false}`, so a
|
|
5
|
+
* navigation renders the new route in the same commit that changes the URL instead of
|
|
6
|
+
* keeping the previous route on screen while the next one prepares. That alone does not
|
|
7
|
+
* cover a page whose code loads on demand: under one shared `<Suspense>` React keeps
|
|
8
|
+
* the previous page mounted (hidden) until the new page's code arrives. Declare such
|
|
9
|
+
* pages with {@link lazyPage}, which gives each page a boundary of its own. React Router
|
|
10
|
+
* versions without the `useTransitions` prop ignore it.
|
|
11
|
+
*
|
|
12
|
+
* @module
|
|
13
|
+
*/
|
|
14
|
+
import type { JSX } from 'react';
|
|
15
|
+
import { type BrowserRouterProps as ReactRouterBrowserRouterProps, type HashRouterProps as ReactRouterHashRouterProps, type HistoryRouterProps as ReactRouterHistoryRouterProps, type MemoryRouterProps as ReactRouterMemoryRouterProps, type RouterProps as ReactRouterProps, type RouterProviderProps as ReactRouterProviderProps } from 'react-router';
|
|
16
|
+
import type { Router as MoleculeRouter } from '@molecule/app-routing';
|
|
17
|
+
/** The molecule router interface, retained alongside the React Router component value. */
|
|
18
|
+
export type Router = MoleculeRouter;
|
|
19
|
+
/** Props for {@link BrowserRouter}, with transitions permanently disabled. */
|
|
20
|
+
export type BrowserRouterProps = Omit<ReactRouterBrowserRouterProps, 'useTransitions'>;
|
|
21
|
+
/** Props for {@link HashRouter}, with transitions permanently disabled. */
|
|
22
|
+
export type HashRouterProps = Omit<ReactRouterHashRouterProps, 'useTransitions'>;
|
|
23
|
+
/** Props for {@link MemoryRouter}, with transitions permanently disabled. */
|
|
24
|
+
export type MemoryRouterProps = Omit<ReactRouterMemoryRouterProps, 'useTransitions'>;
|
|
25
|
+
/** Props for {@link unstable_HistoryRouter}, with transitions permanently disabled. */
|
|
26
|
+
export type HistoryRouterProps = Omit<ReactRouterHistoryRouterProps, 'useTransitions'>;
|
|
27
|
+
/** Props for {@link Router}, with transitions permanently disabled. */
|
|
28
|
+
export type RouterProps = Omit<ReactRouterProps, 'useTransitions'>;
|
|
29
|
+
/** Props for {@link RouterProvider}, with transitions permanently disabled. */
|
|
30
|
+
export type RouterProviderProps = Omit<ReactRouterProviderProps, 'useTransitions'>;
|
|
31
|
+
/**
|
|
32
|
+
* Browser router that commits the URL and rendered page together.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* import { BrowserRouter } from '@molecule/app-routing-react-router'
|
|
37
|
+
*
|
|
38
|
+
* const app = <BrowserRouter><Routes /></BrowserRouter>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare function BrowserRouter(props: BrowserRouterProps): JSX.Element;
|
|
42
|
+
/**
|
|
43
|
+
* Hash router that commits the URL and rendered page together.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { HashRouter } from '@molecule/app-routing-react-router'
|
|
48
|
+
*
|
|
49
|
+
* const app = <HashRouter><Routes /></HashRouter>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function HashRouter(props: HashRouterProps): JSX.Element;
|
|
53
|
+
/**
|
|
54
|
+
* In-memory router that commits its location and rendered page together.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* import { MemoryRouter } from '@molecule/app-routing-react-router'
|
|
59
|
+
*
|
|
60
|
+
* const app = <MemoryRouter initialEntries={['/']}><Routes /></MemoryRouter>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function MemoryRouter(props: MemoryRouterProps): JSX.Element;
|
|
64
|
+
/**
|
|
65
|
+
* Low-level router that commits its location and rendered page together.
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```tsx
|
|
69
|
+
* import { Router } from '@molecule/app-routing-react-router'
|
|
70
|
+
*
|
|
71
|
+
* const app = <Router location={location} navigator={navigator}><Routes /></Router>
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function Router(props: RouterProps): JSX.Element;
|
|
75
|
+
/**
|
|
76
|
+
* Data-router provider that commits the URL and rendered page together.
|
|
77
|
+
*
|
|
78
|
+
* This is React Router's renderer-neutral provider. In a DOM app, import
|
|
79
|
+
* `RouterProvider` from `@molecule/app-routing-react-router/dom` instead, which
|
|
80
|
+
* supplies `react-dom`'s `flushSync` the way `react-router/dom` does.
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* import { RouterProvider } from '@molecule/app-routing-react-router'
|
|
85
|
+
*
|
|
86
|
+
* const app = <RouterProvider router={router} flushSync={flushSync} />
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
export declare function RouterProvider(props: RouterProviderProps): JSX.Element;
|
|
90
|
+
/**
|
|
91
|
+
* History router that commits the URL and rendered page together.
|
|
92
|
+
*
|
|
93
|
+
* @example
|
|
94
|
+
* ```tsx
|
|
95
|
+
* import { unstable_HistoryRouter } from '@molecule/app-routing-react-router'
|
|
96
|
+
*
|
|
97
|
+
* const app = <unstable_HistoryRouter history={history}><Routes /></unstable_HistoryRouter>
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
declare function HistoryRouter(props: HistoryRouterProps): JSX.Element;
|
|
101
|
+
export { HistoryRouter as unstable_HistoryRouter };
|
|
102
|
+
//# sourceMappingURL=routers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{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E,eAAe,GAAG,GAAG,CAAC,OAAO,CAE9D;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,GAAG,CAAC,OAAO,CAElE;AAED;;;;;;;;;GASG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,GAAG,CAAC,OAAO,CAEtD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,GAAG,CAAC,OAAO,CAEtE;AAED;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,GAAG,CAAC,OAAO,CAE7D;AAED,OAAO,EAAE,aAAa,IAAI,sBAAsB,EAAE,CAAA"}
|
package/dist/routers.js
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { BrowserRouter as ReactRouterBrowserRouter, HashRouter as ReactRouterHashRouter, MemoryRouter as ReactRouterMemoryRouter, Router as ReactRouter, RouterProvider as ReactRouterProvider, unstable_HistoryRouter as ReactRouterHistoryRouter, } from 'react-router';
|
|
3
|
+
/**
|
|
4
|
+
* Browser router that commits the URL and rendered page together.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```tsx
|
|
8
|
+
* import { BrowserRouter } from '@molecule/app-routing-react-router'
|
|
9
|
+
*
|
|
10
|
+
* const app = <BrowserRouter><Routes /></BrowserRouter>
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
export function BrowserRouter(props) {
|
|
14
|
+
return _jsx(ReactRouterBrowserRouter, { ...props, useTransitions: false });
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Hash router that commits the URL and rendered page together.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* import { HashRouter } from '@molecule/app-routing-react-router'
|
|
22
|
+
*
|
|
23
|
+
* const app = <HashRouter><Routes /></HashRouter>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export function HashRouter(props) {
|
|
27
|
+
return _jsx(ReactRouterHashRouter, { ...props, useTransitions: false });
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* In-memory router that commits its location and rendered page together.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* import { MemoryRouter } from '@molecule/app-routing-react-router'
|
|
35
|
+
*
|
|
36
|
+
* const app = <MemoryRouter initialEntries={['/']}><Routes /></MemoryRouter>
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export function MemoryRouter(props) {
|
|
40
|
+
return _jsx(ReactRouterMemoryRouter, { ...props, useTransitions: false });
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Low-level router that commits its location and rendered page together.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { Router } from '@molecule/app-routing-react-router'
|
|
48
|
+
*
|
|
49
|
+
* const app = <Router location={location} navigator={navigator}><Routes /></Router>
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export function Router(props) {
|
|
53
|
+
return _jsx(ReactRouter, { ...props, useTransitions: false });
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Data-router provider that commits the URL and rendered page together.
|
|
57
|
+
*
|
|
58
|
+
* This is React Router's renderer-neutral provider. In a DOM app, import
|
|
59
|
+
* `RouterProvider` from `@molecule/app-routing-react-router/dom` instead, which
|
|
60
|
+
* supplies `react-dom`'s `flushSync` the way `react-router/dom` does.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* import { RouterProvider } from '@molecule/app-routing-react-router'
|
|
65
|
+
*
|
|
66
|
+
* const app = <RouterProvider router={router} flushSync={flushSync} />
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
export function RouterProvider(props) {
|
|
70
|
+
return _jsx(ReactRouterProvider, { ...props, useTransitions: false });
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* History router that commits the URL and rendered page together.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```tsx
|
|
77
|
+
* import { unstable_HistoryRouter } from '@molecule/app-routing-react-router'
|
|
78
|
+
*
|
|
79
|
+
* const app = <unstable_HistoryRouter history={history}><Routes /></unstable_HistoryRouter>
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
function HistoryRouter(props) {
|
|
83
|
+
return _jsx(ReactRouterHistoryRouter, { ...props, useTransitions: false });
|
|
84
|
+
}
|
|
85
|
+
export { HistoryRouter as unstable_HistoryRouter };
|
|
86
|
+
//# sourceMappingURL=routers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routers.js","sourceRoot":"","sources":["../src/routers.tsx"],"names":[],"mappings":";AAeA,OAAO,EACL,aAAa,IAAI,wBAAwB,EAEzC,UAAU,IAAI,qBAAqB,EAGnC,YAAY,IAAI,uBAAuB,EAEvC,MAAM,IAAI,WAAW,EAErB,cAAc,IAAI,mBAAmB,EAErC,sBAAsB,IAAI,wBAAwB,GACnD,MAAM,cAAc,CAAA;AAyBrB;;;;;;;;;GASG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,OAAO,KAAC,wBAAwB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AACvE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,OAAO,KAAC,qBAAqB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AACpE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,YAAY,CAAC,KAAwB;IACnD,OAAO,KAAC,uBAAuB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AACtE,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,MAAM,CAAC,KAAkB;IACvC,OAAO,KAAC,WAAW,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AAC1D,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,cAAc,CAAC,KAA0B;IACvD,OAAO,KAAC,mBAAmB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AAClE,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,aAAa,CAAC,KAAyB;IAC9C,OAAO,KAAC,wBAAwB,OAAK,KAAK,EAAE,cAAc,EAAE,KAAK,GAAI,CAAA;AACvE,CAAC;AAED,OAAO,EAAE,aAAa,IAAI,sBAAsB,EAAE,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-routing-react-router",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "React Router v7 provider for @molecule/app-routing",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./dom": {
|
|
15
|
+
"types": "./dist/dom.d.ts",
|
|
16
|
+
"import": "./dist/dom.js",
|
|
17
|
+
"default": "./dist/dom.js"
|
|
18
|
+
},
|
|
19
|
+
"./dist": "./dist/index.js",
|
|
20
|
+
"./dist/*.d.ts.map": "./dist/*.d.ts.map",
|
|
21
|
+
"./dist/*.d.ts": "./dist/*.d.ts",
|
|
22
|
+
"./dist/*.js": "./dist/*.js",
|
|
23
|
+
"./dist/*": "./dist/*.js",
|
|
24
|
+
"./package.json": "./package.json"
|
|
25
|
+
},
|
|
8
26
|
"files": [
|
|
9
27
|
"dist",
|
|
10
28
|
"README.md"
|
|
@@ -25,13 +43,20 @@
|
|
|
25
43
|
"@molecule/app-i18n": "^1.0.1",
|
|
26
44
|
"@molecule/app-routing": "^1.0.1",
|
|
27
45
|
"react": "^18.0.0 || ^19.0.0",
|
|
46
|
+
"react-dom": "^18.0.0 || ^19.0.0",
|
|
28
47
|
"react-router": "^7.0.0 || ^8.0.0"
|
|
29
48
|
},
|
|
49
|
+
"peerDependenciesMeta": {
|
|
50
|
+
"react-dom": {
|
|
51
|
+
"optional": true
|
|
52
|
+
}
|
|
53
|
+
},
|
|
30
54
|
"devDependencies": {
|
|
31
|
-
"@molecule/app-i18n": "1.1.
|
|
55
|
+
"@molecule/app-i18n": "1.1.2",
|
|
32
56
|
"@types/node": "26.6.5",
|
|
33
57
|
"@types/react": "19.3.0",
|
|
34
58
|
"react": "19.3.1",
|
|
59
|
+
"react-dom": "19.3.1",
|
|
35
60
|
"react-router": "8.5.0",
|
|
36
61
|
"typescript": "6.0.3",
|
|
37
62
|
"vitest": "4.1.12"
|