@tanstack/react-router 0.0.1-beta.195 → 0.0.1-beta.197
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.
|
@@ -134,36 +134,8 @@
|
|
|
134
134
|
return true;
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
var prefix = 'Invariant failed';
|
|
138
|
-
function invariant(condition, message) {
|
|
139
|
-
if (condition) {
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
var provided = typeof message === 'function' ? message() : message;
|
|
143
|
-
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
144
|
-
throw new Error(value);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
function warning(condition, message) {
|
|
148
|
-
{
|
|
149
|
-
if (condition) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
var text = "Warning: " + message;
|
|
154
|
-
|
|
155
|
-
if (typeof console !== 'undefined') {
|
|
156
|
-
console.warn(text);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
try {
|
|
160
|
-
throw Error(text);
|
|
161
|
-
} catch (x) {}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
137
|
/**
|
|
166
|
-
* @tanstack/
|
|
138
|
+
* @tanstack/history/src/index.ts
|
|
167
139
|
*
|
|
168
140
|
* Copyright (c) TanStack
|
|
169
141
|
*
|
|
@@ -172,7 +144,6 @@
|
|
|
172
144
|
*
|
|
173
145
|
* @license MIT
|
|
174
146
|
*/
|
|
175
|
-
|
|
176
147
|
// While the public API was clearly inspired by the "history" npm package,
|
|
177
148
|
// This implementation attempts to be more lightweight by
|
|
178
149
|
// making assumptions about the way TanStack Router works
|
|
@@ -192,13 +163,16 @@
|
|
|
192
163
|
};
|
|
193
164
|
function createHistory(opts) {
|
|
194
165
|
let location = opts.getLocation();
|
|
195
|
-
let unsub = () => {};
|
|
196
166
|
let subscribers = new Set();
|
|
197
167
|
let blockers = [];
|
|
198
168
|
let queue = [];
|
|
199
|
-
const
|
|
169
|
+
const onUpdate = () => {
|
|
170
|
+
location = opts.getLocation();
|
|
171
|
+
subscribers.forEach(subscriber => subscriber());
|
|
172
|
+
};
|
|
173
|
+
const tryUnblock = () => {
|
|
200
174
|
if (blockers.length) {
|
|
201
|
-
blockers[0]?.(
|
|
175
|
+
blockers[0]?.(tryUnblock, () => {
|
|
202
176
|
blockers = [];
|
|
203
177
|
stopBlocking();
|
|
204
178
|
});
|
|
@@ -207,42 +181,30 @@
|
|
|
207
181
|
while (queue.length) {
|
|
208
182
|
queue.shift()?.();
|
|
209
183
|
}
|
|
210
|
-
|
|
211
|
-
onUpdate();
|
|
212
|
-
}
|
|
184
|
+
onUpdate();
|
|
213
185
|
};
|
|
214
186
|
const queueTask = task => {
|
|
215
187
|
queue.push(task);
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
const onUpdate = () => {
|
|
219
|
-
location = opts.getLocation();
|
|
220
|
-
subscribers.forEach(subscriber => subscriber());
|
|
188
|
+
tryUnblock();
|
|
221
189
|
};
|
|
222
190
|
return {
|
|
223
191
|
get location() {
|
|
224
192
|
return location;
|
|
225
193
|
},
|
|
226
194
|
subscribe: cb => {
|
|
227
|
-
if (subscribers.size === 0) {
|
|
228
|
-
unsub = typeof opts.subscriber === 'function' ? opts.subscriber(onUpdate) : () => {};
|
|
229
|
-
}
|
|
230
195
|
subscribers.add(cb);
|
|
231
196
|
return () => {
|
|
232
197
|
subscribers.delete(cb);
|
|
233
|
-
if (subscribers.size === 0) {
|
|
234
|
-
unsub();
|
|
235
|
-
}
|
|
236
198
|
};
|
|
237
199
|
},
|
|
238
200
|
push: (path, state) => {
|
|
239
|
-
assignKey(state);
|
|
201
|
+
state = assignKey(state);
|
|
240
202
|
queueTask(() => {
|
|
241
203
|
opts.pushState(path, state, onUpdate);
|
|
242
204
|
});
|
|
243
205
|
},
|
|
244
206
|
replace: (path, state) => {
|
|
245
|
-
assignKey(state);
|
|
207
|
+
state = assignKey(state);
|
|
246
208
|
queueTask(() => {
|
|
247
209
|
opts.replaceState(path, state, onUpdate);
|
|
248
210
|
});
|
|
@@ -277,17 +239,17 @@
|
|
|
277
239
|
}
|
|
278
240
|
};
|
|
279
241
|
},
|
|
280
|
-
flush: () => opts.flush?.()
|
|
242
|
+
flush: () => opts.flush?.(),
|
|
243
|
+
destroy: () => opts.destroy?.(),
|
|
244
|
+
update: onUpdate
|
|
281
245
|
};
|
|
282
246
|
}
|
|
283
247
|
function assignKey(state) {
|
|
248
|
+
if (!state) {
|
|
249
|
+
state = {};
|
|
250
|
+
}
|
|
284
251
|
state.key = createRandomKey();
|
|
285
|
-
|
|
286
|
-
// state.__actualLocation.state = {
|
|
287
|
-
// ...state.__actualLocation.state,
|
|
288
|
-
// key,
|
|
289
|
-
// }
|
|
290
|
-
// }
|
|
252
|
+
return state;
|
|
291
253
|
}
|
|
292
254
|
|
|
293
255
|
/**
|
|
@@ -363,44 +325,43 @@
|
|
|
363
325
|
scheduled = Promise.resolve().then(() => flush());
|
|
364
326
|
}
|
|
365
327
|
};
|
|
366
|
-
|
|
328
|
+
const history = createHistory({
|
|
367
329
|
getLocation,
|
|
368
|
-
subscriber: onUpdate => {
|
|
369
|
-
window.addEventListener(pushStateEvent, () => {
|
|
370
|
-
currentLocation = parseLocation(getHref(), window.history.state);
|
|
371
|
-
onUpdate();
|
|
372
|
-
});
|
|
373
|
-
window.addEventListener(popStateEvent, () => {
|
|
374
|
-
currentLocation = parseLocation(getHref(), window.history.state);
|
|
375
|
-
onUpdate();
|
|
376
|
-
});
|
|
377
|
-
var pushState = window.history.pushState;
|
|
378
|
-
window.history.pushState = function () {
|
|
379
|
-
let res = pushState.apply(history, arguments);
|
|
380
|
-
if (tracking) onUpdate();
|
|
381
|
-
return res;
|
|
382
|
-
};
|
|
383
|
-
var replaceState = window.history.replaceState;
|
|
384
|
-
window.history.replaceState = function () {
|
|
385
|
-
let res = replaceState.apply(history, arguments);
|
|
386
|
-
if (tracking) onUpdate();
|
|
387
|
-
return res;
|
|
388
|
-
};
|
|
389
|
-
return () => {
|
|
390
|
-
window.history.pushState = pushState;
|
|
391
|
-
window.history.replaceState = replaceState;
|
|
392
|
-
window.removeEventListener(pushStateEvent, onUpdate);
|
|
393
|
-
window.removeEventListener(popStateEvent, onUpdate);
|
|
394
|
-
};
|
|
395
|
-
},
|
|
396
330
|
pushState: (path, state, onUpdate) => queueHistoryAction('push', path, state, onUpdate),
|
|
397
331
|
replaceState: (path, state, onUpdate) => queueHistoryAction('replace', path, state, onUpdate),
|
|
398
332
|
back: () => window.history.back(),
|
|
399
333
|
forward: () => window.history.forward(),
|
|
400
334
|
go: n => window.history.go(n),
|
|
401
335
|
createHref: path => createHref(path),
|
|
402
|
-
flush
|
|
336
|
+
flush,
|
|
337
|
+
destroy: () => {
|
|
338
|
+
window.history.pushState = pushState;
|
|
339
|
+
window.history.replaceState = replaceState;
|
|
340
|
+
window.removeEventListener(pushStateEvent, history.update);
|
|
341
|
+
window.removeEventListener(popStateEvent, history.update);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
window.addEventListener(pushStateEvent, () => {
|
|
345
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
346
|
+
history.update;
|
|
403
347
|
});
|
|
348
|
+
window.addEventListener(popStateEvent, () => {
|
|
349
|
+
currentLocation = parseLocation(getHref(), window.history.state);
|
|
350
|
+
history.update;
|
|
351
|
+
});
|
|
352
|
+
var pushState = window.history.pushState;
|
|
353
|
+
window.history.pushState = function () {
|
|
354
|
+
let res = pushState.apply(window.history, arguments);
|
|
355
|
+
if (tracking) history.update();
|
|
356
|
+
return res;
|
|
357
|
+
};
|
|
358
|
+
var replaceState = window.history.replaceState;
|
|
359
|
+
window.history.replaceState = function () {
|
|
360
|
+
let res = replaceState.apply(window.history, arguments);
|
|
361
|
+
if (tracking) history.update();
|
|
362
|
+
return res;
|
|
363
|
+
};
|
|
364
|
+
return history;
|
|
404
365
|
}
|
|
405
366
|
function createHashHistory() {
|
|
406
367
|
return createBrowserHistory({
|
|
@@ -419,7 +380,6 @@
|
|
|
419
380
|
const getLocation = () => parseLocation(entries[index], currentState);
|
|
420
381
|
return createHistory({
|
|
421
382
|
getLocation,
|
|
422
|
-
subscriber: false,
|
|
423
383
|
pushState: (path, state) => {
|
|
424
384
|
currentState = state;
|
|
425
385
|
entries.push(path);
|
|
@@ -456,6 +416,45 @@
|
|
|
456
416
|
return (Math.random() + 1).toString(36).substring(7);
|
|
457
417
|
}
|
|
458
418
|
|
|
419
|
+
var prefix = 'Invariant failed';
|
|
420
|
+
function invariant(condition, message) {
|
|
421
|
+
if (condition) {
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
var provided = typeof message === 'function' ? message() : message;
|
|
425
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
426
|
+
throw new Error(value);
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function warning(condition, message) {
|
|
430
|
+
{
|
|
431
|
+
if (condition) {
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
var text = "Warning: " + message;
|
|
436
|
+
|
|
437
|
+
if (typeof console !== 'undefined') {
|
|
438
|
+
console.warn(text);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
try {
|
|
442
|
+
throw Error(text);
|
|
443
|
+
} catch (x) {}
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* @tanstack/router-core/src/index.ts
|
|
449
|
+
*
|
|
450
|
+
* Copyright (c) TanStack
|
|
451
|
+
*
|
|
452
|
+
* This source code is licensed under the MIT license found in the
|
|
453
|
+
* LICENSE.md file in the root directory of this source tree.
|
|
454
|
+
*
|
|
455
|
+
* @license MIT
|
|
456
|
+
*/
|
|
457
|
+
|
|
459
458
|
// export type Expand<T> = T
|
|
460
459
|
|
|
461
460
|
// type Compute<T> = { [K in keyof T]: T[K] } | never
|