@tanstack/react-router 0.0.1-beta.4 → 0.0.1-beta.41

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.
@@ -34,63 +34,427 @@
34
34
 
35
35
  var React__namespace = /*#__PURE__*/_interopNamespace(React);
36
36
 
37
- function _extends$2() {
38
- _extends$2 = Object.assign ? Object.assign.bind() : function (target) {
37
+ function _extends$1() {
38
+ _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
39
39
  for (var i = 1; i < arguments.length; i++) {
40
40
  var source = arguments[i];
41
-
42
41
  for (var key in source) {
43
42
  if (Object.prototype.hasOwnProperty.call(source, key)) {
44
43
  target[key] = source[key];
45
44
  }
46
45
  }
47
46
  }
48
-
49
47
  return target;
50
48
  };
51
- return _extends$2.apply(this, arguments);
49
+ return _extends$1.apply(this, arguments);
52
50
  }
53
51
 
54
- function _objectWithoutPropertiesLoose(source, excluded) {
55
- if (source == null) return {};
56
- var target = {};
57
- var sourceKeys = Object.keys(source);
58
- var key, i;
59
-
60
- for (i = 0; i < sourceKeys.length; i++) {
61
- key = sourceKeys[i];
62
- if (excluded.indexOf(key) >= 0) continue;
63
- target[key] = source[key];
52
+ // src/core.ts
53
+ var CurrentReaction = void 0;
54
+ var CurrentGets = null;
55
+ var CurrentGetsIndex = 0;
56
+ var EffectQueue = null;
57
+ var CacheClean = 0;
58
+ var CacheCheck = 1;
59
+ var CacheDirty = 2;
60
+ var Root;
61
+ var Reactive = class {
62
+ value;
63
+ fn;
64
+ observers = null;
65
+ sources = null;
66
+ state;
67
+ effect;
68
+ cleanups = null;
69
+ alwaysUpdate = false;
70
+ constructor(fnOrValue, type) {
71
+ if (type != 0 /* Signal */) {
72
+ this.fn = fnOrValue;
73
+ this.value = void 0;
74
+ this.state = CacheDirty;
75
+ if (Root)
76
+ Root.push(this);
77
+ else
78
+ console.error("Memos and effects must be wrapped in a createRoot");
79
+ this.effect = type == 2 /* Effect */;
80
+ if (this.effect)
81
+ this.update();
82
+ } else {
83
+ this.fn = void 0;
84
+ this.value = fnOrValue;
85
+ this.state = CacheClean;
86
+ this.effect = false;
87
+ }
88
+ }
89
+ get() {
90
+ if (CurrentReaction) {
91
+ if (!CurrentGets && CurrentReaction.sources && CurrentReaction.sources[CurrentGetsIndex] == this) {
92
+ CurrentGetsIndex++;
93
+ } else {
94
+ if (!CurrentGets)
95
+ CurrentGets = [this];
96
+ else
97
+ CurrentGets.push(this);
98
+ }
99
+ }
100
+ if (this.fn)
101
+ this.updateIfNecessary();
102
+ return this.value;
103
+ }
104
+ set(value) {
105
+ const notInBatch = !EffectQueue;
106
+ const newValue = typeof value === "function" ? value(this.value) : value;
107
+ if ((this.value !== newValue || this.alwaysUpdate) && this.observers) {
108
+ for (let i = 0; i < this.observers.length; i++) {
109
+ this.observers[i].stale(CacheDirty);
110
+ }
111
+ }
112
+ this.value = newValue;
113
+ if (notInBatch)
114
+ stabilize();
115
+ return newValue;
116
+ }
117
+ stale(state) {
118
+ if (this.state < state) {
119
+ if (this.state === CacheClean && this.effect) {
120
+ if (EffectQueue)
121
+ EffectQueue.push(this);
122
+ else
123
+ EffectQueue = [this];
124
+ }
125
+ this.state = state;
126
+ if (this.observers) {
127
+ for (let i = 0; i < this.observers.length; i++) {
128
+ this.observers[i].stale(CacheCheck);
129
+ }
130
+ }
131
+ }
132
+ }
133
+ update() {
134
+ const oldValue = this.value;
135
+ const prevReaction = CurrentReaction;
136
+ const prevGets = CurrentGets;
137
+ const prevIndex = CurrentGetsIndex;
138
+ CurrentReaction = this;
139
+ CurrentGets = null;
140
+ CurrentGetsIndex = 0;
141
+ try {
142
+ if (this.cleanups) {
143
+ this.cleanups.forEach((c) => c());
144
+ this.cleanups = null;
145
+ }
146
+ this.value = this.fn();
147
+ if (CurrentGets) {
148
+ this.removeParentObservers(CurrentGetsIndex);
149
+ if (this.sources && CurrentGetsIndex > 0) {
150
+ this.sources.length = CurrentGetsIndex + CurrentGets.length;
151
+ for (let i = 0; i < CurrentGets.length; i++) {
152
+ this.sources[CurrentGetsIndex + i] = CurrentGets[i];
153
+ }
154
+ } else {
155
+ this.sources = CurrentGets;
156
+ }
157
+ for (let i = CurrentGetsIndex; i < this.sources.length; i++) {
158
+ const source = this.sources[i];
159
+ if (!source.observers) {
160
+ source.observers = [this];
161
+ } else {
162
+ source.observers.push(this);
163
+ }
164
+ }
165
+ } else if (this.sources && CurrentGetsIndex < this.sources.length) {
166
+ this.removeParentObservers(CurrentGetsIndex);
167
+ this.sources.length = CurrentGetsIndex;
168
+ }
169
+ } finally {
170
+ CurrentGets = prevGets;
171
+ CurrentReaction = prevReaction;
172
+ CurrentGetsIndex = prevIndex;
173
+ }
174
+ if ((oldValue !== this.value || this.alwaysUpdate) && this.observers) {
175
+ for (let i = 0; i < this.observers.length; i++) {
176
+ this.observers[i].state = CacheDirty;
177
+ }
178
+ }
179
+ this.state = CacheClean;
64
180
  }
181
+ updateIfNecessary() {
182
+ if (this.state === CacheCheck) {
183
+ for (const source of this.sources) {
184
+ source.updateIfNecessary();
185
+ if (this.state === CacheDirty) {
186
+ break;
187
+ }
188
+ }
189
+ }
190
+ if (this.state === CacheDirty) {
191
+ this.update();
192
+ }
193
+ this.state = CacheClean;
194
+ }
195
+ removeParentObservers(index) {
196
+ if (!this.sources)
197
+ return;
198
+ for (let i = index; i < this.sources.length; i++) {
199
+ const source = this.sources[i];
200
+ const swap = source.observers.findIndex((v) => v === this);
201
+ source.observers[swap] = source.observers[source.observers.length - 1];
202
+ source.observers.pop();
203
+ }
204
+ }
205
+ destroy() {
206
+ if (this.cleanups) {
207
+ this.cleanups.forEach((c) => c());
208
+ this.cleanups = null;
209
+ }
210
+ this.removeParentObservers(0);
211
+ }
212
+ };
213
+ function onCleanup(fn) {
214
+ if (CurrentReaction) {
215
+ if (!CurrentReaction.cleanups)
216
+ CurrentReaction.cleanups = [fn];
217
+ else
218
+ CurrentReaction.cleanups.push(fn);
219
+ } else {
220
+ console.error("onCleanup must be called from within a memo or effect");
221
+ }
222
+ }
223
+ function stabilize() {
224
+ if (!EffectQueue)
225
+ return;
226
+ for (let i = 0; i < EffectQueue.length; i++) {
227
+ EffectQueue[i].get();
228
+ }
229
+ EffectQueue = null;
230
+ }
231
+ function createSignal(value, options) {
232
+ const signal = new Reactive(value, 0 /* Signal */);
233
+ if (options?.equals !== void 0)
234
+ signal.alwaysUpdate = true;
235
+ return [signal.get.bind(signal), signal.set.bind(signal)];
236
+ }
237
+ function createMemo(fn) {
238
+ const memo = new Reactive(fn, 1 /* Memo */);
239
+ return memo.get.bind(memo);
240
+ }
241
+ function createEffect(fn) {
242
+ const effect = new Reactive(fn, 2 /* Effect */);
243
+ return effect.get.bind(effect);
244
+ }
245
+ function createRoot(fn) {
246
+ let root = [];
247
+ Root = root;
248
+ fn();
249
+ Root = null;
250
+ return () => {
251
+ if (!root)
252
+ return;
253
+ root.forEach((r) => r.destroy());
254
+ root = null;
255
+ };
256
+ }
257
+ function batch(fn) {
258
+ EffectQueue = [];
259
+ let out = fn();
260
+ stabilize();
261
+ return out;
262
+ }
263
+ function untrack(fn) {
264
+ const listener = CurrentReaction;
265
+ CurrentReaction = void 0;
266
+ try {
267
+ return fn();
268
+ } finally {
269
+ CurrentReaction = listener;
270
+ }
271
+ }
65
272
 
66
- return target;
273
+ // src/store.ts
274
+ var $RAW = Symbol("store-raw");
275
+ var $TRACK = Symbol("track");
276
+ var $PROXY = Symbol("store-proxy");
277
+ var $NODE = Symbol("store-node");
278
+ function wrap(value) {
279
+ let p = value[$PROXY];
280
+ if (!p) {
281
+ Object.defineProperty(value, $PROXY, {
282
+ value: p = new Proxy(value, proxyTraps)
283
+ });
284
+ if (!Array.isArray(value)) {
285
+ const keys = Object.keys(value);
286
+ const desc = Object.getOwnPropertyDescriptors(value);
287
+ for (let i = 0, l = keys.length; i < l; i++) {
288
+ const prop = keys[i];
289
+ if (desc[prop].get) {
290
+ const get = desc[prop].get.bind(p);
291
+ Object.defineProperty(value, prop, {
292
+ enumerable: desc[prop].enumerable,
293
+ get
294
+ });
295
+ }
296
+ }
297
+ }
298
+ }
299
+ return p;
300
+ }
301
+ function isWrappable(obj) {
302
+ let proto;
303
+ return obj != null && typeof obj === "object" && (obj[$PROXY] || !(proto = Object.getPrototypeOf(obj)) || proto === Object.prototype || Array.isArray(obj));
304
+ }
305
+ function unwrap(item, set = /* @__PURE__ */ new Set()) {
306
+ let result, unwrapped, v, prop;
307
+ if (result = item != null && item[$RAW])
308
+ return result;
309
+ if (!isWrappable(item) || set.has(item))
310
+ return item;
311
+ if (Array.isArray(item)) {
312
+ if (Object.isFrozen(item))
313
+ item = item.slice(0);
314
+ else
315
+ set.add(item);
316
+ for (let i = 0, l = item.length; i < l; i++) {
317
+ v = item[i];
318
+ if ((unwrapped = unwrap(v, set)) !== v)
319
+ item[i] = unwrapped;
320
+ }
321
+ } else {
322
+ if (Object.isFrozen(item))
323
+ item = Object.assign({}, item);
324
+ else
325
+ set.add(item);
326
+ const keys = Object.keys(item);
327
+ const desc = Object.getOwnPropertyDescriptors(item);
328
+ for (let i = 0, l = keys.length; i < l; i++) {
329
+ prop = keys[i];
330
+ if (desc[prop].get)
331
+ continue;
332
+ v = item[prop];
333
+ if ((unwrapped = unwrap(v, set)) !== v)
334
+ item[prop] = unwrapped;
335
+ }
336
+ }
337
+ return item;
338
+ }
339
+ function getDataNodes(target) {
340
+ let nodes = target[$NODE];
341
+ if (!nodes)
342
+ Object.defineProperty(target, $NODE, { value: nodes = {} });
343
+ return nodes;
344
+ }
345
+ function getDataNode(nodes, property, value) {
346
+ return nodes[property] || (nodes[property] = createDataNode(value));
347
+ }
348
+ function proxyDescriptor(target, property) {
349
+ const desc = Reflect.getOwnPropertyDescriptor(target, property);
350
+ if (!desc || desc.get || !desc.configurable || property === $PROXY || property === $NODE)
351
+ return desc;
352
+ delete desc.value;
353
+ delete desc.writable;
354
+ desc.get = () => target[$PROXY][property];
355
+ return desc;
356
+ }
357
+ function trackSelf(target) {
358
+ if (CurrentReaction) {
359
+ const nodes = getDataNodes(target);
360
+ (nodes._ || (nodes._ = createDataNode())).get();
361
+ }
362
+ }
363
+ function ownKeys(target) {
364
+ trackSelf(target);
365
+ return Reflect.ownKeys(target);
366
+ }
367
+ function createDataNode(value) {
368
+ const s = new Reactive(value, 0);
369
+ s.alwaysUpdate = true;
370
+ return s;
371
+ }
372
+ var Writing = false;
373
+ var proxyTraps = {
374
+ get(target, property, receiver) {
375
+ if (property === $RAW)
376
+ return target;
377
+ if (property === $PROXY)
378
+ return receiver;
379
+ if (property === $TRACK) {
380
+ trackSelf(target);
381
+ return receiver;
382
+ }
383
+ const nodes = getDataNodes(target);
384
+ const tracked = nodes.hasOwnProperty(property);
385
+ let value = tracked ? nodes[property].get() : target[property];
386
+ if (property === $NODE || property === "__proto__")
387
+ return value;
388
+ if (!tracked) {
389
+ const desc = Object.getOwnPropertyDescriptor(target, property);
390
+ if (CurrentReaction && (typeof value !== "function" || target.hasOwnProperty(property)) && !(desc && desc.get))
391
+ value = getDataNode(nodes, property, value).get();
392
+ }
393
+ return isWrappable(value) ? wrap(value) : value;
394
+ },
395
+ has(target, property) {
396
+ if (property === $RAW || property === $PROXY || property === $TRACK || property === $NODE || property === "__proto__")
397
+ return true;
398
+ this.get(target, property, target);
399
+ return property in target;
400
+ },
401
+ set(target, property, value) {
402
+ Writing && setProperty(target, property, unwrap(value));
403
+ return true;
404
+ },
405
+ deleteProperty(target, property) {
406
+ Writing && setProperty(target, property, void 0, true);
407
+ return true;
408
+ },
409
+ ownKeys,
410
+ getOwnPropertyDescriptor: proxyDescriptor
411
+ };
412
+ function setProperty(state, property, value, deleting = false) {
413
+ if (!deleting && state[property] === value)
414
+ return;
415
+ const prev = state[property];
416
+ const len = state.length;
417
+ if (deleting)
418
+ delete state[property];
419
+ else
420
+ state[property] = value;
421
+ const nodes = getDataNodes(state);
422
+ let node;
423
+ if (node = getDataNode(nodes, property, prev))
424
+ node.set(() => value);
425
+ if (Array.isArray(state) && state.length !== len)
426
+ (node = getDataNode(nodes, "length", len)) && node.set(state.length);
427
+ (node = nodes._) && node.set();
428
+ }
429
+ function createStore(store) {
430
+ const unwrappedStore = unwrap(store);
431
+ const wrappedStore = wrap(unwrappedStore);
432
+ const setStore = (fn) => {
433
+ batch(() => {
434
+ try {
435
+ Writing = true;
436
+ fn(wrappedStore);
437
+ } finally {
438
+ Writing = false;
439
+ }
440
+ });
441
+ };
442
+ return [wrappedStore, setStore];
67
443
  }
68
444
 
69
- /**
70
- * router-core
71
- *
72
- * Copyright (c) TanStack
73
- *
74
- * This source code is licensed under the MIT license found in the
75
- * LICENSE.md file in the root directory of this source tree.
76
- *
77
- * @license MIT
78
- */
79
- function _extends$1() {
80
- _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
445
+ function _extends() {
446
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
81
447
  for (var i = 1; i < arguments.length; i++) {
82
448
  var source = arguments[i];
83
-
84
449
  for (var key in source) {
85
450
  if (Object.prototype.hasOwnProperty.call(source, key)) {
86
451
  target[key] = source[key];
87
452
  }
88
453
  }
89
454
  }
90
-
91
455
  return target;
92
456
  };
93
- return _extends$1.apply(this, arguments);
457
+ return _extends.apply(this, arguments);
94
458
  }
95
459
 
96
460
  /**
@@ -234,7 +598,7 @@
234
598
 
235
599
  if (index == null) {
236
600
  index = 0;
237
- globalHistory.replaceState(_extends$1({}, globalHistory.state, {
601
+ globalHistory.replaceState(_extends({}, globalHistory.state, {
238
602
  idx: index
239
603
  }), '');
240
604
  }
@@ -249,7 +613,7 @@
249
613
  state = null;
250
614
  }
251
615
 
252
- return readOnly(_extends$1({
616
+ return readOnly(_extends({
253
617
  pathname: location.pathname,
254
618
  hash: '',
255
619
  search: ''
@@ -483,7 +847,7 @@
483
847
 
484
848
  if (index == null) {
485
849
  index = 0;
486
- globalHistory.replaceState(_extends$1({}, globalHistory.state, {
850
+ globalHistory.replaceState(_extends({}, globalHistory.state, {
487
851
  idx: index
488
852
  }), '');
489
853
  }
@@ -510,7 +874,7 @@
510
874
  state = null;
511
875
  }
512
876
 
513
- return readOnly(_extends$1({
877
+ return readOnly(_extends({
514
878
  pathname: location.pathname,
515
879
  hash: '',
516
880
  search: ''
@@ -662,7 +1026,7 @@
662
1026
  initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
663
1027
  initialIndex = _options3.initialIndex;
664
1028
  var entries = initialEntries.map(function (entry) {
665
- var location = readOnly(_extends$1({
1029
+ var location = readOnly(_extends({
666
1030
  pathname: '/',
667
1031
  search: '',
668
1032
  hash: '',
@@ -687,7 +1051,7 @@
687
1051
  state = null;
688
1052
  }
689
1053
 
690
- return readOnly(_extends$1({
1054
+ return readOnly(_extends({
691
1055
  pathname: location.pathname,
692
1056
  search: '',
693
1057
  hash: ''
@@ -883,6 +1247,7 @@
883
1247
 
884
1248
  return parsedPath;
885
1249
  }
1250
+
886
1251
  var prefix = 'Invariant failed';
887
1252
  function invariant(condition, message) {
888
1253
  if (condition) {
@@ -893,77 +1258,16 @@
893
1258
  throw new Error(value);
894
1259
  }
895
1260
 
896
- // type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
897
- // k: infer I,
898
- // ) => any
899
- // ? I
900
- // : never
901
-
902
1261
  /**
903
- * This function returns `a` if `b` is deeply equal.
904
- * If not, it will replace any deeply equal children of `b` with those of `a`.
905
- * This can be used for structural sharing between JSON values for example.
1262
+ * router-core
1263
+ *
1264
+ * Copyright (c) TanStack
1265
+ *
1266
+ * This source code is licensed under the MIT license found in the
1267
+ * LICENSE.md file in the root directory of this source tree.
1268
+ *
1269
+ * @license MIT
906
1270
  */
907
- function replaceEqualDeep(prev, next) {
908
- if (prev === next) {
909
- return prev;
910
- }
911
-
912
- const array = Array.isArray(prev) && Array.isArray(next);
913
-
914
- if (array || isPlainObject(prev) && isPlainObject(next)) {
915
- const aSize = array ? prev.length : Object.keys(prev).length;
916
- const bItems = array ? next : Object.keys(next);
917
- const bSize = bItems.length;
918
- const copy = array ? [] : {};
919
- let equalItems = 0;
920
-
921
- for (let i = 0; i < bSize; i++) {
922
- const key = array ? i : bItems[i];
923
- copy[key] = replaceEqualDeep(prev[key], next[key]);
924
-
925
- if (copy[key] === prev[key]) {
926
- equalItems++;
927
- }
928
- }
929
-
930
- return aSize === bSize && equalItems === aSize ? prev : copy;
931
- }
932
-
933
- return next;
934
- } // Copied from: https://github.com/jonschlinkert/is-plain-object
935
-
936
- function isPlainObject(o) {
937
- if (!hasObjectPrototype(o)) {
938
- return false;
939
- } // If has modified constructor
940
-
941
-
942
- const ctor = o.constructor;
943
-
944
- if (typeof ctor === 'undefined') {
945
- return true;
946
- } // If has modified prototype
947
-
948
-
949
- const prot = ctor.prototype;
950
-
951
- if (!hasObjectPrototype(prot)) {
952
- return false;
953
- } // If constructor does not have an Object-specific method
954
-
955
-
956
- if (!prot.hasOwnProperty('isPrototypeOf')) {
957
- return false;
958
- } // Most likely a plain Object
959
-
960
-
961
- return true;
962
- }
963
-
964
- function hasObjectPrototype(o) {
965
- return Object.prototype.toString.call(o) === '[object Object]';
966
- }
967
1271
 
968
1272
  function last(arr) {
969
1273
  return arr[arr.length - 1];
@@ -971,26 +1275,27 @@
971
1275
  function warning(cond, message) {
972
1276
  if (cond) {
973
1277
  if (typeof console !== 'undefined') console.warn(message);
974
-
975
1278
  try {
976
1279
  throw new Error(message);
977
- } catch (_unused) {}
1280
+ } catch {}
978
1281
  }
979
-
980
1282
  return true;
981
1283
  }
982
-
983
1284
  function isFunction(d) {
984
1285
  return typeof d === 'function';
985
1286
  }
986
-
987
1287
  function functionalUpdate(updater, previous) {
988
1288
  if (isFunction(updater)) {
989
1289
  return updater(previous);
990
1290
  }
991
-
992
1291
  return updater;
993
1292
  }
1293
+ function pick(parent, keys) {
1294
+ return keys.reduce((obj, key) => {
1295
+ obj[key] = parent[key];
1296
+ return obj;
1297
+ }, {});
1298
+ }
994
1299
 
995
1300
  function joinPaths(paths) {
996
1301
  return cleanPath(paths.filter(Boolean).join('/'));
@@ -1009,8 +1314,8 @@
1009
1314
  return trimPathRight(trimPathLeft(path));
1010
1315
  }
1011
1316
  function resolvePath(basepath, base, to) {
1012
- base = base.replace(new RegExp("^" + basepath), '/');
1013
- to = to.replace(new RegExp("^" + basepath), '/');
1317
+ base = base.replace(new RegExp(`^${basepath}`), '/');
1318
+ to = to.replace(new RegExp(`^${basepath}`), '/');
1014
1319
  let baseSegments = parsePathname(base);
1015
1320
  const toSegments = parsePathname(to);
1016
1321
  toSegments.forEach((toSegment, index) => {
@@ -1024,12 +1329,10 @@
1024
1329
  } else ;
1025
1330
  } else if (toSegment.value === '..') {
1026
1331
  var _last;
1027
-
1028
1332
  // Extra trailing slash? pop it off
1029
1333
  if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
1030
1334
  baseSegments.pop();
1031
1335
  }
1032
-
1033
1336
  baseSegments.pop();
1034
1337
  } else if (toSegment.value === '.') {
1035
1338
  return;
@@ -1044,10 +1347,8 @@
1044
1347
  if (!pathname) {
1045
1348
  return [];
1046
1349
  }
1047
-
1048
1350
  pathname = cleanPath(pathname);
1049
1351
  const segments = [];
1050
-
1051
1352
  if (pathname.slice(0, 1) === '/') {
1052
1353
  pathname = pathname.substring(1);
1053
1354
  segments.push({
@@ -1055,12 +1356,11 @@
1055
1356
  value: '/'
1056
1357
  });
1057
1358
  }
1058
-
1059
1359
  if (!pathname) {
1060
1360
  return segments;
1061
- } // Remove empty segments and '.' segments
1062
-
1361
+ }
1063
1362
 
1363
+ // Remove empty segments and '.' segments
1064
1364
  const split = pathname.split('/').filter(Boolean);
1065
1365
  segments.push(...split.map(part => {
1066
1366
  if (part.startsWith('*')) {
@@ -1069,20 +1369,17 @@
1069
1369
  value: part
1070
1370
  };
1071
1371
  }
1072
-
1073
- if (part.charAt(0) === ':') {
1372
+ if (part.charAt(0) === '$') {
1074
1373
  return {
1075
1374
  type: 'param',
1076
1375
  value: part
1077
1376
  };
1078
1377
  }
1079
-
1080
1378
  return {
1081
1379
  type: 'pathname',
1082
1380
  value: part
1083
1381
  };
1084
1382
  }));
1085
-
1086
1383
  if (pathname.slice(-1) === '/') {
1087
1384
  pathname = pathname.substring(1);
1088
1385
  segments.push({
@@ -1090,7 +1387,6 @@
1090
1387
  value: '/'
1091
1388
  });
1092
1389
  }
1093
-
1094
1390
  return segments;
1095
1391
  }
1096
1392
  function interpolatePath(path, params, leaveWildcard) {
@@ -1099,57 +1395,48 @@
1099
1395
  if (segment.value === '*' && !leaveWildcard) {
1100
1396
  return '';
1101
1397
  }
1102
-
1103
1398
  if (segment.type === 'param') {
1104
- var _segment$value$substr;
1105
-
1106
- return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
1399
+ return params[segment.value.substring(1)] ?? '';
1107
1400
  }
1108
-
1109
1401
  return segment.value;
1110
1402
  }));
