@remix-run/router 0.2.0-pre.0 → 0.2.0-pre.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/CHANGELOG.md +6 -0
- package/LICENSE.md +22 -0
- package/dist/__tests__/TestSequences/EncodedReservedCharacters.d.ts +2 -0
- package/dist/__tests__/TestSequences/GoBack.d.ts +2 -0
- package/dist/__tests__/TestSequences/GoForward.d.ts +2 -0
- package/{__tests__/TestSequences/InitialLocationDefaultKey.ts → dist/__tests__/TestSequences/InitialLocationDefaultKey.d.ts} +1 -4
- package/dist/__tests__/TestSequences/InitialLocationHasKey.d.ts +2 -0
- package/dist/__tests__/TestSequences/Listen.d.ts +2 -0
- package/dist/__tests__/TestSequences/ListenPopOnly.d.ts +2 -0
- package/dist/__tests__/TestSequences/PushMissingPathname.d.ts +2 -0
- package/dist/__tests__/TestSequences/PushNewLocation.d.ts +2 -0
- package/dist/__tests__/TestSequences/PushRelativePathname.d.ts +2 -0
- package/dist/__tests__/TestSequences/PushRelativePathnameWarning.d.ts +2 -0
- package/dist/__tests__/TestSequences/PushSamePath.d.ts +2 -0
- package/dist/__tests__/TestSequences/PushState.d.ts +2 -0
- package/dist/__tests__/TestSequences/ReplaceNewLocation.d.ts +2 -0
- package/dist/__tests__/TestSequences/ReplaceSamePath.d.ts +2 -0
- package/dist/__tests__/TestSequences/ReplaceState.d.ts +2 -0
- package/dist/__tests__/browser-test.d.ts +4 -0
- package/dist/__tests__/create-path-test.d.ts +1 -0
- package/dist/__tests__/hash-base-test.d.ts +4 -0
- package/dist/__tests__/hash-test.d.ts +4 -0
- package/dist/__tests__/memory-test.d.ts +1 -0
- package/dist/__tests__/router-test.d.ts +2 -0
- package/dist/__tests__/setup.d.ts +1 -0
- package/dist/history.d.ts +226 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +2418 -0
- package/dist/index.js.map +1 -0
- package/dist/main.js +19 -0
- package/dist/router.d.ts +299 -0
- package/dist/router.development.js +2294 -0
- package/dist/router.development.js.map +1 -0
- package/dist/router.production.min.js +12 -0
- package/dist/router.production.min.js.map +1 -0
- package/dist/umd/router.development.js +2487 -0
- package/dist/umd/router.development.js.map +1 -0
- package/dist/umd/router.production.min.js +12 -0
- package/dist/umd/router.production.min.js.map +1 -0
- package/dist/utils.d.ts +244 -0
- package/package.json +21 -15
- package/.eslintrc +0 -12
- package/__tests__/.eslintrc +0 -8
- package/__tests__/TestSequences/EncodedReservedCharacters.ts +0 -27
- package/__tests__/TestSequences/GoBack.ts +0 -43
- package/__tests__/TestSequences/GoForward.ts +0 -70
- package/__tests__/TestSequences/InitialLocationHasKey.ts +0 -5
- package/__tests__/TestSequences/Listen.ts +0 -10
- package/__tests__/TestSequences/ListenPopOnly.ts +0 -14
- package/__tests__/TestSequences/PushMissingPathname.ts +0 -23
- package/__tests__/TestSequences/PushNewLocation.ts +0 -17
- package/__tests__/TestSequences/PushRelativePathname.ts +0 -23
- package/__tests__/TestSequences/PushRelativePathnameWarning.ts +0 -28
- package/__tests__/TestSequences/PushSamePath.ts +0 -33
- package/__tests__/TestSequences/PushState.ts +0 -16
- package/__tests__/TestSequences/ReplaceNewLocation.ts +0 -26
- package/__tests__/TestSequences/ReplaceSamePath.ts +0 -23
- package/__tests__/TestSequences/ReplaceState.ts +0 -16
- package/__tests__/browser-test.ts +0 -145
- package/__tests__/create-path-test.ts +0 -61
- package/__tests__/custom-environment.js +0 -19
- package/__tests__/hash-base-test.ts +0 -52
- package/__tests__/hash-test.ts +0 -149
- package/__tests__/memory-test.ts +0 -174
- package/__tests__/resolveTo-test.tsx +0 -26
- package/__tests__/router-test.ts +0 -6300
- package/__tests__/setup.ts +0 -15
- package/history.ts +0 -622
- package/index.ts +0 -96
- package/jest-transformer.js +0 -10
- package/jest.config.js +0 -10
- package/node-main.js +0 -7
- package/router.ts +0 -2033
- package/tsconfig.json +0 -19
- package/utils.ts +0 -822
package/CHANGELOG.md
CHANGED
package/LICENSE.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) React Training 2015-2019
|
|
4
|
+
Copyright (c) Remix Software 2020-2022
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Actions represent the type of change to a location value.
|
|
3
|
+
*/
|
|
4
|
+
export declare enum Action {
|
|
5
|
+
/**
|
|
6
|
+
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
7
|
+
* as a back or forward navigation. It does not describe the direction of the
|
|
8
|
+
* navigation, only that the current index changed.
|
|
9
|
+
*
|
|
10
|
+
* Note: This is the default action for newly created history objects.
|
|
11
|
+
*/
|
|
12
|
+
Pop = "POP",
|
|
13
|
+
/**
|
|
14
|
+
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
15
|
+
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
16
|
+
* entries in the stack are lost.
|
|
17
|
+
*/
|
|
18
|
+
Push = "PUSH",
|
|
19
|
+
/**
|
|
20
|
+
* A REPLACE indicates the entry at the current index in the history stack
|
|
21
|
+
* being replaced by a new one.
|
|
22
|
+
*/
|
|
23
|
+
Replace = "REPLACE"
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The pathname, search, and hash values of a URL.
|
|
27
|
+
*/
|
|
28
|
+
export interface Path {
|
|
29
|
+
/**
|
|
30
|
+
* A URL pathname, beginning with a /.
|
|
31
|
+
*/
|
|
32
|
+
pathname: string;
|
|
33
|
+
/**
|
|
34
|
+
* A URL search string, beginning with a ?.
|
|
35
|
+
*/
|
|
36
|
+
search: string;
|
|
37
|
+
/**
|
|
38
|
+
* A URL fragment identifier, beginning with a #.
|
|
39
|
+
*/
|
|
40
|
+
hash: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* An entry in a history stack. A location contains information about the
|
|
44
|
+
* URL path, as well as possibly some arbitrary state and a key.
|
|
45
|
+
*/
|
|
46
|
+
export interface Location extends Path {
|
|
47
|
+
/**
|
|
48
|
+
* A value of arbitrary data associated with this location.
|
|
49
|
+
*/
|
|
50
|
+
state: any;
|
|
51
|
+
/**
|
|
52
|
+
* A unique string associated with this location. May be used to safely store
|
|
53
|
+
* and retrieve data in some other storage API, like `localStorage`.
|
|
54
|
+
*
|
|
55
|
+
* Note: This value is always "default" on the initial location.
|
|
56
|
+
*/
|
|
57
|
+
key: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A change to the current location.
|
|
61
|
+
*/
|
|
62
|
+
export interface Update {
|
|
63
|
+
/**
|
|
64
|
+
* The action that triggered the change.
|
|
65
|
+
*/
|
|
66
|
+
action: Action;
|
|
67
|
+
/**
|
|
68
|
+
* The new location.
|
|
69
|
+
*/
|
|
70
|
+
location: Location;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* A function that receives notifications about location changes.
|
|
74
|
+
*/
|
|
75
|
+
export interface Listener {
|
|
76
|
+
(update: Update): void;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Describes a location that is the destination of some navigation, either via
|
|
80
|
+
* `history.push` or `history.replace`. May be either a URL or the pieces of a
|
|
81
|
+
* URL path.
|
|
82
|
+
*/
|
|
83
|
+
export declare type To = string | Partial<Path>;
|
|
84
|
+
/**
|
|
85
|
+
* A history is an interface to the navigation stack. The history serves as the
|
|
86
|
+
* source of truth for the current location, as well as provides a set of
|
|
87
|
+
* methods that may be used to change it.
|
|
88
|
+
*
|
|
89
|
+
* It is similar to the DOM's `window.history` object, but with a smaller, more
|
|
90
|
+
* focused API.
|
|
91
|
+
*/
|
|
92
|
+
export interface History {
|
|
93
|
+
/**
|
|
94
|
+
* The last action that modified the current location. This will always be
|
|
95
|
+
* Action.Pop when a history instance is first created. This value is mutable.
|
|
96
|
+
*/
|
|
97
|
+
readonly action: Action;
|
|
98
|
+
/**
|
|
99
|
+
* The current location. This value is mutable.
|
|
100
|
+
*/
|
|
101
|
+
readonly location: Location;
|
|
102
|
+
/**
|
|
103
|
+
* Returns a valid href for the given `to` value that may be used as
|
|
104
|
+
* the value of an <a href> attribute.
|
|
105
|
+
*
|
|
106
|
+
* @param to - The destination URL
|
|
107
|
+
*/
|
|
108
|
+
createHref(to: To): string;
|
|
109
|
+
/**
|
|
110
|
+
* Pushes a new location onto the history stack, increasing its length by one.
|
|
111
|
+
* If there were any entries in the stack after the current one, they are
|
|
112
|
+
* lost.
|
|
113
|
+
*
|
|
114
|
+
* @param to - The new URL
|
|
115
|
+
* @param state - Data to associate with the new location
|
|
116
|
+
*/
|
|
117
|
+
push(to: To, state?: any): void;
|
|
118
|
+
/**
|
|
119
|
+
* Replaces the current location in the history stack with a new one. The
|
|
120
|
+
* location that was replaced will no longer be available.
|
|
121
|
+
*
|
|
122
|
+
* @param to - The new URL
|
|
123
|
+
* @param state - Data to associate with the new location
|
|
124
|
+
*/
|
|
125
|
+
replace(to: To, state?: any): void;
|
|
126
|
+
/**
|
|
127
|
+
* Navigates `n` entries backward/forward in the history stack relative to the
|
|
128
|
+
* current index. For example, a "back" navigation would use go(-1).
|
|
129
|
+
*
|
|
130
|
+
* @param delta - The delta in the stack index
|
|
131
|
+
*/
|
|
132
|
+
go(delta: number): void;
|
|
133
|
+
/**
|
|
134
|
+
* Sets up a listener that will be called whenever the current location
|
|
135
|
+
* changes.
|
|
136
|
+
*
|
|
137
|
+
* @param listener - A function that will be called when the location changes
|
|
138
|
+
* @returns unlisten - A function that may be used to stop listening
|
|
139
|
+
*/
|
|
140
|
+
listen(listener: Listener): () => void;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* A user-supplied object that describes a location. Used when providing
|
|
144
|
+
* entries to `createMemoryHistory` via its `initialEntries` option.
|
|
145
|
+
*/
|
|
146
|
+
export declare type InitialEntry = string | Partial<Location>;
|
|
147
|
+
export declare type MemoryHistoryOptions = {
|
|
148
|
+
initialEntries?: InitialEntry[];
|
|
149
|
+
initialIndex?: number;
|
|
150
|
+
v5Compat?: boolean;
|
|
151
|
+
};
|
|
152
|
+
/**
|
|
153
|
+
* A memory history stores locations in memory. This is useful in stateful
|
|
154
|
+
* environments where there is no web browser, such as node tests or React
|
|
155
|
+
* Native.
|
|
156
|
+
*/
|
|
157
|
+
export interface MemoryHistory extends History {
|
|
158
|
+
/**
|
|
159
|
+
* The current index in the history stack.
|
|
160
|
+
*/
|
|
161
|
+
readonly index: number;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Memory history stores the current location in memory. It is designed for use
|
|
165
|
+
* in stateful non-browser environments like tests and React Native.
|
|
166
|
+
*/
|
|
167
|
+
export declare function createMemoryHistory(options?: MemoryHistoryOptions): MemoryHistory;
|
|
168
|
+
/**
|
|
169
|
+
* A browser history stores the current location in regular URLs in a web
|
|
170
|
+
* browser environment. This is the standard for most web apps and provides the
|
|
171
|
+
* cleanest URLs the browser's address bar.
|
|
172
|
+
*
|
|
173
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#browserhistory
|
|
174
|
+
*/
|
|
175
|
+
export interface BrowserHistory extends UrlHistory {
|
|
176
|
+
}
|
|
177
|
+
export declare type BrowserHistoryOptions = UrlHistoryOptions;
|
|
178
|
+
/**
|
|
179
|
+
* Browser history stores the location in regular URLs. This is the standard for
|
|
180
|
+
* most web apps, but it requires some configuration on the server to ensure you
|
|
181
|
+
* serve the same app at multiple URLs.
|
|
182
|
+
*
|
|
183
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
184
|
+
*/
|
|
185
|
+
export declare function createBrowserHistory(options?: BrowserHistoryOptions): BrowserHistory;
|
|
186
|
+
/**
|
|
187
|
+
* A hash history stores the current location in the fragment identifier portion
|
|
188
|
+
* of the URL in a web browser environment.
|
|
189
|
+
*
|
|
190
|
+
* This is ideal for apps that do not control the server for some reason
|
|
191
|
+
* (because the fragment identifier is never sent to the server), including some
|
|
192
|
+
* shared hosting environments that do not provide fine-grained controls over
|
|
193
|
+
* which pages are served at which URLs.
|
|
194
|
+
*
|
|
195
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#hashhistory
|
|
196
|
+
*/
|
|
197
|
+
export interface HashHistory extends UrlHistory {
|
|
198
|
+
}
|
|
199
|
+
export declare type HashHistoryOptions = UrlHistoryOptions;
|
|
200
|
+
/**
|
|
201
|
+
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
202
|
+
* for situations where you don't want to send the location to the server for
|
|
203
|
+
* some reason, either because you do cannot configure it or the URL space is
|
|
204
|
+
* reserved for something else.
|
|
205
|
+
*
|
|
206
|
+
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
207
|
+
*/
|
|
208
|
+
export declare function createHashHistory(options?: HashHistoryOptions): HashHistory;
|
|
209
|
+
/**
|
|
210
|
+
* Creates a Location object with a unique key from the given Path
|
|
211
|
+
*/
|
|
212
|
+
export declare function createLocation(current: string | Location, to: To, state?: any, key?: string): Location;
|
|
213
|
+
/**
|
|
214
|
+
* Creates a string URL path from the given pathname, search, and hash components.
|
|
215
|
+
*/
|
|
216
|
+
export declare function createPath({ pathname, search, hash, }: Partial<Path>): string;
|
|
217
|
+
/**
|
|
218
|
+
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
219
|
+
*/
|
|
220
|
+
export declare function parsePath(path: string): Partial<Path>;
|
|
221
|
+
export interface UrlHistory extends History {
|
|
222
|
+
}
|
|
223
|
+
export declare type UrlHistoryOptions = {
|
|
224
|
+
window?: Window;
|
|
225
|
+
v5Compat?: boolean;
|
|
226
|
+
};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BrowserHistoryOptions, HashHistoryOptions, MemoryHistoryOptions } from "./history";
|
|
2
|
+
import type { Router, RouterInit } from "./router";
|
|
3
|
+
declare function createMemoryRouter({ initialEntries, initialIndex, ...routerInit }: MemoryHistoryOptions & Omit<RouterInit, "history">): Router;
|
|
4
|
+
declare function createBrowserRouter({ window, ...routerInit }: BrowserHistoryOptions & Omit<RouterInit, "history">): Router;
|
|
5
|
+
declare function createHashRouter({ window, ...routerInit }: HashHistoryOptions & Omit<RouterInit, "history">): Router;
|
|
6
|
+
export * from "./router";
|
|
7
|
+
export type { ActionFunction, DataRouteObject, FormEncType, FormMethod, JsonFunction, LoaderFunction, ParamParseKey, Params, PathMatch, PathPattern, RedirectFunction, RouteMatch, RouteObject, ShouldRevalidateFunction, Submission, } from "./utils";
|
|
8
|
+
export { generatePath, getToPathname, invariant, isRouteErrorResponse, joinPaths, json, matchPath, matchRoutes, normalizePathname, redirect, resolvePath, resolveTo, stripBasename, warning, } from "./utils";
|
|
9
|
+
export type { BrowserHistory, HashHistory, History, InitialEntry, Location, MemoryHistory, Path, To, } from "./history";
|
|
10
|
+
export { Action, createBrowserHistory, createPath, createHashHistory, createMemoryHistory, parsePath, } from "./history";
|
|
11
|
+
export { createBrowserRouter, createHashRouter, createMemoryRouter };
|