react-router 0.0.0-experimental-c7dd3d3a → 0.0.0-experimental-e53172d16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +1 -10
  3. package/dist/index.d.ts +37 -16
  4. package/dist/index.js +9809 -1087
  5. package/dist/index.js.map +1 -1
  6. package/dist/lib/components.d.ts +13 -2
  7. package/dist/lib/context.d.ts +2 -2
  8. package/dist/lib/dom/dom.d.ts +104 -0
  9. package/dist/lib/dom/global.d.ts +36 -0
  10. package/dist/lib/dom/lib.d.ts +304 -0
  11. package/dist/lib/dom/server.d.ts +32 -0
  12. package/dist/lib/dom/ssr/browser.d.ts +3 -0
  13. package/dist/lib/dom/ssr/components.d.ts +61 -0
  14. package/dist/lib/dom/ssr/create-remix-stub.d.ts +56 -0
  15. package/dist/lib/dom/ssr/data.d.ts +16 -0
  16. package/dist/lib/dom/ssr/errorBoundaries.d.ts +33 -0
  17. package/dist/lib/dom/ssr/errors.d.ts +2 -0
  18. package/dist/lib/dom/ssr/fallback.d.ts +2 -0
  19. package/dist/lib/dom/ssr/invariant.d.ts +2 -0
  20. package/dist/lib/dom/ssr/links.d.ts +127 -0
  21. package/dist/lib/dom/ssr/markup.d.ts +5 -0
  22. package/dist/lib/dom/ssr/routeModules.d.ts +141 -0
  23. package/dist/lib/dom/ssr/routes.d.ts +32 -0
  24. package/dist/lib/dom/ssr/server.d.ts +13 -0
  25. package/dist/lib/dom/ssr/single-fetch.d.ts +36 -0
  26. package/dist/lib/hooks.d.ts +3 -3
  27. package/dist/lib/router/history.d.ts +250 -0
  28. package/dist/lib/router/index.d.ts +9 -0
  29. package/dist/lib/router/router.d.ts +512 -0
  30. package/dist/lib/router/utils.d.ts +520 -0
  31. package/dist/main.js +1 -1
  32. package/dist/react-router.development.js +10495 -1126
  33. package/dist/react-router.development.js.map +1 -1
  34. package/dist/react-router.production.min.js +2 -2
  35. package/dist/react-router.production.min.js.map +1 -1
  36. package/dist/umd/react-router.development.js +10876 -1287
  37. package/dist/umd/react-router.development.js.map +1 -1
  38. package/dist/umd/react-router.production.min.js +2 -2
  39. package/dist/umd/react-router.production.min.js.map +1 -1
  40. package/package.json +12 -5