1111
1403
  }
1112
- function matchPathname(currentPathname, matchLocation) {
1113
- const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1404
+ function matchPathname(basepath, currentPathname, matchLocation) {
1405
+ const pathParams = matchByPath(basepath, currentPathname, matchLocation);
1406
+ // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
1114
1407
 
1115
1408
  if (matchLocation.to && !pathParams) {
1116
1409
  return;
1117
- } // if (matchLocation.search && !searchMatched) {
1118
- // return
1119
- // }
1120
-
1121
-
1122
- return pathParams != null ? pathParams : {};
1410
+ }
1411
+ return pathParams ?? {};
1123
1412
  }
1124
- function matchByPath(from, matchLocation) {
1125
- var _matchLocation$to;
1126
-
1413
+ function matchByPath(basepath, from, matchLocation) {
1414
+ if (!from.startsWith(basepath)) {
1415
+ return undefined;
1416
+ }
1417
+ from = basepath != '/' ? from.substring(basepath.length) : from;
1127
1418
  const baseSegments = parsePathname(from);
1128
- const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
1419
+ const to = `${matchLocation.to ?? '*'}`;
1420
+ const routeSegments = parsePathname(to);
1129
1421
  const params = {};
1130
-
1131
1422
  let isMatch = (() => {
1132
1423
  for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
1133
1424
  const baseSegment = baseSegments[i];
1134
1425
  const routeSegment = routeSegments[i];
1135
1426
  const isLastRouteSegment = i === routeSegments.length - 1;
1136
1427
  const isLastBaseSegment = i === baseSegments.length - 1;
1137
-
1138
1428
  if (routeSegment) {
1139
1429
  if (routeSegment.type === 'wildcard') {
1140
1430
  if (baseSegment != null && baseSegment.value) {
1141
1431
  params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
1142
1432
  return true;
1143
1433
  }
1144
-
1145
1434
  return false;
1146
1435
  }
1147
-
1148
1436
  if (routeSegment.type === 'pathname') {
1149
1437
  if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
1150
1438
  return true;
1151
1439
  }
1152
-
1153
1440
  if (baseSegment) {
1154
1441
  if (matchLocation.caseSensitive) {
1155
1442
  if (routeSegment.value !== baseSegment.value) {
@@ -1160,41 +1447,36 @@
1160
1447
  }
1161
1448
  }
1162
1449
  }
1163
-
1164
1450
  if (!baseSegment) {
1165
1451
  return false;
1166
1452
  }
1167
-
1168
1453
  if (routeSegment.type === 'param') {
1169
1454
  if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
1170
1455
  return false;
1171
1456
  }
1172
-
1173
- if (!baseSegment.value.startsWith(':')) {
1457
+ if (baseSegment.value.charAt(0) !== '$') {
1174
1458
  params[routeSegment.value.substring(1)] = baseSegment.value;
1175
1459
  }
1176
1460
  }
1177
1461
  }
1178
-
1179
1462
  if (isLastRouteSegment && !isLastBaseSegment) {
1180
1463
  return !!matchLocation.fuzzy;
1181
1464
  }
1182
1465
  }
1183
-
1184
1466
  return true;
1185
1467
  })();
1186
-
1187
1468
  return isMatch ? params : undefined;
1188
1469
  }
1189
1470
 
1190
1471
  // @ts-nocheck
1472
+
1191
1473
  // qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
1474
+
1192
1475
  function encode(obj, pfx) {
1193
1476
  var k,
1194
- i,
1195
- tmp,
1196
- str = '';
1197
-
1477
+ i,
1478
+ tmp,
1479
+ str = '';
1198
1480
  for (k in obj) {
1199
1481
  if ((tmp = obj[k]) !== void 0) {
1200
1482
  if (Array.isArray(tmp)) {
@@ -1208,10 +1490,8 @@
1208
1490
  }
1209
1491
  }
1210
1492
  }
1211
-
1212
1493
  return (pfx || '') + str;
1213
1494
  }
1214
-
1215
1495
  function toValue(mix) {
1216
1496
  if (!mix) return '';
1217
1497
  var str = decodeURIComponent(mix);
@@ -1220,221 +1500,190 @@
1220
1500
  if (str.charAt(0) === '0') return str;
1221
1501
  return +str * 0 === 0 ? +str : str;
1222
1502
  }
1223
-
1224
1503
  function decode(str) {
1225
1504
  var tmp,
1226
- k,
1227
- out = {},
1228
- arr = str.split('&');
1229
-
1505
+ k,
1506
+ out = {},
1507
+ arr = str.split('&');
1230
1508
  while (tmp = arr.shift()) {
1231
1509
  tmp = tmp.split('=');
1232
1510
  k = tmp.shift();
1233
-
1234
1511
  if (out[k] !== void 0) {
1235
1512
  out[k] = [].concat(out[k], toValue(tmp.shift()));
1236
1513
  } else {
1237
1514
  out[k] = toValue(tmp.shift());
1238
1515
  }
1239
1516
  }
1240
-
1241
1517
  return out;
1242
1518
  }
1243
1519
 
