@tanstack/router-core 0.0.1-beta.5 → 0.0.1-beta.50
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/LICENSE +21 -0
- package/build/cjs/actions.js +94 -0
- package/build/cjs/actions.js.map +1 -0
- package/build/cjs/history.js +163 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/{packages/router-core/src/index.js → index.js} +26 -11
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/interop.js +175 -0
- package/build/cjs/interop.js.map +1 -0
- package/build/cjs/{packages/router-core/src/path.js → path.js} +23 -48
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/route.js +33 -0
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -18
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/routeMatch.js +237 -0
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/router.js +821 -0
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/store.js +54 -0
- package/build/cjs/store.js.map +1 -0
- package/build/cjs/utils.js +47 -0
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +1384 -2059
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +248 -193
- package/build/types/index.d.ts +385 -317
- package/build/umd/index.development.js +1486 -2142
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +6 -4
- package/src/actions.ts +157 -0
- package/src/frameworks.ts +2 -2
- package/src/history.ts +199 -0
- package/src/index.ts +4 -7
- package/src/interop.ts +169 -0
- package/src/link.ts +87 -44
- package/src/path.ts +12 -8
- package/src/route.ts +36 -229
- package/src/routeConfig.ts +99 -102
- package/src/routeInfo.ts +28 -25
- package/src/routeMatch.ts +294 -322
- package/src/router.ts +1047 -884
- package/src/store.ts +52 -0
- package/src/utils.ts +14 -72
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js +0 -161
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js +0 -797
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -118
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
|
@@ -1,815 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* router-core
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
|
-
'use strict';
|
|
12
|
-
|
|
13
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
|
-
|
|
15
|
-
var _extends = require('../@babel/runtime/helpers/esm/extends.js');
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Actions represent the type of change to a location value.
|
|
19
|
-
*
|
|
20
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#action
|
|
21
|
-
*/
|
|
22
|
-
exports.Action = void 0;
|
|
23
|
-
|
|
24
|
-
(function (Action) {
|
|
25
|
-
/**
|
|
26
|
-
* A POP indicates a change to an arbitrary index in the history stack, such
|
|
27
|
-
* as a back or forward navigation. It does not describe the direction of the
|
|
28
|
-
* navigation, only that the current index changed.
|
|
29
|
-
*
|
|
30
|
-
* Note: This is the default action for newly created history objects.
|
|
31
|
-
*/
|
|
32
|
-
Action["Pop"] = "POP";
|
|
33
|
-
/**
|
|
34
|
-
* A PUSH indicates a new entry being added to the history stack, such as when
|
|
35
|
-
* a link is clicked and a new page loads. When this happens, all subsequent
|
|
36
|
-
* entries in the stack are lost.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
Action["Push"] = "PUSH";
|
|
40
|
-
/**
|
|
41
|
-
* A REPLACE indicates the entry at the current index in the history stack
|
|
42
|
-
* being replaced by a new one.
|
|
43
|
-
*/
|
|
44
|
-
|
|
45
|
-
Action["Replace"] = "REPLACE";
|
|
46
|
-
})(exports.Action || (exports.Action = {}));
|
|
47
|
-
|
|
48
|
-
var readOnly = process.env.NODE_ENV !== "production" ? function (obj) {
|
|
49
|
-
return Object.freeze(obj);
|
|
50
|
-
} : function (obj) {
|
|
51
|
-
return obj;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
function warning(cond, message) {
|
|
55
|
-
if (!cond) {
|
|
56
|
-
// eslint-disable-next-line no-console
|
|
57
|
-
if (typeof console !== 'undefined') console.warn(message);
|
|
58
|
-
|
|
59
|
-
try {
|
|
60
|
-
// Welcome to debugging history!
|
|
61
|
-
//
|
|
62
|
-
// This error is thrown as a convenience so you can more easily
|
|
63
|
-
// find the source for a warning that appears in the console by
|
|
64
|
-
// enabling "pause on exceptions" in your JavaScript debugger.
|
|
65
|
-
throw new Error(message); // eslint-disable-next-line no-empty
|
|
66
|
-
} catch (e) {}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
var BeforeUnloadEventType = 'beforeunload';
|
|
71
|
-
var HashChangeEventType = 'hashchange';
|
|
72
|
-
var PopStateEventType = 'popstate';
|
|
73
|
-
/**
|
|
74
|
-
* Browser history stores the location in regular URLs. This is the standard for
|
|
75
|
-
* most web apps, but it requires some configuration on the server to ensure you
|
|
76
|
-
* serve the same app at multiple URLs.
|
|
77
|
-
*
|
|
78
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createbrowserhistory
|
|
79
|
-
*/
|
|
80
|
-
|
|
81
|
-
function createBrowserHistory(options) {
|
|
82
|
-
if (options === void 0) {
|
|
83
|
-
options = {};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
var _options = options,
|
|
87
|
-
_options$window = _options.window,
|
|
88
|
-
window = _options$window === void 0 ? document.defaultView : _options$window;
|
|
89
|
-
var globalHistory = window.history;
|
|
90
|
-
|
|
91
|
-
function getIndexAndLocation() {
|
|
92
|
-
var _window$location = window.location,
|
|
93
|
-
pathname = _window$location.pathname,
|
|
94
|
-
search = _window$location.search,
|
|
95
|
-
hash = _window$location.hash;
|
|
96
|
-
var state = globalHistory.state || {};
|
|
97
|
-
return [state.idx, readOnly({
|
|
98
|
-
pathname: pathname,
|
|
99
|
-
search: search,
|
|
100
|
-
hash: hash,
|
|
101
|
-
state: state.usr || null,
|
|
102
|
-
key: state.key || 'default'
|
|
103
|
-
})];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
var blockedPopTx = null;
|
|
107
|
-
|
|
108
|
-
function handlePop() {
|
|
109
|
-
if (blockedPopTx) {
|
|
110
|
-
blockers.call(blockedPopTx);
|
|
111
|
-
blockedPopTx = null;
|
|
112
|
-
} else {
|
|
113
|
-
var nextAction = exports.Action.Pop;
|
|
114
|
-
|
|
115
|
-
var _getIndexAndLocation = getIndexAndLocation(),
|
|
116
|
-
nextIndex = _getIndexAndLocation[0],
|
|
117
|
-
nextLocation = _getIndexAndLocation[1];
|
|
118
|
-
|
|
119
|
-
if (blockers.length) {
|
|
120
|
-
if (nextIndex != null) {
|
|
121
|
-
var delta = index - nextIndex;
|
|
122
|
-
|
|
123
|
-
if (delta) {
|
|
124
|
-
// Revert the POP
|
|
125
|
-
blockedPopTx = {
|
|
126
|
-
action: nextAction,
|
|
127
|
-
location: nextLocation,
|
|
128
|
-
retry: function retry() {
|
|
129
|
-
go(delta * -1);
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
go(delta);
|
|
133
|
-
}
|
|
134
|
-
} else {
|
|
135
|
-
// Trying to POP to a location with no index. We did not create
|
|
136
|
-
// this location, so we can't effectively block the navigation.
|
|
137
|
-
process.env.NODE_ENV !== "production" ? warning(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
138
|
-
// detail and link to it here so people can understand better what
|
|
139
|
-
// is going on and how to avoid it.
|
|
140
|
-
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
applyTx(nextAction);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
window.addEventListener(PopStateEventType, handlePop);
|
|
149
|
-
var action = exports.Action.Pop;
|
|
150
|
-
|
|
151
|
-
var _getIndexAndLocation2 = getIndexAndLocation(),
|
|
152
|
-
index = _getIndexAndLocation2[0],
|
|
153
|
-
location = _getIndexAndLocation2[1];
|
|
154
|
-
|
|
155
|
-
var listeners = createEvents();
|
|
156
|
-
var blockers = createEvents();
|
|
157
|
-
|
|
158
|
-
if (index == null) {
|
|
159
|
-
index = 0;
|
|
160
|
-
globalHistory.replaceState(_extends["default"]({}, globalHistory.state, {
|
|
161
|
-
idx: index
|
|
162
|
-
}), '');
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function createHref(to) {
|
|
166
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
167
|
-
} // state defaults to `null` because `window.history.state` does
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
function getNextLocation(to, state) {
|
|
171
|
-
if (state === void 0) {
|
|
172
|
-
state = null;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return readOnly(_extends["default"]({
|
|
176
|
-
pathname: location.pathname,
|
|
177
|
-
hash: '',
|
|
178
|
-
search: ''
|
|
179
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
180
|
-
state: state,
|
|
181
|
-
key: createKey()
|
|
182
|
-
}));
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
186
|
-
return [{
|
|
187
|
-
usr: nextLocation.state,
|
|
188
|
-
key: nextLocation.key,
|
|
189
|
-
idx: index
|
|
190
|
-
}, createHref(nextLocation)];
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function allowTx(action, location, retry) {
|
|
194
|
-
return !blockers.length || (blockers.call({
|
|
195
|
-
action: action,
|
|
196
|
-
location: location,
|
|
197
|
-
retry: retry
|
|
198
|
-
}), false);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
function applyTx(nextAction) {
|
|
202
|
-
action = nextAction;
|
|
203
|
-
|
|
204
|
-
var _getIndexAndLocation3 = getIndexAndLocation();
|
|
205
|
-
|
|
206
|
-
index = _getIndexAndLocation3[0];
|
|
207
|
-
location = _getIndexAndLocation3[1];
|
|
208
|
-
listeners.call({
|
|
209
|
-
action: action,
|
|
210
|
-
location: location
|
|
211
|
-
});
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
function push(to, state) {
|
|
215
|
-
var nextAction = exports.Action.Push;
|
|
216
|
-
var nextLocation = getNextLocation(to, state);
|
|
217
|
-
|
|
218
|
-
function retry() {
|
|
219
|
-
push(to, state);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
223
|
-
var _getHistoryStateAndUr = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
224
|
-
historyState = _getHistoryStateAndUr[0],
|
|
225
|
-
url = _getHistoryStateAndUr[1]; // TODO: Support forced reloading
|
|
226
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
try {
|
|
230
|
-
globalHistory.pushState(historyState, '', url);
|
|
231
|
-
} catch (error) {
|
|
232
|
-
// They are going to lose state here, but there is no real
|
|
233
|
-
// way to warn them about it since the page will refresh...
|
|
234
|
-
window.location.assign(url);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
applyTx(nextAction);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
function replace(to, state) {
|
|
242
|
-
var nextAction = exports.Action.Replace;
|
|
243
|
-
var nextLocation = getNextLocation(to, state);
|
|
244
|
-
|
|
245
|
-
function retry() {
|
|
246
|
-
replace(to, state);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
250
|
-
var _getHistoryStateAndUr2 = getHistoryStateAndUrl(nextLocation, index),
|
|
251
|
-
historyState = _getHistoryStateAndUr2[0],
|
|
252
|
-
url = _getHistoryStateAndUr2[1]; // TODO: Support forced reloading
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
globalHistory.replaceState(historyState, '', url);
|
|
256
|
-
applyTx(nextAction);
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function go(delta) {
|
|
261
|
-
globalHistory.go(delta);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
var history = {
|
|
265
|
-
get action() {
|
|
266
|
-
return action;
|
|
267
|
-
},
|
|
268
|
-
|
|
269
|
-
get location() {
|
|
270
|
-
return location;
|
|
271
|
-
},
|
|
272
|
-
|
|
273
|
-
createHref: createHref,
|
|
274
|
-
push: push,
|
|
275
|
-
replace: replace,
|
|
276
|
-
go: go,
|
|
277
|
-
back: function back() {
|
|
278
|
-
go(-1);
|
|
279
|
-
},
|
|
280
|
-
forward: function forward() {
|
|
281
|
-
go(1);
|
|
282
|
-
},
|
|
283
|
-
listen: function listen(listener) {
|
|
284
|
-
return listeners.push(listener);
|
|
285
|
-
},
|
|
286
|
-
block: function block(blocker) {
|
|
287
|
-
var unblock = blockers.push(blocker);
|
|
288
|
-
|
|
289
|
-
if (blockers.length === 1) {
|
|
290
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
return function () {
|
|
294
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
295
|
-
// still be salvageable in the pagehide event.
|
|
296
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
297
|
-
|
|
298
|
-
if (!blockers.length) {
|
|
299
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
300
|
-
}
|
|
301
|
-
};
|
|
302
|
-
}
|
|
303
|
-
};
|
|
304
|
-
return history;
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Hash history stores the location in window.location.hash. This makes it ideal
|
|
308
|
-
* for situations where you don't want to send the location to the server for
|
|
309
|
-
* some reason, either because you do cannot configure it or the URL space is
|
|
310
|
-
* reserved for something else.
|
|
311
|
-
*
|
|
312
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createhashhistory
|
|
313
|
-
*/
|
|
314
|
-
|
|
315
|
-
function createHashHistory(options) {
|
|
316
|
-
if (options === void 0) {
|
|
317
|
-
options = {};
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
var _options2 = options,
|
|
321
|
-
_options2$window = _options2.window,
|
|
322
|
-
window = _options2$window === void 0 ? document.defaultView : _options2$window;
|
|
323
|
-
var globalHistory = window.history;
|
|
324
|
-
|
|
325
|
-
function getIndexAndLocation() {
|
|
326
|
-
var _parsePath = parsePath(window.location.hash.substr(1)),
|
|
327
|
-
_parsePath$pathname = _parsePath.pathname,
|
|
328
|
-
pathname = _parsePath$pathname === void 0 ? '/' : _parsePath$pathname,
|
|
329
|
-
_parsePath$search = _parsePath.search,
|
|
330
|
-
search = _parsePath$search === void 0 ? '' : _parsePath$search,
|
|
331
|
-
_parsePath$hash = _parsePath.hash,
|
|
332
|
-
hash = _parsePath$hash === void 0 ? '' : _parsePath$hash;
|
|
333
|
-
|
|
334
|
-
var state = globalHistory.state || {};
|
|
335
|
-
return [state.idx, readOnly({
|
|
336
|
-
pathname: pathname,
|
|
337
|
-
search: search,
|
|
338
|
-
hash: hash,
|
|
339
|
-
state: state.usr || null,
|
|
340
|
-
key: state.key || 'default'
|
|
341
|
-
})];
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
var blockedPopTx = null;
|
|
345
|
-
|
|
346
|
-
function handlePop() {
|
|
347
|
-
if (blockedPopTx) {
|
|
348
|
-
blockers.call(blockedPopTx);
|
|
349
|
-
blockedPopTx = null;
|
|
350
|
-
} else {
|
|
351
|
-
var nextAction = exports.Action.Pop;
|
|
352
|
-
|
|
353
|
-
var _getIndexAndLocation4 = getIndexAndLocation(),
|
|
354
|
-
nextIndex = _getIndexAndLocation4[0],
|
|
355
|
-
nextLocation = _getIndexAndLocation4[1];
|
|
356
|
-
|
|
357
|
-
if (blockers.length) {
|
|
358
|
-
if (nextIndex != null) {
|
|
359
|
-
var delta = index - nextIndex;
|
|
360
|
-
|
|
361
|
-
if (delta) {
|
|
362
|
-
// Revert the POP
|
|
363
|
-
blockedPopTx = {
|
|
364
|
-
action: nextAction,
|
|
365
|
-
location: nextLocation,
|
|
366
|
-
retry: function retry() {
|
|
367
|
-
go(delta * -1);
|
|
368
|
-
}
|
|
369
|
-
};
|
|
370
|
-
go(delta);
|
|
371
|
-
}
|
|
372
|
-
} else {
|
|
373
|
-
// Trying to POP to a location with no index. We did not create
|
|
374
|
-
// this location, so we can't effectively block the navigation.
|
|
375
|
-
process.env.NODE_ENV !== "production" ? warning(false, // TODO: Write up a doc that explains our blocking strategy in
|
|
376
|
-
// detail and link to it here so people can understand better
|
|
377
|
-
// what is going on and how to avoid it.
|
|
378
|
-
"You are trying to block a POP navigation to a location that was not " + "created by the history library. The block will fail silently in " + "production, but in general you should do all navigation with the " + "history library (instead of using window.history.pushState directly) " + "to avoid this situation.") : void 0;
|
|
379
|
-
}
|
|
380
|
-
} else {
|
|
381
|
-
applyTx(nextAction);
|
|
382
|
-
}
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
window.addEventListener(PopStateEventType, handlePop); // popstate does not fire on hashchange in IE 11 and old (trident) Edge
|
|
387
|
-
// https://developer.mozilla.org/de/docs/Web/API/Window/popstate_event
|
|
388
|
-
|
|
389
|
-
window.addEventListener(HashChangeEventType, function () {
|
|
390
|
-
var _getIndexAndLocation5 = getIndexAndLocation(),
|
|
391
|
-
nextLocation = _getIndexAndLocation5[1]; // Ignore extraneous hashchange events.
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (createPath(nextLocation) !== createPath(location)) {
|
|
395
|
-
handlePop();
|
|
396
|
-
}
|
|
397
|
-
});
|
|
398
|
-
var action = exports.Action.Pop;
|
|
399
|
-
|
|
400
|
-
var _getIndexAndLocation6 = getIndexAndLocation(),
|
|
401
|
-
index = _getIndexAndLocation6[0],
|
|
402
|
-
location = _getIndexAndLocation6[1];
|
|
403
|
-
|
|
404
|
-
var listeners = createEvents();
|
|
405
|
-
var blockers = createEvents();
|
|
406
|
-
|
|
407
|
-
if (index == null) {
|
|
408
|
-
index = 0;
|
|
409
|
-
globalHistory.replaceState(_extends["default"]({}, globalHistory.state, {
|
|
410
|
-
idx: index
|
|
411
|
-
}), '');
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
function getBaseHref() {
|
|
415
|
-
var base = document.querySelector('base');
|
|
416
|
-
var href = '';
|
|
417
|
-
|
|
418
|
-
if (base && base.getAttribute('href')) {
|
|
419
|
-
var url = window.location.href;
|
|
420
|
-
var hashIndex = url.indexOf('#');
|
|
421
|
-
href = hashIndex === -1 ? url : url.slice(0, hashIndex);
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return href;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
function createHref(to) {
|
|
428
|
-
return getBaseHref() + '#' + (typeof to === 'string' ? to : createPath(to));
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function getNextLocation(to, state) {
|
|
432
|
-
if (state === void 0) {
|
|
433
|
-
state = null;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return readOnly(_extends["default"]({
|
|
437
|
-
pathname: location.pathname,
|
|
438
|
-
hash: '',
|
|
439
|
-
search: ''
|
|
440
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
441
|
-
state: state,
|
|
442
|
-
key: createKey()
|
|
443
|
-
}));
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
function getHistoryStateAndUrl(nextLocation, index) {
|
|
447
|
-
return [{
|
|
448
|
-
usr: nextLocation.state,
|
|
449
|
-
key: nextLocation.key,
|
|
450
|
-
idx: index
|
|
451
|
-
}, createHref(nextLocation)];
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
function allowTx(action, location, retry) {
|
|
455
|
-
return !blockers.length || (blockers.call({
|
|
456
|
-
action: action,
|
|
457
|
-
location: location,
|
|
458
|
-
retry: retry
|
|
459
|
-
}), false);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
function applyTx(nextAction) {
|
|
463
|
-
action = nextAction;
|
|
464
|
-
|
|
465
|
-
var _getIndexAndLocation7 = getIndexAndLocation();
|
|
466
|
-
|
|
467
|
-
index = _getIndexAndLocation7[0];
|
|
468
|
-
location = _getIndexAndLocation7[1];
|
|
469
|
-
listeners.call({
|
|
470
|
-
action: action,
|
|
471
|
-
location: location
|
|
472
|
-
});
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
function push(to, state) {
|
|
476
|
-
var nextAction = exports.Action.Push;
|
|
477
|
-
var nextLocation = getNextLocation(to, state);
|
|
478
|
-
|
|
479
|
-
function retry() {
|
|
480
|
-
push(to, state);
|
|
481
|
-
}
|
|
482
|
-
|
|
483
|
-
process.env.NODE_ENV !== "production" ? warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.push(" + JSON.stringify(to) + ")") : void 0;
|
|
484
|
-
|
|
485
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
486
|
-
var _getHistoryStateAndUr3 = getHistoryStateAndUrl(nextLocation, index + 1),
|
|
487
|
-
historyState = _getHistoryStateAndUr3[0],
|
|
488
|
-
url = _getHistoryStateAndUr3[1]; // TODO: Support forced reloading
|
|
489
|
-
// try...catch because iOS limits us to 100 pushState calls :/
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
try {
|
|
493
|
-
globalHistory.pushState(historyState, '', url);
|
|
494
|
-
} catch (error) {
|
|
495
|
-
// They are going to lose state here, but there is no real
|
|
496
|
-
// way to warn them about it since the page will refresh...
|
|
497
|
-
window.location.assign(url);
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
applyTx(nextAction);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
|
|
504
|
-
function replace(to, state) {
|
|
505
|
-
var nextAction = exports.Action.Replace;
|
|
506
|
-
var nextLocation = getNextLocation(to, state);
|
|
507
|
-
|
|
508
|
-
function retry() {
|
|
509
|
-
replace(to, state);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
process.env.NODE_ENV !== "production" ? warning(nextLocation.pathname.charAt(0) === '/', "Relative pathnames are not supported in hash history.replace(" + JSON.stringify(to) + ")") : void 0;
|
|
513
|
-
|
|
514
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
515
|
-
var _getHistoryStateAndUr4 = getHistoryStateAndUrl(nextLocation, index),
|
|
516
|
-
historyState = _getHistoryStateAndUr4[0],
|
|
517
|
-
url = _getHistoryStateAndUr4[1]; // TODO: Support forced reloading
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
globalHistory.replaceState(historyState, '', url);
|
|
521
|
-
applyTx(nextAction);
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
|
|
525
|
-
function go(delta) {
|
|
526
|
-
globalHistory.go(delta);
|
|
527
|
-
}
|
|
528
|
-
|
|
529
|
-
var history = {
|
|
530
|
-
get action() {
|
|
531
|
-
return action;
|
|
532
|
-
},
|
|
533
|
-
|
|
534
|
-
get location() {
|
|
535
|
-
return location;
|
|
536
|
-
},
|
|
537
|
-
|
|
538
|
-
createHref: createHref,
|
|
539
|
-
push: push,
|
|
540
|
-
replace: replace,
|
|
541
|
-
go: go,
|
|
542
|
-
back: function back() {
|
|
543
|
-
go(-1);
|
|
544
|
-
},
|
|
545
|
-
forward: function forward() {
|
|
546
|
-
go(1);
|
|
547
|
-
},
|
|
548
|
-
listen: function listen(listener) {
|
|
549
|
-
return listeners.push(listener);
|
|
550
|
-
},
|
|
551
|
-
block: function block(blocker) {
|
|
552
|
-
var unblock = blockers.push(blocker);
|
|
553
|
-
|
|
554
|
-
if (blockers.length === 1) {
|
|
555
|
-
window.addEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
return function () {
|
|
559
|
-
unblock(); // Remove the beforeunload listener so the document may
|
|
560
|
-
// still be salvageable in the pagehide event.
|
|
561
|
-
// See https://html.spec.whatwg.org/#unloading-documents
|
|
562
|
-
|
|
563
|
-
if (!blockers.length) {
|
|
564
|
-
window.removeEventListener(BeforeUnloadEventType, promptBeforeUnload);
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
return history;
|
|
570
|
-
}
|
|
571
|
-
/**
|
|
572
|
-
* Memory history stores the current location in memory. It is designed for use
|
|
573
|
-
* in stateful non-browser environments like tests and React Native.
|
|
574
|
-
*
|
|
575
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#creatememoryhistory
|
|
576
|
-
*/
|
|
577
|
-
|
|
578
|
-
function createMemoryHistory(options) {
|
|
579
|
-
if (options === void 0) {
|
|
580
|
-
options = {};
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
var _options3 = options,
|
|
584
|
-
_options3$initialEntr = _options3.initialEntries,
|
|
585
|
-
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
|
|
586
|
-
initialIndex = _options3.initialIndex;
|
|
587
|
-
var entries = initialEntries.map(function (entry) {
|
|
588
|
-
var location = readOnly(_extends["default"]({
|
|
589
|
-
pathname: '/',
|
|
590
|
-
search: '',
|
|
591
|
-
hash: '',
|
|
592
|
-
state: null,
|
|
593
|
-
key: createKey()
|
|
594
|
-
}, typeof entry === 'string' ? parsePath(entry) : entry));
|
|
595
|
-
process.env.NODE_ENV !== "production" ? warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in createMemoryHistory({ initialEntries }) (invalid entry: " + JSON.stringify(entry) + ")") : void 0;
|
|
596
|
-
return location;
|
|
597
|
-
});
|
|
598
|
-
var index = clamp(initialIndex == null ? entries.length - 1 : initialIndex, 0, entries.length - 1);
|
|
599
|
-
var action = exports.Action.Pop;
|
|
600
|
-
var location = entries[index];
|
|
601
|
-
var listeners = createEvents();
|
|
602
|
-
var blockers = createEvents();
|
|
603
|
-
|
|
604
|
-
function createHref(to) {
|
|
605
|
-
return typeof to === 'string' ? to : createPath(to);
|
|
606
|
-
}
|
|
607
|
-
|
|
608
|
-
function getNextLocation(to, state) {
|
|
609
|
-
if (state === void 0) {
|
|
610
|
-
state = null;
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
return readOnly(_extends["default"]({
|
|
614
|
-
pathname: location.pathname,
|
|
615
|
-
search: '',
|
|
616
|
-
hash: ''
|
|
617
|
-
}, typeof to === 'string' ? parsePath(to) : to, {
|
|
618
|
-
state: state,
|
|
619
|
-
key: createKey()
|
|
620
|
-
}));
|
|
621
|
-
}
|
|
622
|
-
|
|
623
|
-
function allowTx(action, location, retry) {
|
|
624
|
-
return !blockers.length || (blockers.call({
|
|
625
|
-
action: action,
|
|
626
|
-
location: location,
|
|
627
|
-
retry: retry
|
|
628
|
-
}), false);
|
|
629
|
-
}
|
|
630
|
-
|
|
631
|
-
function applyTx(nextAction, nextLocation) {
|
|
632
|
-
action = nextAction;
|
|
633
|
-
location = nextLocation;
|
|
634
|
-
listeners.call({
|
|
635
|
-
action: action,
|
|
636
|
-
location: location
|
|
637
|
-
});
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
function push(to, state) {
|
|
641
|
-
var nextAction = exports.Action.Push;
|
|
642
|
-
var nextLocation = getNextLocation(to, state);
|
|
643
|
-
|
|
644
|
-
function retry() {
|
|
645
|
-
push(to, state);
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
process.env.NODE_ENV !== "production" ? warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.push(" + JSON.stringify(to) + ")") : void 0;
|
|
649
|
-
|
|
650
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
651
|
-
index += 1;
|
|
652
|
-
entries.splice(index, entries.length, nextLocation);
|
|
653
|
-
applyTx(nextAction, nextLocation);
|
|
654
|
-
}
|
|
655
|
-
}
|
|
656
|
-
|
|
657
|
-
function replace(to, state) {
|
|
658
|
-
var nextAction = exports.Action.Replace;
|
|
659
|
-
var nextLocation = getNextLocation(to, state);
|
|
660
|
-
|
|
661
|
-
function retry() {
|
|
662
|
-
replace(to, state);
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
process.env.NODE_ENV !== "production" ? warning(location.pathname.charAt(0) === '/', "Relative pathnames are not supported in memory history.replace(" + JSON.stringify(to) + ")") : void 0;
|
|
666
|
-
|
|
667
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
668
|
-
entries[index] = nextLocation;
|
|
669
|
-
applyTx(nextAction, nextLocation);
|
|
670
|
-
}
|
|
671
|
-
}
|
|
672
|
-
|
|
673
|
-
function go(delta) {
|
|
674
|
-
var nextIndex = clamp(index + delta, 0, entries.length - 1);
|
|
675
|
-
var nextAction = exports.Action.Pop;
|
|
676
|
-
var nextLocation = entries[nextIndex];
|
|
677
|
-
|
|
678
|
-
function retry() {
|
|
679
|
-
go(delta);
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
if (allowTx(nextAction, nextLocation, retry)) {
|
|
683
|
-
index = nextIndex;
|
|
684
|
-
applyTx(nextAction, nextLocation);
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
|
|
688
|
-
var history = {
|
|
689
|
-
get index() {
|
|
690
|
-
return index;
|
|
691
|
-
},
|
|
692
|
-
|
|
693
|
-
get action() {
|
|
694
|
-
return action;
|
|
695
|
-
},
|
|
696
|
-
|
|
697
|
-
get location() {
|
|
698
|
-
return location;
|
|
699
|
-
},
|
|
700
|
-
|
|
701
|
-
createHref: createHref,
|
|
702
|
-
push: push,
|
|
703
|
-
replace: replace,
|
|
704
|
-
go: go,
|
|
705
|
-
back: function back() {
|
|
706
|
-
go(-1);
|
|
707
|
-
},
|
|
708
|
-
forward: function forward() {
|
|
709
|
-
go(1);
|
|
710
|
-
},
|
|
711
|
-
listen: function listen(listener) {
|
|
712
|
-
return listeners.push(listener);
|
|
713
|
-
},
|
|
714
|
-
block: function block(blocker) {
|
|
715
|
-
return blockers.push(blocker);
|
|
716
|
-
}
|
|
717
|
-
};
|
|
718
|
-
return history;
|
|
719
|
-
} ////////////////////////////////////////////////////////////////////////////////
|
|
720
|
-
// UTILS
|
|
721
|
-
////////////////////////////////////////////////////////////////////////////////
|
|
722
|
-
|
|
723
|
-
function clamp(n, lowerBound, upperBound) {
|
|
724
|
-
return Math.min(Math.max(n, lowerBound), upperBound);
|
|
725
|
-
}
|
|
726
|
-
|
|
727
|
-
function promptBeforeUnload(event) {
|
|
728
|
-
// Cancel the event.
|
|
729
|
-
event.preventDefault(); // Chrome (and legacy IE) requires returnValue to be set.
|
|
730
|
-
|
|
731
|
-
event.returnValue = '';
|
|
732
|
-
}
|
|
733
|
-
|
|
734
|
-
function createEvents() {
|
|
735
|
-
var handlers = [];
|
|
736
|
-
return {
|
|
737
|
-
get length() {
|
|
738
|
-
return handlers.length;
|
|
739
|
-
},
|
|
740
|
-
|
|
741
|
-
push: function push(fn) {
|
|
742
|
-
handlers.push(fn);
|
|
743
|
-
return function () {
|
|
744
|
-
handlers = handlers.filter(function (handler) {
|
|
745
|
-
return handler !== fn;
|
|
746
|
-
});
|
|
747
|
-
};
|
|
748
|
-
},
|
|
749
|
-
call: function call(arg) {
|
|
750
|
-
handlers.forEach(function (fn) {
|
|
751
|
-
return fn && fn(arg);
|
|
752
|
-
});
|
|
753
|
-
}
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
function createKey() {
|
|
758
|
-
return Math.random().toString(36).substr(2, 8);
|
|
759
|
-
}
|
|
760
|
-
/**
|
|
761
|
-
* Creates a string URL path from the given pathname, search, and hash components.
|
|
762
|
-
*
|
|
763
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#createpath
|
|
764
|
-
*/
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
function createPath(_ref) {
|
|
768
|
-
var _ref$pathname = _ref.pathname,
|
|
769
|
-
pathname = _ref$pathname === void 0 ? '/' : _ref$pathname,
|
|
770
|
-
_ref$search = _ref.search,
|
|
771
|
-
search = _ref$search === void 0 ? '' : _ref$search,
|
|
772
|
-
_ref$hash = _ref.hash,
|
|
773
|
-
hash = _ref$hash === void 0 ? '' : _ref$hash;
|
|
774
|
-
if (search && search !== '?') pathname += search.charAt(0) === '?' ? search : '?' + search;
|
|
775
|
-
if (hash && hash !== '#') pathname += hash.charAt(0) === '#' ? hash : '#' + hash;
|
|
776
|
-
return pathname;
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
* Parses a string URL path into its separate pathname, search, and hash components.
|
|
780
|
-
*
|
|
781
|
-
* @see https://github.com/remix-run/history/tree/main/docs/api-reference.md#parsepath
|
|
782
|
-
*/
|
|
783
|
-
|
|
784
|
-
function parsePath(path) {
|
|
785
|
-
var parsedPath = {};
|
|
786
|
-
|
|
787
|
-
if (path) {
|
|
788
|
-
var hashIndex = path.indexOf('#');
|
|
789
|
-
|
|
790
|
-
if (hashIndex >= 0) {
|
|
791
|
-
parsedPath.hash = path.substr(hashIndex);
|
|
792
|
-
path = path.substr(0, hashIndex);
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
var searchIndex = path.indexOf('?');
|
|
796
|
-
|
|
797
|
-
if (searchIndex >= 0) {
|
|
798
|
-
parsedPath.search = path.substr(searchIndex);
|
|
799
|
-
path = path.substr(0, searchIndex);
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
if (path) {
|
|
803
|
-
parsedPath.pathname = path;
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
return parsedPath;
|
|
808
|
-
}
|
|
809
|
-
|
|
810
|
-
exports.createBrowserHistory = createBrowserHistory;
|
|
811
|
-
exports.createHashHistory = createHashHistory;
|
|
812
|
-
exports.createMemoryHistory = createMemoryHistory;
|
|
813
|
-
exports.createPath = createPath;
|
|
814
|
-
exports.parsePath = parsePath;
|
|
815
|
-
//# sourceMappingURL=index.js.map
|