@@ -0,0 +1,9 @@
1
+ export type { ActionFunction, ActionFunctionArgs, AgnosticDataIndexRouteObject, AgnosticDataNonIndexRouteObject, AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticIndexRouteObject, AgnosticNonIndexRouteObject, AgnosticRouteMatch, AgnosticRouteObject, DataStrategyFunction as unstable_DataStrategyFunction, DataStrategyFunctionArgs as unstable_DataStrategyFunctionArgs, DataStrategyMatch as unstable_DataStrategyMatch, ErrorResponse, FormEncType, FormMethod, HandlerResult as unstable_HandlerResult, HTMLFormMethod, JsonFunction, LazyRouteFunction, LoaderFunction, LoaderFunctionArgs, ParamParseKey, Params, PathMatch, PathParam, PathPattern, RedirectFunction, ShouldRevalidateFunction, ShouldRevalidateFunctionArgs, TrackedPromise, UIMatch, V7_FormMethod, } from "./utils";
2
+ export { AbortedDeferredError, defer, generatePath, getToPathname, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, redirectDocument, resolvePath, resolveTo, stripBasename, } from "./utils";
3
+ export type { BrowserHistory, BrowserHistoryOptions, HashHistory, HashHistoryOptions, History, InitialEntry, Location, MemoryHistory, MemoryHistoryOptions, Path, To, } from "./history";
4
+ export { Action, createBrowserHistory, createHashHistory, createMemoryHistory, createPath, parsePath, } from "./history";
5
+ export * from "./router";
6
+ /** @internal */
7
+ export type { RouteManifest as UNSAFE_RouteManifest } from "./utils";
8
+ export { DeferredData as UNSAFE_DeferredData, ErrorResponseImpl as UNSAFE_ErrorResponseImpl, convertRoutesToDataRoutes as UNSAFE_convertRoutesToDataRoutes, convertRouteMatchToUiMatch as UNSAFE_convertRouteMatchToUiMatch, getResolveToMatches as UNSAFE_getResolveToMatches, } from "./utils";
9
+ export { invariant as UNSAFE_invariant, warning as UNSAFE_warning, } from "./history";
@@ -0,0 +1,512 @@
1
+ import type { History, Location, Path, To } from "./history";
2
+ import { Action as HistoryAction } from "./history";
3
+ import type { AgnosticDataRouteMatch, AgnosticDataRouteObject, AgnosticRouteObject, DataStrategyFunction, DeferredData, DetectErrorBoundaryFunction, FormEncType, HTMLFormMethod, MapRoutePropertiesFunction, RouteData, Submission, UIMatch } from "./utils";
4
+ /**
5
+ * A Router instance manages all navigation and data loading/mutations
6
+ */
7
+ export interface Router {
8
+ /**
9
+ * @internal
10
+ * PRIVATE - DO NOT USE
11
+ *
12
+ * Return the basename for the router
13
+ */
14
+ get basename(): RouterInit["basename"];
15
+ /**
16
+ * @internal
17
+ * PRIVATE - DO NOT USE
18
+ *
19
+ * Return the future config for the router
20
+ */
21
+ get future(): FutureConfig;
22
+ /**
23
+ * @internal
24
+ * PRIVATE - DO NOT USE
25
+ *
26
+ * Return the current state of the router
27
+ */
28
+ get state(): RouterState;
29
+ /**
30
+ * @internal
31
+ * PRIVATE - DO NOT USE
32
+ *
33
+ * Return the routes for this router instance
34
+ */
35
+ get routes(): AgnosticDataRouteObject[];
36
+ /**
37
+ * @internal
38
+ * PRIVATE - DO NOT USE
39
+ *
40
+ * Return the window associated with the router
41
+ */
42
+ get window(): RouterInit["window"];
43
+ /**
44
+ * @internal
45
+ * PRIVATE - DO NOT USE
46
+ *
47
+ * Initialize the router, including adding history listeners and kicking off
48
+ * initial data fetches. Returns a function to cleanup listeners and abort
49
+ * any in-progress loads
50
+ */
51
+ initialize(): Router;
52
+ /**
53
+ * @internal
54
+ * PRIVATE - DO NOT USE
55
+ *
56
+ * Subscribe to router.state updates
57
+ *
58
+ * @param fn function to call with the new state
59
+ */
60
+ subscribe(fn: RouterSubscriber): () => void;
61
+ /**
62
+ * @internal
63
+ * PRIVATE - DO NOT USE
64
+ *
65
+ * Enable scroll restoration behavior in the router
66
+ *
67
+ * @param savedScrollPositions Object that will manage positions, in case
68
+ * it's being restored from sessionStorage
69
+ * @param getScrollPosition Function to get the active Y scroll position
70
+ * @param getKey Function to get the key to use for restoration
71
+ */
72
+ enableScrollRestoration(savedScrollPositions: Record<string, number>, getScrollPosition: GetScrollPositionFunction, getKey?: GetScrollRestorationKeyFunction): () => void;
73
+ /**
74
+ * @internal
75
+ * PRIVATE - DO NOT USE
76
+ *
77
+ * Navigate forward/backward in the history stack
78
+ * @param to Delta to move in the history stack
79
+ */
80
+ navigate(to: number): Promise<void>;
81
+ /**
82
+ * Navigate to the given path
83
+ * @param to Path to navigate to
84
+ * @param opts Navigation options (method, submission, etc.)
85
+ */
86
+ navigate(to: To | null, opts?: RouterNavigateOptions): Promise<void>;
87
+ /**
88
+ * @internal
89
+ * PRIVATE - DO NOT USE
90
+ *
91
+ * Trigger a fetcher load/submission
92
+ *
93
+ * @param key Fetcher key
94
+ * @param routeId Route that owns the fetcher
95
+ * @param href href to fetch
96
+ * @param opts Fetcher options, (method, submission, etc.)
97
+ */
98
+ fetch(key: string, routeId: string, href: string | null, opts?: RouterFetchOptions): void;
99
+ /**
100
+ * @internal
101
+ * PRIVATE - DO NOT USE
102
+ *
103
+ * Trigger a revalidation of all current route loaders and fetcher loads
104
+ */
105
+ revalidate(): void;
106
+ /**
107
+ * @internal
108
+ * PRIVATE - DO NOT USE
109
+ *
110
+ * Utility function to create an href for the given location
111
+ * @param location
112
+ */
113
+ createHref(location: Location | URL): string;
114
+ /**
115
+ * @internal
116
+ * PRIVATE - DO NOT USE
117
+ *
118
+ * Utility function to URL encode a destination path according to the internal
119
+ * history implementation
120
+ * @param to
121
+ */
122
+ encodeLocation(to: To): Path;
123
+ /**
124
+ * @internal
125
+ * PRIVATE - DO NOT USE
126
+ *
127
+ * Get/create a fetcher for the given key
128
+ * @param key
129
+ */
130
+ getFetcher<TData = any>(key: string): Fetcher<TData>;
131
+ /**
132
+ * @internal
133
+ * PRIVATE - DO NOT USE
134
+ *
135
+ * Delete the fetcher for a given key
136
+ * @param key
137
+ */
138
+ deleteFetcher(key: string): void;
139
+ /**
140
+ * @internal
141
+ * PRIVATE - DO NOT USE
142
+ *
143
+ * Cleanup listeners and abort any in-progress loads
144
+ */
145
+ dispose(): void;
146
+ /**
147
+ * @internal
148
+ * PRIVATE - DO NOT USE
149
+ *
150
+ * Get a navigation blocker
151
+ * @param key The identifier for the blocker
152
+ * @param fn The blocker function implementation
153
+ */
154
+ getBlocker(key: string, fn: BlockerFunction): Blocker;
155
+ /**
156
+ * @internal
157
+ * PRIVATE - DO NOT USE
158
+ *
159
+ * Delete a navigation blocker
160
+ * @param key The identifier for the blocker
161
+ */
162
+ deleteBlocker(key: string): void;
163
+ /**
164
+ * @internal
165
+ * PRIVATE - DO NOT USE
166
+ *
167
+ * HMR needs to pass in-flight route updates to React Router
168
+ * TODO: Replace this with granular route update APIs (addRoute, updateRoute, deleteRoute)
169
+ */
170
+ _internalSetRoutes(routes: AgnosticRouteObject[]): void;
171
+ /**
172
+ * @internal
173
+ * PRIVATE - DO NOT USE
174
+ *
175
+ * Internal fetch AbortControllers accessed by unit tests
176
+ */
177
+ _internalFetchControllers: Map<string, AbortController>;
178
+ /**
179
+ * @internal
180
+ * PRIVATE - DO NOT USE
181
+ *
182
+ * Internal pending DeferredData instances accessed by unit tests
183
+ */
184
+ _internalActiveDeferreds: Map<string, DeferredData>;
185
+ }
186
+ /**
187
+ * State maintained internally by the router. During a navigation, all states
188
+ * reflect the the "old" location unless otherwise noted.
189
+ */
190
+ export interface RouterState {
191
+ /**
192
+ * The action of the most recent navigation
193
+ */
194
+ historyAction: HistoryAction;
195
+ /**
196
+ * The current location reflected by the router
197
+ */
198
+ location: Location;
199
+ /**
200
+ * The current set of route matches
201
+ */
202
+ matches: AgnosticDataRouteMatch[];
203
+ /**
204
+ * Tracks whether we've completed our initial data load
205
+ */
206
+ initialized: boolean;
207
+ /**
208
+ * Current scroll position we should start at for a new view
209
+ * - number -> scroll position to restore to
210
+ * - false -> do not restore scroll at all (used during submissions)
211
+ * - null -> don't have a saved position, scroll to hash or top of page
212
+ */
213
+ restoreScrollPosition: number | false | null;
214
+ /**
215
+ * Indicate whether this navigation should skip resetting the scroll position
216
+ * if we are unable to restore the scroll position
217
+ */
218
+ preventScrollReset: boolean;
219
+ /**
220
+ * Tracks the state of the current navigation
221
+ */
222
+ navigation: Navigation;
223
+ /**
224
+ * Tracks any in-progress revalidations
225
+ */
226
+ revalidation: RevalidationState;
227
+ /**
228
+ * Data from the loaders for the current matches
229
+ */
230
+ loaderData: RouteData;
231
+ /**
232
+ * Data from the action for the current matches
233
+ */
234
+ actionData: RouteData | null;
235
+ /**
236
+ * Errors caught from loaders for the current matches
237
+ */
238
+ errors: RouteData | null;
239
+ /**
240
+ * Map of current fetchers
241
+ */
242
+ fetchers: Map<string, Fetcher>;
243
+ /**
244
+ * Map of current blockers
245
+ */
246
+ blockers: Map<string, Blocker>;
247
+ }
248
+ /**
249
+ * Data that can be passed into hydrate a Router from SSR
250
+ */
251
+ export type HydrationState = Partial<Pick<RouterState, "loaderData" | "actionData" | "errors">>;
252
+ /**
253
+ * Future flags to toggle new feature behavior
254
+ */
255
+ export interface FutureConfig {
256
+ v7_fetcherPersist: boolean;
257
+ v7_normalizeFormMethod: boolean;
258
+ v7_partialHydration: boolean;
259
+ v7_prependBasename: boolean;
260
+ v7_relativeSplatPath: boolean;
261
+ unstable_skipActionErrorRevalidation: boolean;
262
+ }
263
+ /**
264
+ * Initialization options for createRouter
265
+ */
266
+ export interface RouterInit {
267
+ routes: AgnosticRouteObject[];
268
+ history: History;
269
+ basename?: string;
270
+ /**
271
+ * @deprecated Use `mapRouteProperties` instead
272
+ */
273
+ detectErrorBoundary?: DetectErrorBoundaryFunction;
274
+ mapRouteProperties?: MapRoutePropertiesFunction;
275
+ future?: Partial<FutureConfig>;
276
+ hydrationData?: HydrationState;
277
+ window?: Window;
278
+ unstable_dataStrategy?: DataStrategyFunction;
279
+ }
280
+ /**
281
+ * State returned from a server-side query() call
282
+ */
283
+ export interface StaticHandlerContext {
284
+ basename: Router["basename"];
285
+ location: RouterState["location"];
286
+ matches: RouterState["matches"];
287
+ loaderData: RouterState["loaderData"];
288
+ actionData: RouterState["actionData"];
289
+ errors: RouterState["errors"];
290
+ statusCode: number;
291
+ loaderHeaders: Record<string, Headers>;
292
+ actionHeaders: Record<string, Headers>;
293
+ activeDeferreds: Record<string, DeferredData> | null;
294
+ _deepestRenderedBoundaryId?: string | null;
295
+ }
296
+ /**
297
+ * A StaticHandler instance manages a singular SSR navigation/fetch event
298
+ */
299
+ export interface StaticHandler {
300
+ dataRoutes: AgnosticDataRouteObject[];
301
+ query(request: Request, opts?: {
302
+ requestContext?: unknown;
303
+ skipLoaderErrorBubbling?: boolean;
304
+ unstable_dataStrategy?: DataStrategyFunction;
305
+ }): Promise<StaticHandlerContext | Response>;
306
+ queryRoute(request: Request, opts?: {
307
+ routeId?: string;
308
+ requestContext?: unknown;
309
+ }): Promise<any>;
310
+ }
311
+ type ViewTransitionOpts = {
312
+ currentLocation: Location;
313
+ nextLocation: Location;
314
+ };
315
+ /**
316
+ * Subscriber function signature for changes to router state
317
+ */
318
+ export interface RouterSubscriber {
319
+ (state: RouterState, opts: {
320
+ deletedFetchers: string[];
321
+ unstable_viewTransitionOpts?: ViewTransitionOpts;
322
+ unstable_flushSync: boolean;
323
+ }): void;
324
+ }
325
+ /**
326
+ * Function signature for determining the key to be used in scroll restoration
327
+ * for a given location
328
+ */
329
+ export interface GetScrollRestorationKeyFunction {
330
+ (location: Location, matches: UIMatch[]): string | null;
331
+ }
332
+ /**
333
+ * Function signature for determining the current scroll position
334
+ */
335
+ export interface GetScrollPositionFunction {
336
+ (): number;
337
+ }
338
+ export type RelativeRoutingType = "route" | "path";
339
+ type BaseNavigateOrFetchOptions = {
340
+ preventScrollReset?: boolean;
341
+ relative?: RelativeRoutingType;
342
+ unstable_flushSync?: boolean;
343
+ };
344
+ type BaseNavigateOptions = BaseNavigateOrFetchOptions & {
345
+ replace?: boolean;
346
+ state?: any;
347
+ fromRouteId?: string;
348
+ unstable_viewTransition?: boolean;
349
+ };
350
+ type BaseSubmissionOptions = {
351
+ formMethod?: HTMLFormMethod;
352
+ formEncType?: FormEncType;
353
+ } & ({
354
+ formData: FormData;
355
+ body?: undefined;
356
+ } | {
357
+ formData?: undefined;
358
+ body: any;
359
+ });
360
+ /**
361
+ * Options for a navigate() call for a normal (non-submission) navigation
362
+ */
363
+ type LinkNavigateOptions = BaseNavigateOptions;
364
+ /**
365
+ * Options for a navigate() call for a submission navigation
366
+ */
367
+ type SubmissionNavigateOptions = BaseNavigateOptions & BaseSubmissionOptions;
368
+ /**
369
+ * Options to pass to navigate() for a navigation
370
+ */
371
+ export type RouterNavigateOptions = LinkNavigateOptions | SubmissionNavigateOptions;
372
+ /**
373
+ * Options for a fetch() load
374
+ */
375
+ type LoadFetchOptions = BaseNavigateOrFetchOptions;
376
+ /**
377
+ * Options for a fetch() submission
378
+ */
379
+ type SubmitFetchOptions = BaseNavigateOrFetchOptions & BaseSubmissionOptions;
380
+ /**
381
+ * Options to pass to fetch()
382
+ */
383
+ export type RouterFetchOptions = LoadFetchOptions | SubmitFetchOptions;
384
+ /**
385
+ * Potential states for state.navigation
386
+ */
387
+ export type NavigationStates = {
388
+ Idle: {
389
+ state: "idle";
390
+ location: undefined;
391
+ formMethod: undefined;
392
+ formAction: undefined;
393
+ formEncType: undefined;
394
+ formData: undefined;
395
+ json: undefined;
396
+ text: undefined;
397
+ };
398
+ Loading: {
399
+ state: "loading";
400
+ location: Location;
401
+ formMethod: Submission["formMethod"] | undefined;
402
+ formAction: Submission["formAction"] | undefined;
403
+ formEncType: Submission["formEncType"] | undefined;
404
+ formData: Submission["formData"] | undefined;
405
+ json: Submission["json"] | undefined;
406
+ text: Submission["text"] | undefined;
407
+ };
408
+ Submitting: {
409
+ state: "submitting";
410
+ location: Location;
411
+ formMethod: Submission["formMethod"];
412
+ formAction: Submission["formAction"];
413
+ formEncType: Submission["formEncType"];
414
+ formData: Submission["formData"];
415
+ json: Submission["json"];
416
+ text: Submission["text"];
417
+ };
418
+ };
419
+ export type Navigation = NavigationStates[keyof NavigationStates];
420
+ export type RevalidationState = "idle" | "loading";
421
+ /**
422
+ * Potential states for fetchers
423
+ */
424
+ type FetcherStates<TData = any> = {
425
+ Idle: {
426
+ state: "idle";
427
+ formMethod: undefined;
428
+ formAction: undefined;
429
+ formEncType: undefined;
430
+ text: undefined;
431
+ formData: undefined;
432
+ json: undefined;
433
+ data: TData | undefined;
434
+ };
435
+ Loading: {
436
+ state: "loading";
437
+ formMethod: Submission["formMethod"] | undefined;
438
+ formAction: Submission["formAction"] | undefined;
439
+ formEncType: Submission["formEncType"] | undefined;
440
+ text: Submission["text"] | undefined;
441
+ formData: Submission["formData"] | undefined;
442
+ json: Submission["json"] | undefined;
443
+ data: TData | undefined;
444
+ };
445
+ Submitting: {
446
+ state: "submitting";
447
+ formMethod: Submission["formMethod"];
448
+ formAction: Submission["formAction"];
449
+ formEncType: Submission["formEncType"];
450
+ text: Submission["text"];
451
+ formData: Submission["formData"];
452
+ json: Submission["json"];
453
+ data: TData | undefined;
454
+ };
455
+ };
456
+ export type Fetcher<TData = any> = FetcherStates<TData>[keyof FetcherStates<TData>];
457
+ interface BlockerBlocked {
458
+ state: "blocked";
459
+ reset(): void;
460
+ proceed(): void;
461
+ location: Location;
462
+ }
463
+ interface BlockerUnblocked {
464
+ state: "unblocked";
465
+ reset: undefined;
466
+ proceed: undefined;
467
+ location: undefined;
468
+ }
469
+ interface BlockerProceeding {
470
+ state: "proceeding";
471
+ reset: undefined;
472
+ proceed: undefined;
473
+ location: Location;
474
+ }
475
+ export type Blocker = BlockerUnblocked | BlockerBlocked | BlockerProceeding;
476
+ export type BlockerFunction = (args: {
477
+ currentLocation: Location;
478
+ nextLocation: Location;
479
+ historyAction: HistoryAction;
480
+ }) => boolean;
481
+ export declare const IDLE_NAVIGATION: NavigationStates["Idle"];
482
+ export declare const IDLE_FETCHER: FetcherStates["Idle"];
483
+ export declare const IDLE_BLOCKER: BlockerUnblocked;
484
+ /**
485
+ * Create a router and listen to history POP navigations
486
+ */
487
+ export declare function createRouter(init: RouterInit): Router;
488
+ export declare const UNSAFE_DEFERRED_SYMBOL: unique symbol;
489
+ /**
490
+ * Future flags to toggle new feature behavior
491
+ */
492
+ export interface StaticHandlerFutureConfig {
493
+ v7_relativeSplatPath: boolean;
494
+ v7_throwAbortReason: boolean;
495
+ }
496
+ export interface CreateStaticHandlerOptions {
497
+ basename?: string;
498
+ /**
499
+ * @deprecated Use `mapRouteProperties` instead
500
+ */
501
+ detectErrorBoundary?: DetectErrorBoundaryFunction;
502
+ mapRouteProperties?: MapRoutePropertiesFunction;
503
+ future?: Partial<StaticHandlerFutureConfig>;
504
+ }
505
+ export declare function createStaticHandler(routes: AgnosticRouteObject[], opts?: CreateStaticHandlerOptions): StaticHandler;
506
+ /**
507
+ * Given an existing StaticHandlerContext and an error thrown at render time,
508
+ * provide an updated StaticHandlerContext suitable for a second SSR render
509
+ */
510
+ export declare function getStaticContextFromError(routes: AgnosticDataRouteObject[], context: StaticHandlerContext, error: any): StaticHandlerContext;
511
+ export declare function isDeferredData(value: any): value is DeferredData;
512
+ export {};