1244
- function _extends() {
1245
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1246
- for (var i = 1; i < arguments.length; i++) {
1247
- var source = arguments[i];
1248
-
1249
- for (var key in source) {
1250
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1251
- target[key] = source[key];
1252
- }
1253
- }
1254
- }
1255
-
1256
- return target;
1257
- };
1258
- return _extends.apply(this, arguments);
1259
- }
1260
-
1261
- function createRoute(routeConfig, options, parent, router) {
1520
+ function createRoute(routeConfig, options, originalIndex, parent, router) {
1262
1521
  const {
1263
1522
  id,
1264
1523
  routeId,
1265
1524
  path: routePath,
1266
1525
  fullPath
1267
1526
  } = routeConfig;
1268
-
1269
- const action = router.state.actions[id] || (() => {
1270
- router.state.actions[id] = {
1271
- pending: [],
1272
- submit: async (submission, actionOpts) => {
1273
- var _actionOpts$invalidat;
1274
-
1275
- if (!route) {
1276
- return;
1277
- }
1278
-
1279
- const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
1280
- const actionState = {
1281
- submittedAt: Date.now(),
1282
- status: 'pending',
1283
- submission
1284
- };
1285
- action.current = actionState;
1286
- action.latest = actionState;
1287
- action.pending.push(actionState);
1288
- router.state = _extends({}, router.state, {
1289
- currentAction: actionState,
1290
- latestAction: actionState
1291
- });
1292
- router.notify();
1293
-
1294
- try {
1295
- const res = await (route.options.action == null ? void 0 : route.options.action(submission));
1296
- actionState.data = res;
1297
-
1298
- if (invalidate) {
1299
- router.invalidateRoute({
1300
- to: '.',
1301
- fromCurrent: true
1302
- });
1303
- await router.reload();
1304
- }
1305
-
1306
- actionState.status = 'success';
1307
- return res;
1308
- } catch (err) {
1309
- console.error(err);
1310
- actionState.error = err;
1311
- actionState.status = 'error';
1312
- } finally {
1313
- action.pending = action.pending.filter(d => d !== actionState);
1314
- router.removeActionQueue.push({
1315
- action,
1316
- actionState
1317
- });
1318
- router.notify();
1319
- }
1320
- }
1321
- };
1322
- return router.state.actions[id];
1323
- })();
1324
-
1325
- const loader = router.state.loaders[id] || (() => {
1326
- router.state.loaders[id] = {
1327
- pending: [],
1328
- fetch: async loaderContext => {
1329
- if (!route) {
1330
- return;
1331
- }
1332
-
1333
- const loaderState = {
1334
- loadedAt: Date.now(),
1335
- loaderContext
1336
- };
1337
- loader.current = loaderState;
1338
- loader.latest = loaderState;
1339
- loader.pending.push(loaderState); // router.state = {
1340
- // ...router.state,
1341
- // currentAction: loaderState,
1342
- // latestAction: loaderState,
1343
- // }
1344
-
1345
- router.notify();
1346
-
1347
- try {
1348
- return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
1349
- } finally {
1350
- loader.pending = loader.pending.filter(d => d !== loaderState); // router.removeActionQueue.push({ loader, loaderState })
1351
-
1352
- router.notify();
1353
- }
1354
- }
1355
- };
1356
- return router.state.loaders[id];
1357
- })();
1358
-
1359
1527
  let route = {
1528
+ routeInfo: undefined,
1360
1529
  routeId: id,
1361
1530
  routeRouteId: routeId,
1531
+ originalIndex,
1362
1532
  routePath,
1363
1533
  fullPath,
1364
1534
  options,
1365
1535
  router,
1366
1536
  childRoutes: undefined,
1367
1537
  parentRoute: parent,
1368
- action,
1369
- loader: loader,
1370
- buildLink: options => {
1371
- return router.buildLink(_extends({}, options, {
1372
- from: fullPath
1373
- }));
1374
- },
1375
- navigate: options => {
1376
- return router.navigate(_extends({}, options, {
1377
- from: fullPath
1378
- }));
1538
+ get action() {
1539
+ let action = router.store.actions[id] || (() => {
1540
+ router.setStore(s => {
1541
+ s.actions[id] = {
1542
+ submissions: [],
1543
+ submit: async (submission, actionOpts) => {
1544
+ if (!route) {
1545
+ return;
1546
+ }
1547
+ const invalidate = (actionOpts == null ? void 0 : actionOpts.invalidate) ?? true;
1548
+ const [actionStore, setActionStore] = createStore({
1549
+ submittedAt: Date.now(),
1550
+ status: 'pending',
1551
+ submission,
1552
+ isMulti: !!(actionOpts != null && actionOpts.multi)
1553
+ });
1554
+ router.setStore(s => {
1555
+ if (!(actionOpts != null && actionOpts.multi)) {
1556
+ s.actions[id].submissions = action.submissions.filter(d => d.isMulti);
1557
+ }
1558
+ s.actions[id].current = actionStore;
1559
+ s.actions[id].latest = actionStore;
1560
+ s.actions[id].submissions.push(actionStore);
1561
+ });
1562
+ try {
1563
+ const res = await (route.options.action == null ? void 0 : route.options.action(submission));
1564
+ setActionStore(s => {
1565
+ s.data = res;
1566
+ });
1567
+ if (invalidate) {
1568
+ router.invalidateRoute({
1569
+ to: '.',
1570
+ fromCurrent: true
1571
+ });
1572
+ await router.reload();
1573
+ }
1574
+ setActionStore(s => {
1575
+ s.status = 'success';
1576
+ });
1577
+ return res;
1578
+ } catch (err) {
1579
+ console.error(err);
1580
+ setActionStore(s => {
1581
+ s.error = err;
1582
+ s.status = 'error';
1583
+ });
1584
+ }
1585
+ }
1586
+ };
1587
+ });
1588
+ return router.store.actions[id];
1589
+ })();
1590
+ return action;
1379
1591
  },
1380
- matchRoute: (matchLocation, opts) => {
1381
- return router.matchRoute(_extends({}, matchLocation, {
1382
- from: fullPath
1383
- }), opts);
1592
+ get loader() {
1593
+ let loader = router.store.loaders[id] || (() => {
1594
+ router.setStore(s => {
1595
+ s.loaders[id] = {
1596
+ pending: [],
1597
+ fetch: async loaderContext => {
1598
+ if (!route) {
1599
+ return;
1600
+ }
1601
+ const loaderState = {
1602
+ loadedAt: Date.now(),
1603
+ loaderContext
1604
+ };
1605
+ router.setStore(s => {
1606
+ s.loaders[id].current = loaderState;
1607
+ s.loaders[id].latest = loaderState;
1608
+ s.loaders[id].pending.push(loaderState);
1609
+ });
1610
+ try {
1611
+ return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
1612
+ } finally {
1613
+ router.setStore(s => {
1614
+ s.loaders[id].pending = s.loaders[id].pending.filter(d => d !== loaderState);
1615
+ });
1616
+ }
1617
+ }
1618
+ };
1619
+ });
1620
+ return router.store.loaders[id];
1621
+ })();
1622
+ return loader;
1384
1623
  }
1624
+
1625
+ // buildLink: (options) => {
1626
+ // return router.buildLink({
1627
+ // ...options,
1628
+ // from: fullPath,
1629
+ // } as any) as any
1630
+ // },
1631
+
1632
+ // navigate: (options) => {
1633
+ // return router.navigate({
1634
+ // ...options,
1635
+ // from: fullPath,
1636
+ // } as any) as any
1637
+ // },
1638
+
1639
+ // matchRoute: (matchLocation, opts) => {
1640
+ // return router.matchRoute(
1641
+ // {
1642
+ // ...matchLocation,
1643
+ // from: fullPath,
1644
+ // } as any,
1645
+ // opts,
1646
+ // ) as any
1647
+ // },
1385
1648
  };
1649
+
1386
1650
  router.options.createRoute == null ? void 0 : router.options.createRoute({
1387
1651
  router,
1388
1652
  route
1389
1653
  });
1390
1654
  return route;
1391
1655
  }
1392
- function cascadeLoaderData(matches) {
1393
- matches.forEach((match, index) => {
1394
- const parent = matches[index - 1];
1395
-
1396
- if (parent) {
1397
- match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
1398
- }
1399
- });
1400
- }
1401
1656
 
1402
1657
  const rootRouteId = '__root__';
1403
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
1658
+ const createRouteConfig = function (options, children, isRoot, parentId, parentPath) {
1404
1659
  if (options === void 0) {
1405
1660
  options = {};
1406
1661
  }
1407
-
1408
1662
  if (isRoot === void 0) {
1409
1663
  isRoot = true;
1410
1664
  }
1411
-
1412
1665
  if (isRoot) {
1413
1666
  options.path = rootRouteId;
1414
- } // Strip the root from parentIds
1415
-
1667
+ }
1416
1668
 
1669
+ // Strip the root from parentIds
1417
1670
  if (parentId === rootRouteId) {
1418
1671
  parentId = '';
1419
1672
  }
1673
+ let path = isRoot ? rootRouteId : options.path;
1420
1674
 
1421
- let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
1422
-
1675
+ // If the path is anything other than an index path, trim it up
1423
1676
  if (path && path !== '/') {
1424
1677
  path = trimPath(path);
1425
1678
  }
1426
-
1427
1679
  const routeId = path || options.id;
1428
1680
  let id = joinPaths([parentId, routeId]);
1429
-
1430
1681
  if (path === rootRouteId) {
1431
1682
  path = '/';
1432
1683
  }
1433
-
1434
1684
  if (id !== rootRouteId) {
1435
1685
  id = joinPaths(['/', id]);
1436
1686
  }
1437
-
1438
1687
  const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
1439
1688
  return {
1440
1689
  id: id,
@@ -1443,256 +1692,340 @@
1443
1692
  fullPath: fullPath,
1444
1693
  options: options,
1445
1694
  children,
1446
- createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
1447
1695
  addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
1448
- createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
1696
+ createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
1697
+ generate: () => {
1698
+ invariant(false, `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `);
1699
+ }
1449
1700
  };
1450
1701
  };
1451
1702
 
1452
- const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
1703
+ /**
1704
+ * This function returns `a` if `b` is deeply equal.
1705
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
1706
+ * This can be used for structural sharing between JSON values for example.
1707
+ */
1708
+ function sharedClone(prev, next, touchAll) {
1709
+ const things = new Map();
1710
+ function recurse(prev, next) {
1711
+ if (prev === next) {
1712
+ return prev;
1713
+ }
1714
+ if (things.has(next)) {
1715
+ return things.get(next);
1716
+ }
1717
+ const prevIsArray = Array.isArray(prev);
1718
+ const nextIsArray = Array.isArray(next);
1719
+ const prevIsObj = isPlainObject(prev);
1720
+ const nextIsObj = isPlainObject(next);
1721
+ const isArray = prevIsArray && nextIsArray;
1722
+ const isObj = prevIsObj && nextIsObj;
1723
+ const isSameStructure = isArray || isObj;
1724
+
1725
+ // Both are arrays or objects
1726
+ if (isSameStructure) {
1727
+ const aSize = isArray ? prev.length : Object.keys(prev).length;
1728
+ const bItems = isArray ? next : Object.keys(next);
1729
+ const bSize = bItems.length;
1730
+ const copy = isArray ? [] : {};
1731
+ let equalItems = 0;
1732
+ for (let i = 0; i < bSize; i++) {
1733
+ const key = isArray ? i : bItems[i];
1734
+ if (copy[key] === prev[key]) {
1735
+ equalItems++;
1736
+ }
1737
+ }
1738
+ if (aSize === bSize && equalItems === aSize) {
1739
+ things.set(next, prev);
1740
+ return prev;
1741
+ }
1742
+ things.set(next, copy);
1743
+ for (let i = 0; i < bSize; i++) {
1744
+ const key = isArray ? i : bItems[i];
1745
+ if (typeof bItems[i] === 'function') {
1746
+ copy[key] = prev[key];
1747
+ } else {
1748
+ copy[key] = recurse(prev[key], next[key]);
1749
+ }
1750
+ if (copy[key] === prev[key]) {
1751
+ equalItems++;
1752
+ }
1753
+ }
1754
+ return copy;
1755
+ }
1756
+ if (nextIsArray) {
1757
+ const copy = [];
1758
+ things.set(next, copy);
1759
+ for (let i = 0; i < next.length; i++) {
1760
+ copy[i] = recurse(undefined, next[i]);
1761
+ }
1762
+ return copy;
1763
+ }
1764
+ if (nextIsObj) {
1765
+ const copy = {};
1766
+ things.set(next, copy);
1767
+ const nextKeys = Object.keys(next);
1768
+ for (let i = 0; i < nextKeys.length; i++) {
1769
+ const key = nextKeys[i];
1770
+ copy[key] = recurse(undefined, next[key]);
1771
+ }
1772
+ return copy;
1773
+ }
1774
+ return next;
1775
+ }
1776
+ return recurse(prev, next);
1777
+ }
1778
+
1779
+ // Copied from: https://github.com/jonschlinkert/is-plain-object
1780
+ function isPlainObject(o) {
1781
+ if (!hasObjectPrototype(o)) {
1782
+ return false;
1783
+ }
1784
+
1785
+ // If has modified constructor
1786
+ const ctor = o.constructor;
1787
+ if (typeof ctor === 'undefined') {
1788
+ return true;
1789
+ }
1790
+
1791
+ // If has modified prototype
1792
+ const prot = ctor.prototype;
1793
+ if (!hasObjectPrototype(prot)) {
1794
+ return false;
1795
+ }
1796
+
1797
+ // If constructor does not have an Object-specific method
1798
+ if (!prot.hasOwnProperty('isPrototypeOf')) {
1799
+ return false;
1800
+ }
1801
+
1802
+ // Most likely a plain Object
1803
+ return true;
1804
+ }
1805
+ function hasObjectPrototype(o) {
1806
+ return Object.prototype.toString.call(o) === '[object Object]';
1807
+ }
1808
+
1809
+ const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
1453
1810
  function createRouteMatch(router, route, opts) {
1454
- const routeMatch = _extends({}, route, opts, {
1455
- router,
1811
+ let componentsPromise;
1812
+ let dataPromise;
1813
+ let latestId = '';
1814
+ let resolve = () => {};
1815
+ function setLoaderData(loaderData) {
1816
+ batch(() => {
1817
+ setStore(s => {
1818
+ s.routeLoaderData = sharedClone(s.routeLoaderData, loaderData);
1819
+ });
1820
+ updateLoaderData();
1821
+ });
1822
+ }
1823
+ function updateLoaderData() {
1824
+ setStore(s => {
1825
+ var _store$parentMatch;
1826
+ s.loaderData = sharedClone(s.loaderData, {
1827
+ ...((_store$parentMatch = store.parentMatch) == null ? void 0 : _store$parentMatch.store.loaderData),
1828
+ ...s.routeLoaderData
1829
+ });
1830
+ });
1831
+ }
1832
+ const [store, setStore] = createStore({
1456
1833
  routeSearch: {},
1457
1834
  search: {},
1458
- childMatches: [],
1459
1835
  status: 'idle',
1460
1836
  routeLoaderData: {},
1461
1837
  loaderData: {},
1462
- isPending: false,
1463
1838
  isFetching: false,
1464
- isInvalid: false,
1839
+ invalid: false,
1465
1840
  invalidAt: Infinity,
1466
- getIsInvalid: () => {
1841
+ get isInvalid() {
1467
1842
  const now = Date.now();
1468
- return routeMatch.isInvalid || routeMatch.invalidAt < now;
1469
- },
1843
+ return this.invalid || this.invalidAt < now;
1844
+ }
1845
+ });
1846
+ const routeMatch = {
1847
+ ...route,
1848
+ ...opts,
1849
+ store,
1850
+ // setStore,
1851
+ router,
1852
+ childMatches: [],
1470
1853
  __: {
1471
- abortController: new AbortController(),
1472
- latestId: '',
1473
- resolve: () => {},
1474
- notify: () => {
1475
- routeMatch.__.resolve();
1476
-
1477
- routeMatch.router.notify();
1478
- },
1479
- startPending: () => {
1480
- var _routeMatch$options$p, _routeMatch$options$p2;
1481
-
1482
- const pendingMs = (_routeMatch$options$p = routeMatch.options.pendingMs) != null ? _routeMatch$options$p : router.options.defaultPendingMs;
1483
- const pendingMinMs = (_routeMatch$options$p2 = routeMatch.options.pendingMinMs) != null ? _routeMatch$options$p2 : router.options.defaultPendingMinMs;
1484
-
1485
- if (routeMatch.__.pendingTimeout || routeMatch.status !== 'loading' || typeof pendingMs === 'undefined') {
1486
- return;
1487
- }
1488
-
1489
- routeMatch.__.pendingTimeout = setTimeout(() => {
1490
- routeMatch.isPending = true;
1491
-
1492
- routeMatch.__.resolve();
1493
-
1494
- if (typeof pendingMinMs !== 'undefined') {
1495
- routeMatch.__.pendingMinPromise = new Promise(r => routeMatch.__.pendingMinTimeout = setTimeout(r, pendingMinMs));
1496
- }
1497
- }, pendingMs);
1498
- },
1499
- cancelPending: () => {
1500
- routeMatch.isPending = false;
1501
- clearTimeout(routeMatch.__.pendingTimeout);
1502
- clearTimeout(routeMatch.__.pendingMinTimeout);
1503
- delete routeMatch.__.pendingMinPromise;
1854
+ setParentMatch: parentMatch => {
1855
+ batch(() => {
1856
+ setStore(s => {
1857
+ s.parentMatch = parentMatch;
1858
+ });
1859
+ updateLoaderData();
1860
+ });
1504
1861
  },
1505
- // setParentMatch: (parentMatch?: RouteMatch) => {
1506
- // routeMatch.parentMatch = parentMatch
1507
- // },
1508
- // addChildMatch: (childMatch: RouteMatch) => {
1509
- // if (
1510
- // routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
1511
- // ) {
1512
- // return
1513
- // }
1514
- // routeMatch.childMatches.push(childMatch)
1515
- // },
1862
+ abortController: new AbortController(),
1516
1863
  validate: () => {
1517
- var _routeMatch$parentMat, _routeMatch$parentMat2;
1518
-
1864
+ var _store$parentMatch2;
1519
1865
  // Validate the search params and stabilize them
1520
- const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.location.search;
1521
-
1866
+ const parentSearch = ((_store$parentMatch2 = store.parentMatch) == null ? void 0 : _store$parentMatch2.store.search) ?? router.store.currentLocation.search;
1522
1867
  try {
1523
- const prevSearch = routeMatch.routeSearch;
1868
+ const prevSearch = store.routeSearch;
1524
1869
  const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
1525
- let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
1526
-
1527
- if (prevSearch !== nextSearch) {
1528
- routeMatch.isInvalid = true;
1529
- }
1870
+ let nextSearch = sharedClone(prevSearch, (validator == null ? void 0 : validator(parentSearch)) ?? {});
1871
+ batch(() => {
1872
+ // Invalidate route matches when search param stability changes
1873
+ if (prevSearch !== nextSearch) {
1874
+ setStore(s => s.invalid = true);
1875
+ }
1530
1876
 
1531
- routeMatch.routeSearch = nextSearch;
1532
- routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
1877
+ // TODO: Alright, do we need batch() here?
1878
+ setStore(s => {
1879
+ s.routeSearch = nextSearch;
1880
+ s.search = sharedClone(parentSearch, {
1881
+ ...parentSearch,
1882
+ ...nextSearch
1883
+ });
1884
+ });
1885
+ });
1886
+ componentTypes.map(async type => {
1887
+ const component = routeMatch.options[type];
1888
+ if (typeof routeMatch.__[type] !== 'function') {
1889
+ routeMatch.__[type] = component;
1890
+ }
1891
+ });
1533
1892
  } catch (err) {
1534
1893
  console.error(err);
1535
1894
  const error = new Error('Invalid search params found', {
1536
1895
  cause: err
1537
1896
  });
1538
1897
  error.code = 'INVALID_SEARCH_PARAMS';
1539
- routeMatch.status = 'error';
1540
- routeMatch.error = error; // Do not proceed with loading the route
1898
+ setStore(s => {
1899
+ s.status = 'error';
1900
+ s.error = error;
1901
+ });
1541
1902
 
1903
+ // Do not proceed with loading the route
1542
1904
  return;
1543
1905
  }
1544
1906
  }
1545
1907
  },
1546
1908
  cancel: () => {
1547
1909
  var _routeMatch$__$abortC;
1548
-
1549
1910
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1550
-
1551
- routeMatch.__.cancelPending();
1552
1911
  },
1553
1912
  invalidate: () => {
1554
- routeMatch.isInvalid = true;
1913
+ setStore(s => s.invalid = true);
1555
1914
  },
1556
1915
  hasLoaders: () => {
1557
- return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
1916
+ return !!(route.options.loader || componentTypes.some(d => {
1917
+ var _route$options$d;
1918
+ return (_route$options$d = route.options[d]) == null ? void 0 : _route$options$d.preload;
1919
+ }));
1558
1920
  },
1559
1921
  load: async loaderOpts => {
1560
1922
  const now = Date.now();
1561
- const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0; // If this is a preload, add it to the preload cache
1923
+ const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
1562
1924
 
1925
+ // If this is a preload, add it to the preload cache
1563
1926
  if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
1564
1927
  // If the match is currently active, don't preload it
1565
- if (router.state.matches.find(d => d.matchId === routeMatch.matchId)) {
1928
+ if (router.store.currentMatches.find(d => d.matchId === routeMatch.matchId)) {
1566
1929
  return;
1567
1930
  }
1568
-
1569
- router.matchCache[routeMatch.matchId] = {
1931
+ router.store.matchCache[routeMatch.matchId] = {
1570
1932
  gc: now + loaderOpts.gcMaxAge,
1571
1933
  match: routeMatch
1572
1934
  };
1573
- } // If the match is invalid, errored or idle, trigger it to load
1574
-
1935
+ }
1575
1936
 
1576
- if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
1937
+ // If the match is invalid, errored or idle, trigger it to load
1938
+ if (store.status === 'success' && store.isInvalid || store.status === 'error' || store.status === 'idle') {
1577
1939
  const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
1578
- routeMatch.fetch({
1940
+ await routeMatch.fetch({
1579
1941
  maxAge
1580
1942
  });
1581
1943
  }
1582
1944
  },
1583
1945
  fetch: async opts => {
1584
- const id = '' + Date.now() + Math.random();
1585
- routeMatch.__.latestId = id; // If the match was in an error state, set it
1586
- // to a loading state again. Otherwise, keep it
1587
- // as loading or resolved
1588
-
1589
- if (routeMatch.status === 'idle') {
1590
- routeMatch.status = 'loading';
1591
- } // We started loading the route, so it's no longer invalid
1592
-
1946
+ const loadId = '' + Date.now() + Math.random();
1947
+ latestId = loadId;
1948
+ const checkLatest = async () => {
1949
+ if (loadId !== latestId) {
1950
+ // warning(true, 'Data loader is out of date!')
1951
+ return new Promise(() => {});
1952
+ }
1953
+ };
1954
+ batch(() => {
1955
+ // If the match was in an error state, set it
1956
+ // to a loading state again. Otherwise, keep it
1957
+ // as loading or resolved
1958
+ if (store.status === 'idle') {
1959
+ setStore(s => s.status = 'loading');
1960
+ }
1593
1961
 
1594
- routeMatch.isInvalid = false;
1595
- routeMatch.__.loadPromise = new Promise(async resolve => {
1962
+ // We started loading the route, so it's no longer invalid
1963
+ setStore(s => s.invalid = false);
1964
+ });
1965
+ routeMatch.__.loadPromise = new Promise(async r => {
1596
1966
  // We are now fetching, even if it's in the background of a
1597
1967
  // resolved state
1598
- routeMatch.isFetching = true;
1599
- routeMatch.__.resolve = resolve;
1600
-
1601
- const loaderPromise = (async () => {
1602
- // Load the elements and data in parallel
1603
- routeMatch.__.elementsPromise = (async () => {
1604
- // then run all element and data loaders in parallel
1605
- // For each element type, potentially load it asynchronously
1606
- await Promise.all(elementTypes.map(async type => {
1607
- const routeElement = routeMatch.options[type];
1608
-
1609
- if (routeMatch.__[type]) {
1610
- return;
1611
- }
1612
-
1613
- routeMatch.__[type] = await router.options.createElement(routeElement);
1614
- }));
1615
- })();
1616
-
1617
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1618
- try {
1619
- var _ref, _ref2, _opts$maxAge;
1620
-
1621
- if (routeMatch.options.loader) {
1622
- const data = await routeMatch.options.loader({
1623
- params: routeMatch.params,
1624
- search: routeMatch.routeSearch,
1625
- signal: routeMatch.__.abortController.signal
1626
- });
1627
-
1628
- if (id !== routeMatch.__.latestId) {
1629
- return routeMatch.__.loaderPromise;
1630
- }
1631
-
1632
- routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1633
- }
1634
-
1635
- routeMatch.error = undefined;
1636
- routeMatch.status = 'success';
1637
- routeMatch.updatedAt = Date.now();
1638
- routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
1639
- } catch (err) {
1640
- if (id !== routeMatch.__.latestId) {
1641
- return routeMatch.__.loaderPromise;
1642
- }
1643
-
1644
- {
1645
- console.error(err);
1646
- }
1647
-
1648
- routeMatch.error = err;
1649
- routeMatch.status = 'error';
1650
- routeMatch.updatedAt = Date.now();
1968
+ setStore(s => s.isFetching = true);
1969
+ resolve = r;
1970
+ componentsPromise = (async () => {
1971
+ // then run all component and data loaders in parallel
1972
+ // For each component type, potentially load it asynchronously
1973
+
1974
+ await Promise.all(componentTypes.map(async type => {
1975
+ var _routeMatch$__$type;
1976
+ const component = routeMatch.options[type];
1977
+ if ((_routeMatch$__$type = routeMatch.__[type]) != null && _routeMatch$__$type.preload) {
1978
+ routeMatch.__[type] = await router.options.loadComponent(component);
1651
1979
  }
1652
- });
1653
-
1980
+ }));
1981
+ })();
1982
+ dataPromise = Promise.resolve().then(async () => {
1654
1983
  try {
1655
- await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
1656
-
1657
- if (id !== routeMatch.__.latestId) {
1658
- return routeMatch.__.loaderPromise;
1659
- }
1660
-
1661
- if (routeMatch.__.pendingMinPromise) {
1662
- await routeMatch.__.pendingMinPromise;
1663
- delete routeMatch.__.pendingMinPromise;
1984
+ if (routeMatch.options.loader) {
1985
+ const data = await router.loadMatchData(routeMatch);
1986
+ await checkLatest();
1987
+ setLoaderData(data);
1664
1988
  }
1665
- } finally {
1666
- if (id !== routeMatch.__.latestId) {
1667
- return routeMatch.__.loaderPromise;
1989
+ setStore(s => {
1990
+ s.error = undefined;
1991
+ s.status = 'success';
1992
+ s.updatedAt = Date.now();
1993
+ s.invalidAt = s.updatedAt + ((opts == null ? void 0 : opts.maxAge) ?? routeMatch.options.loaderMaxAge ?? router.options.defaultLoaderMaxAge ?? 0);
1994
+ });
1995
+ return store.routeLoaderData;
1996
+ } catch (err) {
1997
+ await checkLatest();
1998
+ {
1999
+ console.error(err);
1668
2000
  }
1669
-
1670
- routeMatch.__.cancelPending();
1671
-
1672
- routeMatch.isPending = false;
1673
- routeMatch.isFetching = false;
1674
-
1675
- routeMatch.__.notify();
2001
+ setStore(s => {
2002
+ s.error = err;
2003
+ s.status = 'error';
2004
+ s.updatedAt = Date.now();
2005
+ });
2006
+ throw err;
1676
2007
  }
1677
- })();
1678
-
1679
- routeMatch.__.loaderPromise = loaderPromise;
1680
- await loaderPromise;
1681
-
1682
- if (id !== routeMatch.__.latestId) {
1683
- return routeMatch.__.loaderPromise;
2008
+ });
2009
+ const after = async () => {
2010
+ await checkLatest();
2011
+ setStore(s => s.isFetching = false);
2012
+ delete routeMatch.__.loadPromise;
2013
+ resolve();
2014
+ };
2015
+ try {
2016
+ await Promise.all([componentsPromise, dataPromise.catch(() => {})]);
2017
+ after();
2018
+ } catch {
2019
+ after();
1684
2020
  }
1685
-
1686
- delete routeMatch.__.loaderPromise;
1687
2021
  });
1688
- return await routeMatch.__.loadPromise;
2022
+ await routeMatch.__.loadPromise;
2023
+ await checkLatest();
1689
2024
  }
1690
- });
1691
-
2025
+ };
1692
2026
  if (!routeMatch.hasLoaders()) {
1693
- routeMatch.status = 'success';
2027
+ setStore(s => s.status = 'success');
1694
2028
  }
1695
-
1696
2029
  return routeMatch;
1697
2030
  }
1698
2031
 
@@ -1703,221 +2036,347 @@
1703
2036
  if (searchStr.substring(0, 1) === '?') {
1704
2037
  searchStr = searchStr.substring(1);
1705
2038
  }
2039
+ let query = decode(searchStr);
1706
2040
 
1707
- let query = decode(searchStr); // Try to parse any query params that might be json
1708
-
2041
+ // Try to parse any query params that might be json
1709
2042
  for (let key in query) {
1710
2043
  const value = query[key];
1711
-
1712
2044
  if (typeof value === 'string') {
1713
2045
  try {
1714
2046
  query[key] = parser(value);
1715
- } catch (err) {//
2047
+ } catch (err) {
2048
+ //
1716
2049
  }
1717
2050
  }
1718
2051
  }
1719
-
1720
2052
  return query;
1721
2053
  };
1722
2054
  }
1723
2055
  function stringifySearchWith(stringify) {
1724
2056
  return search => {
1725
- search = _extends({}, search);
1726
-
2057
+ search = {
2058
+ ...search
2059
+ };
1727
2060
  if (search) {
1728
2061
  Object.keys(search).forEach(key => {
1729
2062
  const val = search[key];
1730
-
1731
2063
  if (typeof val === 'undefined' || val === undefined) {
1732
2064
  delete search[key];
1733
2065
  } else if (val && typeof val === 'object' && val !== null) {
1734
2066
  try {
1735
2067
  search[key] = stringify(val);
1736
- } catch (err) {// silent
2068
+ } catch (err) {
2069
+ // silent
1737
2070
  }
1738
2071
  }
1739
2072
  });
1740
2073
  }
1741
-
1742
2074
  const searchStr = encode(search).toString();
1743
- return searchStr ? "?" + searchStr : '';
2075
+ return searchStr ? `?${searchStr}` : '';
1744
2076
  };
1745
2077
  }
1746
2078
 
1747
2079
  var _window$document;
1748
2080
  // Detect if we're in the DOM
1749
- const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement); // This is the default history object if none is defined
2081
+ const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
1750
2082
 
2083
+ // This is the default history object if none is defined
1751
2084
  const createDefaultHistory = () => isServer ? createMemoryHistory() : createBrowserHistory();
1752
-
2085
+ function getInitialRouterState() {
2086
+ return {
2087
+ status: 'idle',
2088
+ latestLocation: null,
2089
+ currentLocation: null,
2090
+ currentMatches: [],
2091
+ actions: {},
2092
+ loaders: {},
2093
+ lastUpdated: Date.now(),
2094
+ matchCache: {},
2095
+ get isFetching() {
2096
+ return this.status === 'loading' || this.currentMatches.some(d => d.store.isFetching);
2097
+ },
2098
+ get isPreloading() {
2099
+ return Object.values(this.matchCache).some(d => d.match.store.isFetching && !this.currentMatches.find(dd => dd.matchId === d.match.matchId));
2100
+ }
2101
+ };
2102
+ }
1753
2103
  function createRouter(userOptions) {
1754
- var _userOptions$stringif, _userOptions$parseSea;
1755
-
1756
- const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
1757
-
1758
- const originalOptions = _extends({
2104
+ const originalOptions = {
1759
2105
  defaultLoaderGcMaxAge: 5 * 60 * 1000,
1760
2106
  defaultLoaderMaxAge: 0,
1761
2107
  defaultPreloadMaxAge: 2000,
1762
- defaultPreloadDelay: 50
1763
- }, userOptions, {
1764
- stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
1765
- parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
1766
- });
1767
-
1768
- let router = {
1769
- history,
2108
+ defaultPreloadDelay: 50,
2109
+ context: undefined,
2110
+ ...userOptions,
2111
+ stringifySearch: (userOptions == null ? void 0 : userOptions.stringifySearch) ?? defaultStringifySearch,
2112
+ parseSearch: (userOptions == null ? void 0 : userOptions.parseSearch) ?? defaultParseSearch
2113
+ };
2114
+ const [store, setStore] = createStore(getInitialRouterState());
2115
+ let navigationPromise;
2116
+ let startedLoadingAt = Date.now();
2117
+ let resolveNavigation = () => {};
2118
+ function onFocus() {
2119
+ router.load();
2120
+ }
2121
+ function buildRouteTree(rootRouteConfig) {
2122
+ const recurseRoutes = (routeConfigs, parent) => {
2123
+ return routeConfigs.map((routeConfig, i) => {
2124
+ const routeOptions = routeConfig.options;
2125
+ const route = createRoute(routeConfig, routeOptions, i, parent, router);
2126
+ const existingRoute = router.routesById[route.routeId];
2127
+ if (existingRoute) {
2128
+ {
2129
+ console.warn(`Duplicate routes found with id: ${String(route.routeId)}`, router.routesById, route);
2130
+ }
2131
+ throw new Error();
2132
+ }
2133
+ router.routesById[route.routeId] = route;
2134
+ const children = routeConfig.children;
2135
+ route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
2136
+ return route;
2137
+ });
2138
+ };
2139
+ const routes = recurseRoutes([rootRouteConfig]);
2140
+ return routes[0];
2141
+ }
2142
+ function parseLocation(location, previousLocation) {
2143
+ const parsedSearch = router.options.parseSearch(location.search);
2144
+ return {
2145
+ pathname: location.pathname,
2146
+ searchStr: location.search,
2147
+ search: sharedClone(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
2148
+ hash: location.hash.split('#').reverse()[0] ?? '',
2149
+ href: `${location.pathname}${location.search}${location.hash}`,
2150
+ state: location.state,
2151
+ key: location.key
2152
+ };
2153
+ }
2154
+ function navigate(location) {
2155
+ const next = router.buildNext(location);
2156
+ return commitLocation(next, location.replace);
2157
+ }
2158
+ function buildLocation(dest) {
2159
+ var _last, _dest$__preSearchFilt, _dest$__preSearchFilt2, _dest$__postSearchFil;
2160
+ if (dest === void 0) {
2161
+ dest = {};
2162
+ }
2163
+ const fromPathname = dest.fromCurrent ? store.latestLocation.pathname : dest.from ?? store.latestLocation.pathname;
2164
+ let pathname = resolvePath(router.basepath ?? '/', fromPathname, `${dest.to ?? '.'}`);
2165
+ const fromMatches = router.matchRoutes(store.latestLocation.pathname, {
2166
+ strictParseParams: true
2167
+ });
2168
+ const toMatches = router.matchRoutes(pathname);
2169
+ const prevParams = {
2170
+ ...((_last = last(fromMatches)) == null ? void 0 : _last.params)
2171
+ };
2172
+ let nextParams = (dest.params ?? true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
2173
+ if (nextParams) {
2174
+ toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
2175
+ Object.assign({}, nextParams, fn(nextParams));
2176
+ });
2177
+ }
2178
+ pathname = interpolatePath(pathname, nextParams ?? {});
2179
+
2180
+ // Pre filters first
2181
+ const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), store.latestLocation.search) : store.latestLocation.search;
2182
+
2183
+ // Then the link/navigate function
2184
+ const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
2185
+ : dest.search ? functionalUpdate(dest.search, preFilteredSearch) ?? {} // Updater
2186
+ : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
2187
+ : {};
2188
+
2189
+ // Then post filters
2190
+ const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
2191
+ const search = sharedClone(store.latestLocation.search, postFilteredSearch);
2192
+ const searchStr = router.options.stringifySearch(search);
2193
+ let hash = dest.hash === true ? store.latestLocation.hash : functionalUpdate(dest.hash, store.latestLocation.hash);
2194
+ hash = hash ? `#${hash}` : '';
2195
+ return {
2196
+ pathname,
2197
+ search,
2198
+ searchStr,
2199
+ state: store.latestLocation.state,
2200
+ hash,
2201
+ href: `${pathname}${searchStr}${hash}`,
2202
+ key: dest.key
2203
+ };
2204
+ }
2205
+ function commitLocation(next, replace) {
2206
+ const id = '' + Date.now() + Math.random();
2207
+ let nextAction = 'replace';
2208
+ if (!replace) {
2209
+ nextAction = 'push';
2210
+ }
2211
+ const isSameUrl = parseLocation(router.history.location).href === next.href;
2212
+ if (isSameUrl && !next.key) {
2213
+ nextAction = 'replace';
2214
+ }
2215
+ router.history[nextAction]({
2216
+ pathname: next.pathname,
2217
+ hash: next.hash,
2218
+ search: next.searchStr
2219
+ }, {
2220
+ id,
2221
+ ...next.state
2222
+ });
2223
+ return navigationPromise = new Promise(resolve => {
2224
+ const previousNavigationResolve = resolveNavigation;
2225
+ resolveNavigation = () => {
2226
+ previousNavigationResolve();
2227
+ resolve();
2228
+ };
2229
+ });
2230
+ }
2231
+ const router = {
2232
+ types: undefined,
2233
+ // public api
2234
+ history: (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory(),
2235
+ store,
2236
+ setStore,
1770
2237
  options: originalOptions,
1771
- listeners: [],
1772
- removeActionQueue: [],
1773
- // Resolved after construction
1774
2238
  basepath: '',
1775
2239
  routeTree: undefined,
1776
2240
  routesById: {},
1777
- location: undefined,
1778
- allRouteInfo: undefined,
1779
- //
1780
- navigationPromise: Promise.resolve(),
1781
- resolveNavigation: () => {},
1782
- matchCache: {},
1783
- state: {
1784
- status: 'idle',
1785
- location: null,
1786
- matches: [],
1787
- actions: {},
1788
- loaders: {},
1789
- loaderData: {},
1790
- lastUpdated: Date.now(),
1791
- isFetching: false,
1792
- isPreloading: false
1793
- },
1794
- startedLoadingAt: Date.now(),
1795
- subscribe: listener => {
1796
- router.listeners.push(listener);
1797
- return () => {
1798
- router.listeners = router.listeners.filter(x => x !== listener);
1799
- };
2241
+ reset: () => {
2242
+ setStore(s => Object.assign(s, getInitialRouterState()));
1800
2243
  },
1801
2244
  getRoute: id => {
1802
2245
  return router.routesById[id];
1803
2246
  },
1804
- notify: () => {
1805
- router.state = _extends({}, router.state, {
1806
- isFetching: router.state.status === 'loading' || router.state.matches.some(d => d.isFetching),
1807
- isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
2247
+ dehydrate: () => {
2248
+ return {
2249
+ store: {
2250
+ ...pick(store, ['latestLocation', 'currentLocation', 'status', 'lastUpdated']),
2251
+ currentMatches: store.currentMatches.map(match => ({
2252
+ matchId: match.matchId,
2253
+ store: pick(match.store, ['status', 'routeLoaderData', 'isInvalid', 'invalidAt'])
2254
+ }))
2255
+ },
2256
+ context: router.options.context
2257
+ };
2258
+ },
2259
+ hydrate: dehydratedRouter => {
2260
+ setStore(s => {
2261
+ // Update the context TODO: make this part of state?
2262
+ router.options.context = dehydratedRouter.context;
2263
+
2264
+ // Match the routes
2265
+ const currentMatches = router.matchRoutes(dehydratedRouter.store.latestLocation.pathname, {
2266
+ strictParseParams: true
2267
+ });
2268
+ currentMatches.forEach((match, index) => {
2269
+ const dehydratedMatch = dehydratedRouter.store.currentMatches[index];
2270
+ invariant(dehydratedMatch && dehydratedMatch.matchId === match.matchId, 'Oh no! There was a hydration mismatch when attempting to restore the state of the router! 😬');
2271
+ Object.assign(match, dehydratedMatch);
2272
+ });
2273
+ currentMatches.forEach(match => match.__.validate());
2274
+ Object.assign(s, {
2275
+ ...dehydratedRouter.store,
2276
+ currentMatches
2277
+ });
1808
2278
  });
1809
- cascadeLoaderData(router.state.matches);
1810
- router.listeners.forEach(listener => listener(router));
1811
2279
  },
1812
2280
  mount: () => {
1813
- const next = router.__.buildLocation({
1814
- to: '.',
1815
- search: true,
1816
- hash: true
1817
- }); // If the current location isn't updated, trigger a navigation
1818
- // to the current location. Otherwise, load the current location.
1819
-
1820
-
1821
- if (next.href !== router.location.href) {
1822
- router.__.commitLocation(next, true);
1823
- } else {
1824
- router.loadLocation();
1825
- }
1826
-
1827
- const unsub = history.listen(event => {
1828
- router.loadLocation(router.__.parseLocation(event.location, router.location));
1829
- }); // addEventListener does not exist in React Native, but window does
1830
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2281
+ // Mount only does anything on the client
2282
+ if (!isServer) {
2283
+ // If the router matches are empty, load the matches
2284
+ if (!store.currentMatches.length) {
2285
+ router.load();
2286
+ }
2287
+ const unsub = router.history.listen(event => {
2288
+ router.load(parseLocation(event.location, store.latestLocation));
2289
+ });
1831
2290
 
1832
- if (!isServer && window.addEventListener) {
1833
- // Listen to visibillitychange and focus
1834
- window.addEventListener('visibilitychange', router.onFocus, false);
1835
- window.addEventListener('focus', router.onFocus, false);
2291
+ // addEventListener does not exist in React Native, but window does
2292
+ // In the future, we might need to invert control here for more adapters
2293
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
2294
+ if (window.addEventListener) {
2295
+ // Listen to visibilitychange and focus
2296
+ window.addEventListener('visibilitychange', onFocus, false);
2297
+ window.addEventListener('focus', onFocus, false);
2298
+ }
2299
+ return () => {
2300
+ unsub();
2301
+ if (window.removeEventListener) {
2302
+ // Be sure to unsubscribe if a new handler is set
2303
+ window.removeEventListener('visibilitychange', onFocus);
2304
+ window.removeEventListener('focus', onFocus);
2305
+ }
2306
+ };
1836
2307
  }
1837
-
1838
- return () => {
1839
- unsub(); // Be sure to unsubscribe if a new handler is set
1840
-
1841
- window.removeEventListener('visibilitychange', router.onFocus);
1842
- window.removeEventListener('focus', router.onFocus);
1843
- };
1844
- },
1845
- onFocus: () => {
1846
- router.loadLocation();
2308
+ return () => {};
1847
2309
  },
1848
2310
  update: opts => {
2311
+ const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
2312
+ if (!store.latestLocation || newHistory) {
2313
+ if (opts != null && opts.history) {
2314
+ router.history = opts.history;
2315
+ }
2316
+ setStore(s => {
2317
+ s.latestLocation = parseLocation(router.history.location);
2318
+ s.currentLocation = s.latestLocation;
2319
+ });
2320
+ }
1849
2321
  Object.assign(router.options, opts);
1850
2322
  const {
1851
2323
  basepath,
1852
2324
  routeConfig
1853
2325
  } = router.options;
1854
- router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
1855
-
2326
+ router.basepath = `/${trimPath(basepath ?? '') ?? ''}`;
1856
2327
  if (routeConfig) {
1857
2328
  router.routesById = {};
1858
- router.routeTree = router.__.buildRouteTree(routeConfig);
2329
+ router.routeTree = buildRouteTree(routeConfig);
1859
2330
  }
1860
-
1861
2331
  return router;
1862
2332
  },
1863
2333
  cancelMatches: () => {
1864
- var _router$state$pending, _router$state$pending2;
1865
- [...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
2334
+ [...store.currentMatches, ...(store.pendingMatches || [])].forEach(match => {
1866
2335
  match.cancel();
1867
2336
  });
1868
2337
  },
1869
- loadLocation: async next => {
1870
- const id = Math.random();
1871
- router.startedLoadingAt = id;
1872
-
1873
- if (next) {
1874
- // Ingest the new location
1875
- router.location = next;
1876
- } // Clear out old actions
1877
-
1878
-
1879
- router.removeActionQueue.forEach(_ref => {
1880
- let {
1881
- action,
1882
- actionState
1883
- } = _ref;
1884
-
1885
- if (router.state.currentAction === actionState) {
1886
- router.state.currentAction = undefined;
1887
- }
1888
-
1889
- if (action.current === actionState) {
1890
- action.current = undefined;
2338
+ load: async next => {
2339
+ let now = Date.now();
2340
+ const startedAt = now;
2341
+ startedLoadingAt = startedAt;
2342
+
2343
+ // Cancel any pending matches
2344
+ router.cancelMatches();
2345
+ let matches;
2346
+ batch(() => {
2347
+ if (next) {
2348
+ // Ingest the new location
2349
+ setStore(s => {
2350
+ s.latestLocation = next;
2351
+ });
1891
2352
  }
1892
- });
1893
- router.removeActionQueue = []; // Cancel any pending matches
1894
-
1895
- router.cancelMatches(); // Match the routes
1896
2353
 
1897
- const matches = router.matchRoutes(location.pathname, {
1898
- strictParseParams: true
1899
- });
1900
- router.state = _extends({}, router.state, {
1901
- pending: {
1902
- matches: matches,
1903
- location: router.location
1904
- },
1905
- status: 'loading'
1906
- });
1907
- router.notify(); // Load the matches
1908
-
1909
- await router.loadMatches(matches, {
1910
- withPending: true
2354
+ // Match the routes
2355
+ matches = router.matchRoutes(store.latestLocation.pathname, {
2356
+ strictParseParams: true
2357
+ });
2358
+ console.log('set loading', matches);
2359
+ setStore(s => {
2360
+ s.status = 'loading';
2361
+ s.pendingMatches = matches;
2362
+ s.pendingLocation = store.latestLocation;
2363
+ });
1911
2364
  });
1912
2365
 
1913
- if (router.startedLoadingAt !== id) {
1914
- // Ignore side-effects of match loading
1915
- return router.navigationPromise;
2366
+ // Load the matches
2367
+ try {
2368
+ await router.loadMatches(matches);
2369
+ } catch (err) {
2370
+ console.log(err);
2371
+ invariant(false, 'Matches failed to load due to error above ☝️. Navigation cancelled!');
1916
2372
  }
1917
-
1918
- const previousMatches = router.state.matches;
2373
+ if (startedLoadingAt !== startedAt) {
2374
+ // Ignore side-effects of outdated side-effects
2375
+ return navigationPromise;
2376
+ }
2377
+ const previousMatches = store.currentMatches;
1919
2378
  const exiting = [],
1920
- staying = [];
2379
+ staying = [];
1921
2380
  previousMatches.forEach(d => {
1922
2381
  if (matches.find(dd => dd.matchId === d.matchId)) {
1923
2382
  staying.push(d);
@@ -1925,24 +2384,24 @@
1925
2384
  exiting.push(d);
1926
2385
  }
1927
2386
  });
1928
- const now = Date.now();
2387
+ const entering = matches.filter(d => {
2388
+ return !previousMatches.find(dd => dd.matchId === d.matchId);
2389
+ });
2390
+ now = Date.now();
1929
2391
  exiting.forEach(d => {
1930
- var _ref2, _d$options$loaderGcMa, _ref3, _d$options$loaderMaxA;
1931
-
1932
2392
  d.__.onExit == null ? void 0 : d.__.onExit({
1933
2393
  params: d.params,
1934
- search: d.routeSearch
1935
- }); // Clear idle error states when match leaves
2394
+ search: d.store.routeSearch
2395
+ });
1936
2396
 
1937
- if (d.status === 'error' && !d.isFetching) {
1938
- d.status = 'idle';
1939
- d.error = undefined;
2397
+ // Clear idle error states when match leaves
2398
+ if (d.store.status === 'error' && !d.store.isFetching) {
2399
+ d.store.status = 'idle';
2400
+ d.store.error = undefined;
1940
2401
  }
1941
-
1942
- const gc = Math.max((_ref2 = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref2 : 0, (_ref3 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0);
1943
-
2402
+ const gc = Math.max(d.options.loaderGcMaxAge ?? router.options.defaultLoaderGcMaxAge ?? 0, d.options.loaderMaxAge ?? router.options.defaultLoaderMaxAge ?? 0);
1944
2403
  if (gc > 0) {
1945
- router.matchCache[d.matchId] = {
2404
+ store.matchCache[d.matchId] = {
1946
2405
  gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
1947
2406
  match: d
1948
2407
  };
@@ -1951,62 +2410,65 @@
1951
2410
  staying.forEach(d => {
1952
2411
  d.options.onTransition == null ? void 0 : d.options.onTransition({
1953
2412
  params: d.params,
1954
- search: d.routeSearch
2413
+ search: d.store.routeSearch
1955
2414
  });
1956
2415
  });
1957
- const entering = matches.filter(d => {
1958
- return !previousMatches.find(dd => dd.matchId === d.matchId);
1959
- });
1960
2416
  entering.forEach(d => {
1961
- d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
2417
+ d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1962
2418
  params: d.params,
1963
- search: d.search
2419
+ search: d.store.search
1964
2420
  });
1965
- delete router.matchCache[d.matchId];
2421
+ delete store.matchCache[d.matchId];
1966
2422
  });
1967
-
1968
- if (matches.some(d => d.status === 'loading')) {
1969
- router.notify();
1970
- await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
1971
- }
1972
-
1973
- if (router.startedLoadingAt !== id) {
2423
+ if (startedLoadingAt !== startedAt) {
1974
2424
  // Ignore side-effects of match loading
1975
2425
  return;
1976
2426
  }
1977
-
1978
- router.state = _extends({}, router.state, {
1979
- location: router.location,
1980
- matches,
1981
- pending: undefined,
1982
- status: 'idle'
2427
+ matches.forEach(match => {
2428
+ // Clear actions
2429
+ if (match.action) {
2430
+ // TODO: Check reactivity here
2431
+ match.action.current = undefined;
2432
+ match.action.submissions = [];
2433
+ }
2434
+ });
2435
+ setStore(s => {
2436
+ console.log('set', matches);
2437
+ Object.assign(s, {
2438
+ status: 'idle',
2439
+ currentLocation: store.latestLocation,
2440
+ currentMatches: matches,
2441
+ pendingLocation: undefined,
2442
+ pendingMatches: undefined
2443
+ });
1983
2444
  });
1984
- router.notify();
1985
- router.resolveNavigation();
2445
+ resolveNavigation();
1986
2446
  },
1987
2447
  cleanMatchCache: () => {
1988
2448
  const now = Date.now();
1989
- Object.keys(router.matchCache).forEach(matchId => {
1990
- const entry = router.matchCache[matchId]; // Don't remove loading matches
2449
+ setStore(s => {
2450
+ Object.keys(s.matchCache).forEach(matchId => {
2451
+ const entry = s.matchCache[matchId];
1991
2452
 
1992
- if (entry.match.status === 'loading') {
1993
- return;
1994
- } // Do not remove successful matches that are still valid
1995
-
1996
-
1997
- if (entry.gc > 0 && entry.gc > now) {
1998
- return;
1999
- } // Everything else gets removed
2453
+ // Don't remove loading matches
2454
+ if (entry.match.store.status === 'loading') {
2455
+ return;
2456
+ }
2000
2457
 
2458
+ // Do not remove successful matches that are still valid
2459
+ if (entry.gc > 0 && entry.gc > now) {
2460
+ return;
2461
+ }
2001
2462
 
2002
- delete router.matchCache[matchId];
2463
+ // Everything else gets removed
2464
+ delete s.matchCache[matchId];
2465
+ });
2003
2466
  });
2004
2467
  },
2005
- loadRoute: async function loadRoute(navigateOpts) {
2468
+ loadRoute: async function (navigateOpts) {
2006
2469
  if (navigateOpts === void 0) {
2007
- navigateOpts = router.location;
2470
+ navigateOpts = store.latestLocation;
2008
2471
  }
2009
-
2010
2472
  const next = router.buildNext(navigateOpts);
2011
2473
  const matches = router.matchRoutes(next.pathname, {
2012
2474
  strictParseParams: true
@@ -2014,143 +2476,176 @@
2014
2476
  await router.loadMatches(matches);
2015
2477
  return matches;
2016
2478
  },
2017
- preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
2018
- var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
2019
-
2479
+ preloadRoute: async function (navigateOpts, loaderOpts) {
2020
2480
  if (navigateOpts === void 0) {
2021
- navigateOpts = router.location;
2481
+ navigateOpts = store.latestLocation;
2022
2482
  }
2023
-
2024
2483
  const next = router.buildNext(navigateOpts);
2025
2484
  const matches = router.matchRoutes(next.pathname, {
2026
2485
  strictParseParams: true
2027
2486
  });
2028
2487
  await router.loadMatches(matches, {
2029
2488
  preload: true,
2030
- maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
2031
- gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
2489
+ maxAge: loaderOpts.maxAge ?? router.options.defaultPreloadMaxAge ?? router.options.defaultLoaderMaxAge ?? 0,
2490
+ gcMaxAge: loaderOpts.gcMaxAge ?? router.options.defaultPreloadGcMaxAge ?? router.options.defaultLoaderGcMaxAge ?? 0
2032
2491
  });
2033
2492
  return matches;
2034
2493
  },
2035
2494
  matchRoutes: (pathname, opts) => {
2036
- var _router$state$pending3, _router$state$pending4;
2037
-
2038
2495
  router.cleanMatchCache();
2039
2496
  const matches = [];
2040
-
2041
2497
  if (!router.routeTree) {
2042
2498
  return matches;
2043
2499
  }
2044
-
2045
- const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
2046
-
2500
+ const existingMatches = [...store.currentMatches, ...(store.pendingMatches ?? [])];
2047
2501
  const recurse = async routes => {
2048
- var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
2049
-
2502
+ var _foundRoute$childRout;
2050
2503
  const parentMatch = last(matches);
2051
- let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
2052
- const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
2504
+ let params = (parentMatch == null ? void 0 : parentMatch.params) ?? {};
2505
+ const filteredRoutes = (router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) ?? routes;
2053
2506
  let foundRoutes = [];
2054
-
2055
2507
  const findMatchInRoutes = (parentRoutes, routes) => {
2056
2508
  routes.some(route => {
2057
- var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
2058
-
2509
+ var _route$childRoutes, _route$childRoutes2;
2059
2510
  if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
2060
2511
  return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
2061
2512
  }
2062
-
2063
2513
  const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
2064
- const matchParams = matchPathname(pathname, {
2514
+ const matchParams = matchPathname(router.basepath, pathname, {
2065
2515
  to: route.fullPath,
2066
2516
  fuzzy,
2067
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
2517
+ caseSensitive: route.options.caseSensitive ?? router.options.caseSensitive
2068
2518
  });
2069
-
2070
2519
  if (matchParams) {
2071
2520
  let parsedParams;
2072
-
2073
2521
  try {
2074
- var _route$options$parseP;
2075
-
2076
- parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
2522
+ parsedParams = (route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) ?? matchParams;
2077
2523
  } catch (err) {
2078
2524
  if (opts != null && opts.strictParseParams) {
2079
2525
  throw err;
2080
2526
  }
2081
2527
  }
2082
-
2083
- params = _extends({}, params, parsedParams);
2528
+ params = {
2529
+ ...params,
2530
+ ...parsedParams
2531
+ };
2084
2532
  }
2085
-
2086
2533
  if (!!matchParams) {
2087
2534
  foundRoutes = [...parentRoutes, route];
2088
2535
  }
2089
-
2090
2536
  return !!foundRoutes.length;
2091
2537
  });
2092
2538
  return !!foundRoutes.length;
2093
2539
  };
2094
-
2095
2540
  findMatchInRoutes([], filteredRoutes);
2096
-
2097
2541
  if (!foundRoutes.length) {
2098
2542
  return;
2099
2543
  }
2100
-
2101
2544
  foundRoutes.forEach(foundRoute => {
2102
- var _router$matchCache$ma;
2103
-
2545
+ var _store$matchCache$mat;
2104
2546
  const interpolatedPath = interpolatePath(foundRoute.routePath, params);
2105
2547
  const matchId = interpolatePath(foundRoute.routeId, params, true);
2106
- const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
2548
+ const match = existingMatches.find(d => d.matchId === matchId) || ((_store$matchCache$mat = store.matchCache[matchId]) == null ? void 0 : _store$matchCache$mat.match) || createRouteMatch(router, foundRoute, {
2549
+ parentMatch,
2107
2550
  matchId,
2108
2551
  params,
2109
- pathname: joinPaths([pathname, interpolatedPath])
2552
+ pathname: joinPaths([router.basepath, interpolatedPath])
2110
2553
  });
2111
2554
  matches.push(match);
2112
2555
  });
2113
2556
  const foundRoute = last(foundRoutes);
2114
-
2115
2557
  if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
2116
2558
  recurse(foundRoute.childRoutes);
2117
2559
  }
2118
2560
  };
2119
-
2120
2561
  recurse([router.routeTree]);
2121
- cascadeLoaderData(matches);
2562
+ linkMatches(matches);
2122
2563
  return matches;
2123
2564
  },
2124
2565
  loadMatches: async (resolvedMatches, loaderOpts) => {
2125
- const matchPromises = resolvedMatches.map(async match => {
2566
+ resolvedMatches.forEach(async match => {
2126
2567
  // Validate the match (loads search params etc)
2127
2568
  match.__.validate();
2569
+ });
2128
2570
 
2571
+ // Check each match middleware to see if the route can be accessed
2572
+ await Promise.all(resolvedMatches.map(async match => {
2573
+ try {
2574
+ await (match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
2575
+ router: router,
2576
+ match
2577
+ }));
2578
+ } catch (err) {
2579
+ if (!(loaderOpts != null && loaderOpts.preload)) {
2580
+ match.options.onLoadError == null ? void 0 : match.options.onLoadError(err);
2581
+ }
2582
+ throw err;
2583
+ }
2584
+ }));
2585
+ const matchPromises = resolvedMatches.map(async match => {
2586
+ var _search$__data;
2587
+ const search = match.store.search;
2588
+ if ((_search$__data = search.__data) != null && _search$__data.matchId && search.__data.matchId !== match.matchId) {
2589
+ return;
2590
+ }
2129
2591
  match.load(loaderOpts);
2130
-
2131
- if (match.status === 'loading') {
2132
- // If requested, start the pending timers
2133
- if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
2134
- // This might be completion, error, or a pending state
2135
-
2592
+ if (match.store.status !== 'success' && match.__.loadPromise) {
2593
+ // Wait for the first sign of activity from the match
2136
2594
  await match.__.loadPromise;
2137
2595
  }
2138
2596
  });
2139
- router.notify();
2140
2597
  await Promise.all(matchPromises);
2141
2598
  },
2142
- invalidateRoute: opts => {
2143
- var _router$state$pending5, _router$state$pending6;
2599
+ loadMatchData: async routeMatch => {
2600
+ if (isServer || !router.options.useServerData) {
2601
+ return (await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
2602
+ // parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
2603
+ params: routeMatch.params,
2604
+ search: routeMatch.store.routeSearch,
2605
+ signal: routeMatch.__.abortController.signal
2606
+ }))) || {};
2607
+ } else {
2608
+ const next = router.buildNext({
2609
+ to: '.',
2610
+ search: d => ({
2611
+ ...(d ?? {}),
2612
+ __data: {
2613
+ matchId: routeMatch.matchId
2614
+ }
2615
+ })
2616
+ });
2617
+
2618
+ // Refresh:
2619
+ // '/dashboard'
2620
+ // '/dashboard/invoices/'
2621
+ // '/dashboard/invoices/123'
2622
+
2623
+ // New:
2624
+ // '/dashboard/invoices/456'
2144
2625
 
2626
+ // TODO: batch requests when possible
2627
+
2628
+ const res = await fetch(next.href, {
2629
+ method: 'GET'
2630
+ // signal: routeMatch.__.abortController.signal,
2631
+ });
2632
+
2633
+ if (res.ok) {
2634
+ return res.json();
2635
+ }
2636
+ throw new Error('Failed to fetch match data');
2637
+ }
2638
+ },
2639
+ invalidateRoute: opts => {
2145
2640
  const next = router.buildNext(opts);
2146
2641
  const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
2147
- [...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
2642
+ [...store.currentMatches, ...(store.pendingMatches ?? [])].forEach(match => {
2148
2643
  if (unloadedMatchIds.includes(match.matchId)) {
2149
2644
  match.invalidate();
2150
2645
  }
2151
2646
  });
2152
2647
  },
2153
- reload: () => router.__.navigate({
2648
+ reload: () => navigate({
2154
2649
  fromCurrent: true,
2155
2650
  replace: true,
2156
2651
  search: true
@@ -2159,31 +2654,28 @@
2159
2654
  return resolvePath(router.basepath, from, cleanPath(path));
2160
2655
  },
2161
2656
  matchRoute: (location, opts) => {
2162
- var _location$from;
2163
-
2164
2657
  // const location = router.buildNext(opts)
2165
- location = _extends({}, location, {
2166
- to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
2167
- });
2168
- const next = router.buildNext(location);
2169
2658
 
2659
+ location = {
2660
+ ...location,
2661
+ to: location.to ? router.resolvePath(location.from ?? '', location.to) : undefined
2662
+ };
2663
+ const next = router.buildNext(location);
2170
2664
  if (opts != null && opts.pending) {
2171
- var _router$state$pending7;
2172
-
2173
- if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
2665
+ if (!store.pendingLocation) {
2174
2666
  return false;
2175
2667
  }
2176
-
2177
- return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
2668
+ return !!matchPathname(router.basepath, store.pendingLocation.pathname, {
2669
+ ...opts,
2178
2670
  to: next.pathname
2179
- }));
2671
+ });
2180
2672
  }
2181
-
2182
- return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
2673
+ return matchPathname(router.basepath, store.currentLocation.pathname, {
2674
+ ...opts,
2183
2675
  to: next.pathname
2184
- }));
2676
+ });
2185
2677
  },
2186
- navigate: async _ref8 => {
2678
+ navigate: async _ref => {
2187
2679
  let {
2188
2680
  from,
2189
2681
  to = '.',
@@ -2191,22 +2683,21 @@
2191
2683
  hash,
2192
2684
  replace,
2193
2685
  params
2194
- } = _ref8;
2686
+ } = _ref;
2195
2687
  // If this link simply reloads the current route,
2196
2688
  // make sure it has a new key so it will trigger a data refresh
2689
+
2197
2690
  // If this `to` is a valid external URL, return
2198
2691
  // null for LinkUtils
2199
2692
  const toString = String(to);
2200
2693
  const fromString = String(from);
2201
2694
  let isExternal;
2202
-
2203
2695
  try {
2204
- new URL("" + toString);
2696
+ new URL(`${toString}`);
2205
2697
  isExternal = true;
2206
2698
  } catch (e) {}
2207
-
2208
2699
  invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
2209
- return router.__.navigate({
2700
+ return navigate({
2210
2701
  from: fromString,
2211
2702
  to: toString,
2212
2703
  search,
@@ -2215,9 +2706,7 @@
2215
2706
  params
2216
2707
  });
2217
2708
  },
2218
- buildLink: _ref9 => {
2219
- var _preload, _ref10;
2220
-
2709
+ buildLink: _ref2 => {
2221
2710
  let {
2222
2711
  from,
2223
2712
  to = '.',
@@ -2232,20 +2721,20 @@
2232
2721
  preloadGcMaxAge: userPreloadGcMaxAge,
2233
2722
  preloadDelay: userPreloadDelay,
2234
2723
  disabled
2235
- } = _ref9;
2236
-
2724
+ } = _ref2;
2237
2725
  // If this link simply reloads the current route,
2238
2726
  // make sure it has a new key so it will trigger a data refresh
2727
+
2239
2728
  // If this `to` is a valid external URL, return
2240
2729
  // null for LinkUtils
2730
+
2241
2731
  try {
2242
- new URL("" + to);
2732
+ new URL(`${to}`);
2243
2733
  return {
2244
2734
  type: 'external',
2245
2735
  href: to
2246
2736
  };
2247
2737
  } catch (e) {}
2248
-
2249
2738
  const nextOpts = {
2250
2739
  from,
2251
2740
  to,
@@ -2255,70 +2744,72 @@
2255
2744
  replace
2256
2745
  };
2257
2746
  const next = router.buildNext(nextOpts);
2258
- preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2259
- const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
2747
+ preload = preload ?? router.options.defaultPreload;
2748
+ const preloadDelay = userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0;
2260
2749
 
2261
- const pathIsEqual = router.state.location.pathname === next.pathname;
2262
- const currentPathSplit = router.state.location.pathname.split('/');
2750
+ // Compare path/hash for matches
2751
+ const pathIsEqual = store.currentLocation.pathname === next.pathname;
2752
+ const currentPathSplit = store.currentLocation.pathname.split('/');
2263
2753
  const nextPathSplit = next.pathname.split('/');
2264
2754
  const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
2265
- const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
2266
-
2755
+ const hashIsEqual = store.currentLocation.hash === next.hash;
2756
+ // Combine the matches based on user options
2267
2757
  const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
2268
- const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
2758
+ const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
2269
2759
 
2270
- const isActive = pathTest && hashTest; // The click handler
2760
+ // The final "active" test
2761
+ const isActive = pathTest && hashTest;
2271
2762
 
2763
+ // The click handler
2272
2764
  const handleClick = e => {
2273
2765
  if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
2274
2766
  e.preventDefault();
2275
-
2276
2767
  if (pathIsEqual && !search && !hash) {
2277
2768
  router.invalidateRoute(nextOpts);
2278
- } // All is well? Navigate!)
2279
-
2769
+ }
2280
2770
 
2281
- router.__.navigate(nextOpts);
2771
+ // All is well? Navigate!
2772
+ navigate(nextOpts);
2282
2773
  }
2283
- }; // The click handler
2284
-
2774
+ };
2285
2775
 
2776
+ // The click handler
2286
2777
  const handleFocus = e => {
2287
2778
  if (preload) {
2288
2779
  router.preloadRoute(nextOpts, {
2289
2780
  maxAge: userPreloadMaxAge,
2290
2781
  gcMaxAge: userPreloadGcMaxAge
2782
+ }).catch(err => {
2783
+ console.log(err);
2784
+ console.warn('Error preloading route! ☝️');
2291
2785
  });
2292
2786
  }
2293
2787
  };
2294
-
2295
2788
  const handleEnter = e => {
2296
2789
  const target = e.target || {};
2297
-
2298
2790
  if (preload) {
2299
2791
  if (target.preloadTimeout) {
2300
2792
  return;
2301
2793
  }
2302
-
2303
2794
  target.preloadTimeout = setTimeout(() => {
2304
2795
  target.preloadTimeout = null;
2305
2796
  router.preloadRoute(nextOpts, {
2306
2797
  maxAge: userPreloadMaxAge,
2307
2798
  gcMaxAge: userPreloadGcMaxAge
2799
+ }).catch(err => {
2800
+ console.log(err);
2801
+ console.warn('Error preloading route! ☝️');
2308
2802
  });
2309
2803
  }, preloadDelay);
2310
2804
  }
2311
2805
  };
2312
-
2313
2806
  const handleLeave = e => {
2314
2807
  const target = e.target || {};
2315
-
2316
2808
  if (target.preloadTimeout) {
2317
2809
  clearTimeout(target.preloadTimeout);
2318
2810
  target.preloadTimeout = null;
2319
2811
  }
2320
2812
  };
2321
-
2322
2813
  return {
2323
2814
  type: 'internal',
2324
2815
  next,
@@ -2331,512 +2822,412 @@
2331
2822
  };
2332
2823
  },
2333
2824
  buildNext: opts => {
2334
- const next = router.__.buildLocation(opts);
2335
-
2825
+ const next = buildLocation(opts);
2336
2826
  const matches = router.matchRoutes(next.pathname);
2337
-
2338
- const __preSearchFilters = matches.map(match => {
2339
- var _match$options$preSea;
2340
-
2341
- return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
2342
- }).flat().filter(Boolean);
2343
-
2344
- const __postSearchFilters = matches.map(match => {
2345
- var _match$options$postSe;
2346
-
2347
- return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
2348
- }).flat().filter(Boolean);
2349
-
2350
- return router.__.buildLocation(_extends({}, opts, {
2827
+ const __preSearchFilters = matches.map(match => match.options.preSearchFilters ?? []).flat().filter(Boolean);
2828
+ const __postSearchFilters = matches.map(match => match.options.postSearchFilters ?? []).flat().filter(Boolean);
2829
+ return buildLocation({
2830
+ ...opts,
2351
2831
  __preSearchFilters,
2352
2832
  __postSearchFilters
2353
- }));
2354
- },
2355
- __: {
2356
- buildRouteTree: rootRouteConfig => {
2357
- const recurseRoutes = (routeConfigs, parent) => {
2358
- return routeConfigs.map(routeConfig => {
2359
- const routeOptions = routeConfig.options;
2360
- const route = createRoute(routeConfig, routeOptions, parent, router); // {
2361
- // pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
2362
- // pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
2363
- // }
2364
-
2365
- const existingRoute = router.routesById[route.routeId];
2366
-
2367
- if (existingRoute) {
2368
- {
2369
- console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
2370
- }
2371
-
2372
- throw new Error();
2373
- }
2374
- router.routesById[route.routeId] = route;
2375
- const children = routeConfig.children;
2376
- route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
2377
- return route;
2378
- });
2379
- };
2380
-
2381
- const routes = recurseRoutes([rootRouteConfig]);
2382
- return routes[0];
2383
- },
2384
- parseLocation: (location, previousLocation) => {
2385
- var _location$hash$split$;
2386
-
2387
- const parsedSearch = router.options.parseSearch(location.search);
2388
- return {
2389
- pathname: location.pathname,
2390
- searchStr: location.search,
2391
- search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
2392
- hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
2393
- href: "" + location.pathname + location.search + location.hash,
2394
- state: location.state,
2395
- key: location.key
2396
- };
2397
- },
2398
- navigate: location => {
2399
- const next = router.buildNext(location);
2400
- return router.__.commitLocation(next, location.replace);
2401
- },
2402
- buildLocation: function buildLocation(dest) {
2403
- var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
2404
-
2405
- if (dest === void 0) {
2406
- dest = {};
2407
- }
2408
-
2409
- // const resolvedFrom: Location = {
2410
- // ...router.location,
2411
- const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
2412
-
2413
- let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
2414
-
2415
- const fromMatches = router.matchRoutes(router.location.pathname, {
2416
- strictParseParams: true
2417
- });
2418
- const toMatches = router.matchRoutes(pathname);
2419
-
2420
- const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
2421
-
2422
- let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
2423
-
2424
- if (nextParams) {
2425
- toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
2426
- Object.assign({}, nextParams, fn(nextParams));
2427
- });
2428
- }
2429
-
2430
- pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
2431
-
2432
- const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
2433
-
2434
- const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
2435
- : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
2436
- : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
2437
- : {}; // Then post filters
2438
-
2439
- const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
2440
- const search = replaceEqualDeep(router.location.search, postFilteredSearch);
2441
- const searchStr = router.options.stringifySearch(search);
2442
- let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
2443
- hash = hash ? "#" + hash : '';
2444
- return {
2445
- pathname,
2446
- search,
2447
- searchStr,
2448
- state: router.location.state,
2449
- hash,
2450
- href: "" + pathname + searchStr + hash,
2451
- key: dest.key
2452
- };
2453
- },
2454
- commitLocation: (next, replace) => {
2455
- const id = '' + Date.now() + Math.random();
2456
- if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
2457
- let nextAction = 'replace';
2458
-
2459
- if (!replace) {
2460
- nextAction = 'push';
2461
- }
2462
-
2463
- const isSameUrl = router.__.parseLocation(history.location).href === next.href;
2464
-
2465
- if (isSameUrl && !next.key) {
2466
- nextAction = 'replace';
2467
- }
2468
-
2469
- if (nextAction === 'replace') {
2470
- history.replace({
2471
- pathname: next.pathname,
2472
- hash: next.hash,
2473
- search: next.searchStr
2474
- }, {
2475
- id
2476
- });
2477
- } else {
2478
- history.push({
2479
- pathname: next.pathname,
2480
- hash: next.hash,
2481
- search: next.searchStr
2482
- }, {
2483
- id
2484
- });
2485
- }
2486
-
2487
- router.navigationPromise = new Promise(resolve => {
2488
- const previousNavigationResolve = router.resolveNavigation;
2489
-
2490
- router.resolveNavigation = () => {
2491
- previousNavigationResolve();
2492
- resolve();
2493
- };
2494
- });
2495
- return router.navigationPromise;
2496
- }
2833
+ });
2497
2834
  }
2498
2835
  };
2499
- router.location = router.__.parseLocation(history.location);
2500
- router.state.location = router.location;
2501
- router.update(userOptions); // Allow frameworks to hook into the router creation
2836
+ router.update(userOptions);
2502
2837
 
2838
+ // Allow frameworks to hook into the router creation
2503
2839
  router.options.createRouter == null ? void 0 : router.options.createRouter(router);
2504
2840
  return router;
2505
2841
  }
2506
-
2507
2842
  function isCtrlEvent(e) {
2508
2843
  return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2509
2844
  }
2510
-
2511
- const _excluded = ["type", "children", "target", "activeProps", "inactiveProps", "activeOptions", "disabled", "hash", "search", "params", "to", "preload", "preloadDelay", "preloadMaxAge", "replace", "style", "className", "onClick", "onFocus", "onMouseEnter", "onMouseLeave", "onTouchStart", "onTouchEnd"],
2512
- _excluded2 = ["pending", "caseSensitive", "children"],
2513
- _excluded3 = ["children", "router"];
2514
- //
2515
- const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2516
- const routerContext = /*#__PURE__*/React__namespace.createContext(null); // Detect if we're in the DOM
2517
-
2518
- const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
2519
- const useLayoutEffect = isDOM ? React__namespace.useLayoutEffect : React__namespace.useEffect;
2520
- function MatchesProvider(props) {
2521
- return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, props);
2845
+ function linkMatches(matches) {
2846
+ matches.forEach((match, index) => {
2847
+ const parent = matches[index - 1];
2848
+ if (parent) {
2849
+ match.__.setParentMatch(parent);
2850
+ } else {
2851
+ match.__.setParentMatch(undefined);
2852
+ }
2853
+ });
2522
2854
  }
2523
2855
 
2524
- const useRouterSubscription = router => {
2525
- shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
2526
- };
2856
+ function lazy(importer) {
2857
+ const lazyComp = /*#__PURE__*/React__namespace.lazy(importer);
2858
+ const finalComp = lazyComp;
2859
+ finalComp.preload = async () => {
2860
+ {
2861
+ await importer();
2862
+ }
2863
+ };
2864
+ return finalComp;
2865
+ }
2866
+ //
2527
2867
 
2528
- function createReactRouter(opts) {
2529
- const makeRouteExt = (route, router) => {
2868
+ function useLinkProps(options) {
2869
+ const router = useRouter();
2870
+ const {
2871
+ // custom props
2872
+ type,
2873
+ children,
2874
+ target,
2875
+ activeProps = () => ({
2876
+ className: 'active'
2877
+ }),
2878
+ inactiveProps = () => ({}),
2879
+ activeOptions,
2880
+ disabled,
2881
+ // fromCurrent,
2882
+ hash,
2883
+ search,
2884
+ params,
2885
+ to,
2886
+ preload,
2887
+ preloadDelay,
2888
+ preloadMaxAge,
2889
+ replace,
2890
+ // element props
2891
+ style,
2892
+ className,
2893
+ onClick,
2894
+ onFocus,
2895
+ onMouseEnter,
2896
+ onMouseLeave,
2897
+ onTouchStart,
2898
+ onTouchEnd,
2899
+ ...rest
2900
+ } = options;
2901
+ const linkInfo = router.buildLink(options);
2902
+ if (linkInfo.type === 'external') {
2903
+ const {
2904
+ href
2905
+ } = linkInfo;
2530
2906
  return {
2531
- useRoute: function useRoute(subRouteId) {
2532
- if (subRouteId === void 0) {
2533
- subRouteId = '.';
2534
- }
2535
-
2536
- const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
2537
- const resolvedRoute = router.getRoute(resolvedRouteId);
2538
- useRouterSubscription(router);
2539
- invariant(resolvedRoute, "Could not find a route for route \"" + resolvedRouteId + "\"! Did you forget to add it to your route config?");
2540
- return resolvedRoute;
2541
- },
2542
- linkProps: options => {
2543
- var _functionalUpdate, _functionalUpdate2;
2544
-
2545
- const {
2546
- // custom props
2547
- target,
2548
- activeProps = () => ({
2549
- className: 'active'
2550
- }),
2551
- inactiveProps = () => ({}),
2552
- disabled,
2553
- // element props
2554
- style,
2555
- className,
2556
- onClick,
2557
- onFocus,
2558
- onMouseEnter,
2559
- onMouseLeave
2560
- } = options,
2561
- rest = _objectWithoutPropertiesLoose(options, _excluded);
2562
-
2563
- const linkInfo = route.buildLink(options);
2564
-
2565
- if (linkInfo.type === 'external') {
2566
- const {
2567
- href
2568
- } = linkInfo;
2569
- return {
2570
- href
2571
- };
2572
- }
2573
-
2574
- const {
2575
- handleClick,
2576
- handleFocus,
2577
- handleEnter,
2578
- handleLeave,
2579
- isActive,
2580
- next
2581
- } = linkInfo;
2582
-
2583
- const composeHandlers = handlers => e => {
2584
- e.persist();
2585
- handlers.forEach(handler => {
2586
- if (handler) handler(e);
2587
- });
2588
- }; // Get the active props
2589
-
2590
-
2591
- const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps, {})) != null ? _functionalUpdate : {} : {}; // Get the inactive props
2592
-
2593
- const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
2594
- return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
2595
- href: disabled ? undefined : next.href,
2596
- onClick: composeHandlers([handleClick, onClick]),
2597
- onFocus: composeHandlers([handleFocus, onFocus]),
2598
- onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
2599
- onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
2600
- target,
2601
- style: _extends$2({}, style, resolvedActiveProps.style, resolvedInactiveProps.style),
2602
- className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined
2603
- }, disabled ? {
2604
- role: 'link',
2605
- 'aria-disabled': true
2606
- } : undefined, {
2607
- ['data-status']: isActive ? 'active' : undefined
2608
- });
2609
- },
2610
- Link: /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2611
- const linkProps = route.linkProps(props);
2612
- useRouterSubscription(router);
2613
- return /*#__PURE__*/React__namespace.createElement("a", _extends$2({
2614
- ref: ref
2615
- }, linkProps, {
2616
- children: typeof props.children === 'function' ? props.children({
2617
- isActive: linkProps['data-status'] === 'active'
2618
- }) : props.children
2619
- }));
2620
- }),
2621
- MatchRoute: opts => {
2622
- const {
2623
- pending,
2624
- caseSensitive
2625
- } = opts,
2626
- rest = _objectWithoutPropertiesLoose(opts, _excluded2);
2627
-
2628
- const params = route.matchRoute(rest, {
2629
- pending,
2630
- caseSensitive
2631
- });
2632
-
2633
- if (!params) {
2634
- return null;
2635
- }
2636
-
2637
- return typeof opts.children === 'function' ? opts.children(params) : opts.children;
2638
- }
2907
+ href
2639
2908
  };
2909
+ }
2910
+ const {
2911
+ handleClick,
2912
+ handleFocus,
2913
+ handleEnter,
2914
+ handleLeave,
2915
+ isActive,
2916
+ next
2917
+ } = linkInfo;
2918
+ const reactHandleClick = e => {
2919
+ if (React__namespace.startTransition) {
2920
+ // This is a hack for react < 18
2921
+ React__namespace.startTransition(() => {
2922
+ handleClick(e);
2923
+ });
2924
+ } else {
2925
+ handleClick(e);
2926
+ }
2927
+ };
2928
+ const composeHandlers = handlers => e => {
2929
+ if (e.persist) e.persist();
2930
+ handlers.filter(Boolean).forEach(handler => {
2931
+ if (e.defaultPrevented) return;
2932
+ handler(e);
2933
+ });
2640
2934
  };
2641
2935
 
2642
- const coreRouter = createRouter(_extends$2({}, opts, {
2643
- createRouter: router => {
2644
- const routerExt = {
2645
- useState: () => {
2646
- useRouterSubscription(router);
2647
- return router.state;
2648
- },
2649
- useMatch: routeId => {
2650
- useRouterSubscription(router);
2651
- invariant(routeId !== rootRouteId, "\"" + rootRouteId + "\" cannot be used with useMatch! Did you mean to useRoute(\"" + rootRouteId + "\")?");
2652
-
2653
- const runtimeMatch = _useMatch();
2654
-
2655
- const match = router.state.matches.find(d => d.routeId === routeId);
2656
- invariant(match, "Could not find a match for route \"" + routeId + "\" being rendered in this component!");
2657
- invariant(runtimeMatch.routeId == (match == null ? void 0 : match.routeId), "useMatch('" + (match == null ? void 0 : match.routeId) + "') is being called in a component that is meant to render the '" + runtimeMatch.routeId + "' route. Did you mean to 'useRoute(" + (match == null ? void 0 : match.routeId) + ")' instead?");
2658
-
2659
- if (!match) {
2660
- invariant('Match not found!');
2661
- }
2936
+ // Get the active props
2937
+ const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
2662
2938
 
2663
- return match;
2664
- }
2665
- };
2666
- const routeExt = makeRouteExt(router.getRoute('/'), router);
2667
- Object.assign(router, routerExt, routeExt);
2668
- },
2669
- createRoute: _ref => {
2670
- let {
2671
- router,
2672
- route
2673
- } = _ref;
2674
- const routeExt = makeRouteExt(route, router);
2675
- Object.assign(route, routeExt);
2939
+ // Get the inactive props
2940
+ const resolvedInactiveProps = isActive ? {} : functionalUpdate(inactiveProps, {}) ?? {};
2941
+ return {
2942
+ ...resolvedActiveProps,
2943
+ ...resolvedInactiveProps,
2944
+ ...rest,
2945
+ href: disabled ? undefined : next.href,
2946
+ onClick: composeHandlers([onClick, reactHandleClick]),
2947
+ onFocus: composeHandlers([onFocus, handleFocus]),
2948
+ onMouseEnter: composeHandlers([onMouseEnter, handleEnter]),
2949
+ onMouseLeave: composeHandlers([onMouseLeave, handleLeave]),
2950
+ target,
2951
+ style: {
2952
+ ...style,
2953
+ ...resolvedActiveProps.style,
2954
+ ...resolvedInactiveProps.style
2676
2955
  },
2677
- createElement: async element => {
2678
- if (typeof element === 'function') {
2679
- const res = await element(); // Support direct import() calls
2956
+ className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined,
2957
+ ...(disabled ? {
2958
+ role: 'link',
2959
+ 'aria-disabled': true
2960
+ } : undefined),
2961
+ ['data-status']: isActive ? 'active' : undefined
2962
+ };
2963
+ }
2964
+ const Link = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2965
+ const linkProps = useLinkProps(props);
2966
+ return /*#__PURE__*/React__namespace.createElement("a", _extends$1({
2967
+ ref: ref
2968
+ }, linkProps, {
2969
+ children: typeof props.children === 'function' ? props.children({
2970
+ isActive: linkProps['data-status'] === 'active'
2971
+ }) : props.children
2972
+ }));
2973
+ });
2974
+ const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2975
+ const routerContext = /*#__PURE__*/React__namespace.createContext(null);
2976
+ const EMPTY = {};
2977
+ const __useStoreValue = (seed, selector) => {
2978
+ const valueRef = React__namespace.useRef(EMPTY);
2979
+
2980
+ // If there is no selector, track the seed
2981
+ // If there is a selector, do not track the seed
2982
+ const getValue = () => !selector ? seed() : selector(untrack(() => seed()));
2983
+
2984
+ // If empty, initialize the value
2985
+ if (valueRef.current === EMPTY) {
2986
+ valueRef.current = sharedClone(undefined, getValue());
2987
+ }
2680
2988
 
2681
- if (typeof res === 'object' && res.default) {
2682
- return /*#__PURE__*/React__namespace.createElement(res.default);
2683
- } else {
2684
- return res;
2685
- }
2989
+ // Snapshot should just return the current cached value
2990
+ const getSnapshot = React__namespace.useCallback(() => valueRef.current, []);
2991
+ const getStore = React__namespace.useCallback(cb => {
2992
+ // A root is necessary to track effects
2993
+ return createRoot(() => {
2994
+ createEffect(() => {
2995
+ // Read and update the value
2996
+ // getValue will handle which values are accessed and
2997
+ // thus tracked.
2998
+ // sharedClone will both recursively track the end result
2999
+ // and ensure that the previous value is structurally shared
3000
+ // into the new version.
3001
+ valueRef.current = unwrap(
3002
+ // Unwrap the value to get rid of any proxy structures
3003
+ sharedClone(valueRef.current, getValue()));
3004
+ cb();
3005
+ });
3006
+ });
3007
+ }, []);
3008
+ return shim.useSyncExternalStore(getStore, getSnapshot, getSnapshot);
3009
+ };
3010
+ const [store, setStore] = createStore({
3011
+ foo: 'foo',
3012
+ bar: {
3013
+ baz: 'baz'
3014
+ }
3015
+ });
3016
+ createRoot(() => {
3017
+ let prev;
3018
+ createEffect(() => {
3019
+ console.log('effect');
3020
+ const next = sharedClone(prev, store);
3021
+ console.log(next);
3022
+ prev = untrack(() => next);
3023
+ });
3024
+ });
3025
+ setStore(s => {
3026
+ s.foo = '1';
3027
+ });
3028
+ setStore(s => {
3029
+ s.bar.baz = '2';
3030
+ });
3031
+ function createReactRouter(opts) {
3032
+ const coreRouter = createRouter({
3033
+ ...opts,
3034
+ loadComponent: async component => {
3035
+ if (component.preload) {
3036
+ await component.preload();
2686
3037
  }
2687
-
2688
- return element;
3038
+ return component;
2689
3039
  }
2690
- }));
3040
+ });
2691
3041
  return coreRouter;
2692
3042
  }
2693
- function RouterProvider(_ref2) {
3043
+ function RouterProvider(_ref) {
2694
3044
  let {
2695
- children,
2696
- router
2697
- } = _ref2,
2698
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
2699
-
3045
+ router,
3046
+ ...rest
3047
+ } = _ref;
2700
3048
  router.update(rest);
2701
- useRouterSubscription(router);
2702
- useLayoutEffect(() => {
2703
- return router.mount();
2704
- }, [router]);
2705
- return /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
3049
+ const [,, currentMatches] = __useStoreValue(() => router.store, s => [s.status, s.pendingMatches, s.currentMatches]);
3050
+ React__namespace.useEffect(router.mount, [router]);
3051
+ console.log('current', currentMatches);
3052
+ return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
2706
3053
  value: {
2707
- router
3054
+ router: router
2708
3055
  }
2709
- }, /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
2710
- value: router.state.matches
2711
- }, children != null ? children : /*#__PURE__*/React__namespace.createElement(Outlet, null)));
3056
+ }, /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, {
3057
+ value: [undefined, ...currentMatches]
3058
+ }, /*#__PURE__*/React__namespace.createElement(Outlet, null))));
2712
3059
  }
2713
-
2714
3060
  function useRouter() {
2715
3061
  const value = React__namespace.useContext(routerContext);
2716
3062
  warning(!value, 'useRouter must be used inside a <Router> component!');
2717
- useRouterSubscription(value.router);
2718
3063
  return value.router;
2719
3064
  }
2720
-
3065
+ function useRouterStore(selector) {
3066
+ const router = useRouter();
3067
+ return __useStoreValue(() => router.store, selector);
3068
+ }
2721
3069
  function useMatches() {
2722
3070
  return React__namespace.useContext(matchesContext);
2723
- } // function useParentMatches(): RouteMatch[] {
2724
- // const router = useRouter()
2725
- // const match = useMatch()
2726
- // const matches = router.state.matches
2727
- // return matches.slice(
2728
- // 0,
2729
- // matches.findIndex((d) => d.matchId === match.matchId) - 1,
2730
- // )
2731
- // }
2732
-
2733
-
2734
- function _useMatch() {
2735
- var _useMatches;
2736
-
2737
- return (_useMatches = useMatches()) == null ? void 0 : _useMatches[0];
2738
3071
  }
2739
-
3072
+ function useMatch(opts) {
3073
+ const router = useRouter();
3074
+ const nearestMatch = useMatches()[0];
3075
+ const match = opts != null && opts.from ? router.store.currentMatches.find(d => d.routeId === (opts == null ? void 0 : opts.from)) : nearestMatch;
3076
+ invariant(match, `Could not find ${opts != null && opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`);
3077
+ if ((opts == null ? void 0 : opts.strict) ?? true) {
3078
+ invariant(nearestMatch.routeId == (match == null ? void 0 : match.routeId), `useMatch("${match == null ? void 0 : match.routeId}") is being called in a component that is meant to render the '${nearestMatch.routeId}' route. Did you mean to 'useMatch("${match == null ? void 0 : match.routeId}", { strict: false })' or 'useRoute("${match == null ? void 0 : match.routeId}")' instead?`);
3079
+ }
3080
+ __useStoreValue(() => match.store);
3081
+ return match;
3082
+ }
3083
+ function useRoute(routeId) {
3084
+ const router = useRouter();
3085
+ const resolvedRoute = router.getRoute(routeId);
3086
+ invariant(resolvedRoute, `Could not find a route for route "${routeId}"! Did you forget to add it to your route config?`);
3087
+ return resolvedRoute;
3088
+ }
3089
+ function useLoaderData(opts) {
3090
+ const match = useMatch(opts);
3091
+ return __useStoreValue(() => match == null ? void 0 : match.store.loaderData, opts == null ? void 0 : opts.select);
3092
+ }
3093
+ function useSearch(opts) {
3094
+ const match = useMatch(opts);
3095
+ return __useStoreValue(() => match == null ? void 0 : match.store.search, opts == null ? void 0 : opts.select);
3096
+ }
3097
+ function useParams(opts) {
3098
+ const router = useRouter();
3099
+ return __useStoreValue(() => {
3100
+ var _last;
3101
+ return (_last = last(router.store.currentMatches)) == null ? void 0 : _last.params;
3102
+ }, opts == null ? void 0 : opts.select);
3103
+ }
3104
+ function useNavigate(defaultOpts) {
3105
+ return opts => {
3106
+ const router = useRouter();
3107
+ return router.navigate({
3108
+ ...defaultOpts,
3109
+ ...opts
3110
+ });
3111
+ };
3112
+ }
3113
+ function useAction(opts) {
3114
+ const route = useRoute(opts.from);
3115
+ const action = route.action;
3116
+ __useStoreValue(() => action);
3117
+ return action;
3118
+ }
3119
+ function useMatchRoute() {
3120
+ const router = useRouter();
3121
+ return opts => {
3122
+ const {
3123
+ pending,
3124
+ caseSensitive,
3125
+ ...rest
3126
+ } = opts;
3127
+ return router.matchRoute(rest, {
3128
+ pending,
3129
+ caseSensitive
3130
+ });
3131
+ };
3132
+ }
3133
+ function MatchRoute(props) {
3134
+ const matchRoute = useMatchRoute();
3135
+ const params = matchRoute(props);
3136
+ if (!params) {
3137
+ return null;
3138
+ }
3139
+ return /*#__PURE__*/React__namespace.createElement(typeof props.children === 'function' ? props.children(params) : props.children, props);
3140
+ }
2740
3141
  function Outlet() {
2741
- var _childMatch$options$c;
2742
-
2743
3142
  const router = useRouter();
2744
- const [, ...matches] = useMatches();
2745
- const childMatch = matches[0];
2746
- if (!childMatch) return null;
2747
-
2748
- const element = (() => {
2749
- var _childMatch$__$errorE, _ref4;
2750
-
2751
- if (!childMatch) {
2752
- return null;
3143
+ const matches = useMatches().slice(1);
3144
+ const match = matches[0];
3145
+ const defaultPending = React__namespace.useCallback(() => null, []);
3146
+ __useStoreValue(() => match == null ? void 0 : match.store);
3147
+ const Inner = React__namespace.useCallback(props => {
3148
+ if (props.match.store.status === 'error') {
3149
+ throw props.match.store.error;
2753
3150
  }
2754
-
2755
- const errorElement = (_childMatch$__$errorE = childMatch.__.errorElement) != null ? _childMatch$__$errorE : router.options.defaultErrorElement;
2756
-
2757
- if (childMatch.status === 'error') {
2758
- if (errorElement) {
2759
- return errorElement;
2760
- }
2761
-
2762
- if (childMatch.options.useErrorBoundary || router.options.useErrorBoundary) {
2763
- throw childMatch.error;
2764
- }
2765
-
2766
- return /*#__PURE__*/React__namespace.createElement(DefaultErrorBoundary, {
2767
- error: childMatch.error
2768
- });
3151
+ if (props.match.store.status === 'success') {
3152
+ return /*#__PURE__*/React__namespace.createElement(props.match.__.component ?? router.options.defaultComponent ?? Outlet);
2769
3153
  }
2770
-
2771
- if (childMatch.status === 'loading' || childMatch.status === 'idle') {
2772
- if (childMatch.isPending) {
2773
- var _childMatch$__$pendin;
2774
-
2775
- const pendingElement = (_childMatch$__$pendin = childMatch.__.pendingElement) != null ? _childMatch$__$pendin : router.options.defaultPendingElement;
2776
-
2777
- if (childMatch.options.pendingMs || pendingElement) {
2778
- var _ref3;
2779
-
2780
- return (_ref3 = pendingElement) != null ? _ref3 : null;
2781
- }
2782
- }
2783
-
2784
- return null;
3154
+ if (props.match.store.status === 'loading') {
3155
+ throw props.match.__.loadPromise;
2785
3156
  }
2786
-
2787
- return (_ref4 = childMatch.__.element) != null ? _ref4 : router.options.defaultElement;
2788
- })();
2789
-
2790
- const catchElement = (_childMatch$options$c = childMatch == null ? void 0 : childMatch.options.catchElement) != null ? _childMatch$options$c : router.options.defaultCatchElement;
2791
- return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
2792
- value: matches,
2793
- key: childMatch.matchId
3157
+ invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
3158
+ }, []);
3159
+ if (!match) {
3160
+ return null;
3161
+ }
3162
+ const PendingComponent = match.__.pendingComponent ?? router.options.defaultPendingComponent ?? defaultPending;
3163
+ const errorComponent = match.__.errorComponent ?? router.options.defaultErrorComponent;
3164
+ return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, {
3165
+ value: matches
3166
+ }, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
3167
+ fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, null)
2794
3168
  }, /*#__PURE__*/React__namespace.createElement(CatchBoundary, {
2795
- catchElement: catchElement
2796
- }, element));
3169
+ key: match.routeId,
3170
+ errorComponent: errorComponent,
3171
+ match: match
3172
+ }, /*#__PURE__*/React__namespace.createElement(Inner, {
3173
+ match: match
3174
+ }))));
2797
3175
  }
2798
-
2799
3176
  class CatchBoundary extends React__namespace.Component {
2800
- constructor() {
2801
- super(...arguments);
2802
- this.state = {
2803
- error: false
2804
- };
2805
-
2806
- this.reset = () => {
2807
- this.setState({
2808
- error: false,
2809
- info: false
2810
- });
2811
- };
2812
- }
2813
-
3177
+ state = {
3178
+ error: false,
3179
+ info: undefined
3180
+ };
2814
3181
  componentDidCatch(error, info) {
3182
+ console.error(`Error in route match: ${this.props.match.matchId}`);
2815
3183
  console.error(error);
2816
3184
  this.setState({
2817
3185
  error,
2818
3186
  info
2819
3187
  });
2820
3188
  }
2821
-
2822
3189
  render() {
2823
- var _this$props$catchElem;
2824
-
2825
- const catchElement = (_this$props$catchElem = this.props.catchElement) != null ? _this$props$catchElem : DefaultErrorBoundary;
3190
+ return /*#__PURE__*/React__namespace.createElement(CatchBoundaryInner, _extends$1({}, this.props, {
3191
+ errorState: this.state,
3192
+ reset: () => this.setState({})
3193
+ }));
3194
+ }
3195
+ }
2826
3196
 
2827
- if (this.state.error) {
2828
- return typeof catchElement === 'function' ? catchElement(this.state) : catchElement;
3197
+ // This is the messiest thing ever... I'm either seriously tired (likely) or
3198
+ // there has to be a better way to reset error boundaries when the
3199
+ // router's location key changes.
3200
+ function CatchBoundaryInner(props) {
3201
+ const [activeErrorState, setActiveErrorState] = React__namespace.useState(props.errorState);
3202
+ const router = useRouter();
3203
+ const errorComponent = props.errorComponent ?? DefaultErrorBoundary;
3204
+ React__namespace.useEffect(() => {
3205
+ if (activeErrorState) {
3206
+ let prevKey = router.store.currentLocation.key;
3207
+ return createRoot(() => createEffect(() => {
3208
+ if (router.store.currentLocation.key !== prevKey) {
3209
+ prevKey = router.store.currentLocation.key;
3210
+ setActiveErrorState({});
3211
+ }
3212
+ }));
2829
3213
  }
2830
-
2831
- return this.props.children;
3214
+ return;
3215
+ }, [activeErrorState]);
3216
+ React__namespace.useEffect(() => {
3217
+ if (props.errorState.error) {
3218
+ setActiveErrorState(props.errorState);
3219
+ }
3220
+ props.reset();
3221
+ }, [props.errorState.error]);
3222
+ if (props.errorState.error) {
3223
+ return /*#__PURE__*/React__namespace.createElement(errorComponent, activeErrorState);
2832
3224
  }
2833
-
3225
+ return props.children;
2834
3226
  }
2835
-
2836
- function DefaultErrorBoundary(_ref5) {
3227
+ function DefaultErrorBoundary(_ref2) {
2837
3228
  let {
2838
3229
  error
2839
- } = _ref5;
3230
+ } = _ref2;
2840
3231
  return /*#__PURE__*/React__namespace.createElement("div", {
2841
3232
  style: {
2842
3233
  padding: '.5rem',
@@ -2858,18 +3249,7 @@
2858
3249
  padding: '.5rem',
2859
3250
  color: 'red'
2860
3251
  }
2861
- }, error.message) : null)), /*#__PURE__*/React__namespace.createElement("div", {
2862
- style: {
2863
- height: '1rem'
2864
- }
2865
- }), /*#__PURE__*/React__namespace.createElement("div", {
2866
- style: {
2867
- fontSize: '.8em',
2868
- borderLeft: '3px solid rgba(127, 127, 127, 1)',
2869
- paddingLeft: '.5rem',
2870
- opacity: 0.5
2871
- }
2872
- }, "If you are the owner of this website, it's highly recommended that you configure your own custom Catch/Error boundaries for the router. You can optionally configure a boundary for each route."));
3252
+ }, error.message) : null)));
2873
3253
  }
2874
3254
  function usePrompt(message, when) {
2875
3255
  const router = useRouter();
@@ -2880,37 +3260,61 @@
2880
3260
  unblock();
2881
3261
  transition.retry();
2882
3262
  } else {
2883
- router.location.pathname = window.location.pathname;
3263
+ router.store.currentLocation.pathname = window.location.pathname;
2884
3264
  }
2885
3265
  });
2886
3266
  return unblock;
2887
- }, [when, location, message]);
3267
+ }, [when, message]);
2888
3268
  }
2889
- function Prompt(_ref6) {
3269
+ function Prompt(_ref3) {
2890
3270
  let {
2891
3271
  message,
2892
3272
  when,
2893
3273
  children
2894
- } = _ref6;
2895
- usePrompt(message, when != null ? when : true);
2896
- return children != null ? children : null;
3274
+ } = _ref3;
3275
+ usePrompt(message, when ?? true);
3276
+ return children ?? null;
2897
3277
  }
2898
3278
 
3279
+ // function circularStringify(obj: any) {
3280
+ // const seen = new Set()
3281
+
3282
+ // return (
3283
+ // JSON.stringify(obj, (_, value) => {
3284
+ // if (typeof value === 'function') {
3285
+ // return undefined
3286
+ // }
3287
+ // if (typeof value === 'object' && value !== null) {
3288
+ // if (seen.has(value)) return
3289
+ // seen.add(value)
3290
+ // }
3291
+ // return value
3292
+ // }) || ''
3293
+ // )
3294
+ // }
3295
+
2899
3296
  exports.DefaultErrorBoundary = DefaultErrorBoundary;
2900
- exports.MatchesProvider = MatchesProvider;
3297
+ exports.Link = Link;
3298
+ exports.MatchRoute = MatchRoute;
2901
3299
  exports.Outlet = Outlet;
2902
3300
  exports.Prompt = Prompt;
2903
3301
  exports.RouterProvider = RouterProvider;
2904
- exports.cascadeLoaderData = cascadeLoaderData;
3302
+ exports.__useStoreValue = __useStoreValue;
3303
+ exports.batch = batch;
2905
3304
  exports.cleanPath = cleanPath;
2906
3305
  exports.createBrowserHistory = createBrowserHistory;
3306
+ exports.createEffect = createEffect;
2907
3307
  exports.createHashHistory = createHashHistory;
3308
+ exports.createMemo = createMemo;
2908
3309
  exports.createMemoryHistory = createMemoryHistory;
2909
3310
  exports.createReactRouter = createReactRouter;
3311
+ exports.createRoot = createRoot;
2910
3312
  exports.createRoute = createRoute;
2911
3313
  exports.createRouteConfig = createRouteConfig;
2912
3314
  exports.createRouteMatch = createRouteMatch;
2913
3315
  exports.createRouter = createRouter;
3316
+ exports.createSignal = createSignal;
3317
+ exports.createStore = createStore;
2914
3318
  exports.decode = decode;
2915
3319
  exports.defaultParseSearch = defaultParseSearch;
2916
3320
  exports.defaultStringifySearch = defaultStringifySearch;
@@ -2918,20 +3322,40 @@
2918
3322
  exports.functionalUpdate = functionalUpdate;
2919
3323
  exports.interpolatePath = interpolatePath;
2920
3324
  exports.invariant = invariant;
3325
+ exports.isWrappable = isWrappable;
2921
3326
  exports.joinPaths = joinPaths;
2922
3327
  exports.last = last;
3328
+ exports.lazy = lazy;
2923
3329
  exports.matchByPath = matchByPath;
2924
3330
  exports.matchPathname = matchPathname;
3331
+ exports.matchesContext = matchesContext;
3332
+ exports.onCleanup = onCleanup;
2925
3333
  exports.parsePathname = parsePathname;
2926
3334
  exports.parseSearchWith = parseSearchWith;
2927
- exports.replaceEqualDeep = replaceEqualDeep;
3335
+ exports.pick = pick;
2928
3336
  exports.resolvePath = resolvePath;
2929
3337
  exports.rootRouteId = rootRouteId;
3338
+ exports.routerContext = routerContext;
3339
+ exports.sharedClone = sharedClone;
2930
3340
  exports.stringifySearchWith = stringifySearchWith;
2931
3341
  exports.trimPath = trimPath;
2932
3342
  exports.trimPathLeft = trimPathLeft;
2933
3343
  exports.trimPathRight = trimPathRight;
3344
+ exports.untrack = untrack;
3345
+ exports.unwrap = unwrap;
3346
+ exports.useAction = useAction;
3347
+ exports.useLinkProps = useLinkProps;
3348
+ exports.useLoaderData = useLoaderData;
3349
+ exports.useMatch = useMatch;
3350
+ exports.useMatchRoute = useMatchRoute;
3351
+ exports.useMatches = useMatches;
3352
+ exports.useNavigate = useNavigate;
3353
+ exports.useParams = useParams;
2934
3354
  exports.usePrompt = usePrompt;
3355
+ exports.useRoute = useRoute;
3356
+ exports.useRouter = useRouter;
3357
+ exports.useRouterStore = useRouterStore;
3358
+ exports.useSearch = useSearch;
2935
3359
  exports.warning = warning;
2936
3360
 
2937
3361
  Object.defineProperty(exports, '__esModule', { value: true });