@tanstack/react-router 0.0.1-beta.38 → 0.0.1-beta.39

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,8 +34,8 @@
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
41
  for (var key in source) {
@@ -46,23 +46,404 @@
46
46
  }
47
47
  return target;
48
48
  };
49
- return _extends$2.apply(this, arguments);
49
+ return _extends$1.apply(this, arguments);
50
50
  }
51
- function _objectWithoutPropertiesLoose(source, excluded) {
52
- if (source == null) return {};
53
- var target = {};
54
- var sourceKeys = Object.keys(source);
55
- var key, i;
56
- for (i = 0; i < sourceKeys.length; i++) {
57
- key = sourceKeys[i];
58
- if (excluded.indexOf(key) >= 0) continue;
59
- target[key] = source[key];
51
+
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
+ }
60
88
  }
61
- return target;
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;
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
+ }
272
+
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];
62
443
  }
63
444
 
64
- function _extends$1() {
65
- _extends$1 = Object.assign ? Object.assign.bind() : function (target) {
445
+ function _extends() {
446
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
66
447
  for (var i = 1; i < arguments.length; i++) {
67
448
  var source = arguments[i];
68
449
  for (var key in source) {
@@ -73,7 +454,7 @@
73
454
  }
74
455
  return target;
75
456
  };
76
- return _extends$1.apply(this, arguments);
457
+ return _extends.apply(this, arguments);
77
458
  }
78
459
 
79
460
  /**
@@ -217,7 +598,7 @@
217
598
 
218
599
  if (index == null) {
219
600
  index = 0;
220
- globalHistory.replaceState(_extends$1({}, globalHistory.state, {
601
+ globalHistory.replaceState(_extends({}, globalHistory.state, {
221
602
  idx: index
222
603
  }), '');
223
604
  }
@@ -232,7 +613,7 @@
232
613
  state = null;
233
614
  }
234
615
 
235
- return readOnly(_extends$1({
616
+ return readOnly(_extends({
236
617
  pathname: location.pathname,
237
618
  hash: '',
238
619
  search: ''
@@ -466,7 +847,7 @@
466
847
 
467
848
  if (index == null) {
468
849
  index = 0;
469
- globalHistory.replaceState(_extends$1({}, globalHistory.state, {
850
+ globalHistory.replaceState(_extends({}, globalHistory.state, {
470
851
  idx: index
471
852
  }), '');
472
853
  }
@@ -493,7 +874,7 @@
493
874
  state = null;
494
875
  }
495
876
 
496
- return readOnly(_extends$1({
877
+ return readOnly(_extends({
497
878
  pathname: location.pathname,
498
879
  hash: '',
499
880
  search: ''
@@ -645,7 +1026,7 @@
645
1026
  initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
646
1027
  initialIndex = _options3.initialIndex;
647
1028
  var entries = initialEntries.map(function (entry) {
648
- var location = readOnly(_extends$1({
1029
+ var location = readOnly(_extends({
649
1030
  pathname: '/',
650
1031
  search: '',
651
1032
  hash: '',
@@ -670,7 +1051,7 @@
670
1051
  state = null;
671
1052
  }
672
1053
 
673
- return readOnly(_extends$1({
1054
+ return readOnly(_extends({
674
1055
  pathname: location.pathname,
675
1056
  search: '',
676
1057
  hash: ''
@@ -888,63 +1269,6 @@
888
1269
  * @license MIT
889
1270
  */
890
1271
 
891
- /**
892
- * This function returns `a` if `b` is deeply equal.
893
- * If not, it will replace any deeply equal children of `b` with those of `a`.
894
- * This can be used for structural sharing between JSON values for example.
895
- */
896
- function replaceEqualDeep(prev, next) {
897
- if (prev === next) {
898
- return prev;
899
- }
900
- const array = Array.isArray(prev) && Array.isArray(next);
901
- if (array || isPlainObject(prev) && isPlainObject(next)) {
902
- const aSize = array ? prev.length : Object.keys(prev).length;
903
- const bItems = array ? next : Object.keys(next);
904
- const bSize = bItems.length;
905
- const copy = array ? [] : {};
906
- let equalItems = 0;
907
- for (let i = 0; i < bSize; i++) {
908
- const key = array ? i : bItems[i];
909
- copy[key] = replaceEqualDeep(prev[key], next[key]);
910
- if (copy[key] === prev[key]) {
911
- equalItems++;
912
- }
913
- }
914
- return aSize === bSize && equalItems === aSize ? prev : copy;
915
- }
916
- return next;
917
- }
918
-
919
- // Copied from: https://github.com/jonschlinkert/is-plain-object
920
- function isPlainObject(o) {
921
- if (!hasObjectPrototype(o)) {
922
- return false;
923
- }
924
-
925
- // If has modified constructor
926
- const ctor = o.constructor;
927
- if (typeof ctor === 'undefined') {
928
- return true;
929
- }
930
-
931
- // If has modified prototype
932
- const prot = ctor.prototype;
933
- if (!hasObjectPrototype(prot)) {
934
- return false;
935
- }
936
-
937
- // If constructor does not have an Object-specific method
938
- if (!prot.hasOwnProperty('isPrototypeOf')) {
939
- return false;
940
- }
941
-
942
- // Most likely a plain Object
943
- return true;
944
- }
945
- function hasObjectPrototype(o) {
946
- return Object.prototype.toString.call(o) === '[object Object]';
947
- }
948
1272
  function last(arr) {
949
1273
  return arr[arr.length - 1];
950
1274
  }
@@ -953,7 +1277,7 @@
953
1277
  if (typeof console !== 'undefined') console.warn(message);
954
1278
  try {
955
1279
  throw new Error(message);
956
- } catch (_unused) {}
1280
+ } catch {}
957
1281
  }
958
1282
  return true;
959
1283
  }
@@ -990,8 +1314,8 @@
990
1314
  return trimPathRight(trimPathLeft(path));
991
1315
  }
992
1316
  function resolvePath(basepath, base, to) {
993
- base = base.replace(new RegExp("^" + basepath), '/');
994
- to = to.replace(new RegExp("^" + basepath), '/');
1317
+ base = base.replace(new RegExp(`^${basepath}`), '/');
1318
+ to = to.replace(new RegExp(`^${basepath}`), '/');
995
1319
  let baseSegments = parsePathname(base);
996
1320
  const toSegments = parsePathname(to);
997
1321
  toSegments.forEach((toSegment, index) => {
@@ -1072,8 +1396,7 @@
1072
1396
  return '';
1073
1397
  }
1074
1398
  if (segment.type === 'param') {
1075
- var _segment$value$substr;
1076
- return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
1399
+ return params[segment.value.substring(1)] ?? '';
1077
1400
  }
1078
1401
  return segment.value;
1079
1402
  }));
@@ -1085,16 +1408,15 @@
1085
1408
  if (matchLocation.to && !pathParams) {
1086
1409
  return;
1087
1410
  }
1088
- return pathParams != null ? pathParams : {};
1411
+ return pathParams ?? {};
1089
1412
  }
1090
1413
  function matchByPath(basepath, from, matchLocation) {
1091
- var _matchLocation$to;
1092
1414
  if (!from.startsWith(basepath)) {
1093
1415
  return undefined;
1094
1416
  }
1095
1417
  from = basepath != '/' ? from.substring(basepath.length) : from;
1096
1418
  const baseSegments = parsePathname(from);
1097
- const to = "" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*');
1419
+ const to = `${matchLocation.to ?? '*'}`;
1098
1420
  const routeSegments = parsePathname(to);
1099
1421
  const params = {};
1100
1422
  let isMatch = (() => {
@@ -1195,134 +1517,136 @@
1195
1517
  return out;
1196
1518
  }
1197
1519
 
1198
- function _extends() {
1199
- _extends = Object.assign ? Object.assign.bind() : function (target) {
1200
- for (var i = 1; i < arguments.length; i++) {
1201
- var source = arguments[i];
1202
- for (var key in source) {
1203
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1204
- target[key] = source[key];
1205
- }
1206
- }
1207
- }
1208
- return target;
1209
- };
1210
- return _extends.apply(this, arguments);
1211
- }
1212
-
1213
- function createRoute(routeConfig, options, parent, router) {
1520
+ function createRoute(routeConfig, options, originalIndex, parent, router) {
1214
1521
  const {
1215
1522
  id,
1216
1523
  routeId,
1217
1524
  path: routePath,
1218
1525
  fullPath
1219
1526
  } = routeConfig;
1220
- const action = router.state.actions[id] || (() => {
1221
- router.state.actions[id] = {
1222
- submissions: [],
1223
- submit: async (submission, actionOpts) => {
1224
- var _actionOpts$invalidat;
1225
- if (!route) {
1226
- return;
1227
- }
1228
- const invalidate = (_actionOpts$invalidat = actionOpts == null ? void 0 : actionOpts.invalidate) != null ? _actionOpts$invalidat : true;
1229
- if (!(actionOpts != null && actionOpts.multi)) {
1230
- action.submissions = action.submissions.filter(d => d.isMulti);
1231
- }
1232
- const actionState = {
1233
- submittedAt: Date.now(),
1234
- status: 'pending',
1235
- submission,
1236
- isMulti: !!(actionOpts != null && actionOpts.multi)
1237
- };
1238
- action.current = actionState;
1239
- action.latest = actionState;
1240
- action.submissions.push(actionState);
1241
- router.notify();
1242
- try {
1243
- const res = await (route.options.action == null ? void 0 : route.options.action(submission));
1244
- actionState.data = res;
1245
- if (invalidate) {
1246
- router.invalidateRoute({
1247
- to: '.',
1248
- fromCurrent: true
1249
- });
1250
- await router.reload();
1251
- }
1252
- actionState.status = 'success';
1253
- return res;
1254
- } catch (err) {
1255
- console.error(err);
1256
- actionState.error = err;
1257
- actionState.status = 'error';
1258
- } finally {
1259
- router.notify();
1260
- }
1261
- }
1262
- };
1263
- return router.state.actions[id];
1264
- })();
1265
- const loader = router.state.loaders[id] || (() => {
1266
- router.state.loaders[id] = {
1267
- pending: [],
1268
- fetch: async loaderContext => {
1269
- if (!route) {
1270
- return;
1271
- }
1272
- const loaderState = {
1273
- loadedAt: Date.now(),
1274
- loaderContext
1275
- };
1276
- loader.current = loaderState;
1277
- loader.latest = loaderState;
1278
- loader.pending.push(loaderState);
1279
-
1280
- // router.state = {
1281
- // ...router.state,
1282
- // currentAction: loaderState,
1283
- // latestAction: loaderState,
1284
- // }
1285
-
1286
- router.notify();
1287
- try {
1288
- return await (route.options.loader == null ? void 0 : route.options.loader(loaderContext));
1289
- } finally {
1290
- loader.pending = loader.pending.filter(d => d !== loaderState);
1291
- // router.removeActionQueue.push({ loader, loaderState })
1292
- router.notify();
1293
- }
1294
- }
1295
- };
1296
- return router.state.loaders[id];
1297
- })();
1298
1527
  let route = {
1299
1528
  routeInfo: undefined,
1300
1529
  routeId: id,
1301
1530
  routeRouteId: routeId,
1531
+ originalIndex,
1302
1532
  routePath,
1303
1533
  fullPath,
1304
1534
  options,
1305
1535
  router,
1306
1536
  childRoutes: undefined,
1307
1537
  parentRoute: parent,
1308
- action,
1309
- loader: loader,
1310
- buildLink: options => {
1311
- return router.buildLink(_extends({}, options, {
1312
- from: fullPath
1313
- }));
1314
- },
1315
- navigate: options => {
1316
- return router.navigate(_extends({}, options, {
1317
- from: fullPath
1318
- }));
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;
1319
1591
  },
1320
- matchRoute: (matchLocation, opts) => {
1321
- return router.matchRoute(_extends({}, matchLocation, {
1322
- from: fullPath
1323
- }), 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;
1324
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
+ // },
1325
1648
  };
1649
+
1326
1650
  router.options.createRoute == null ? void 0 : router.options.createRoute({
1327
1651
  router,
1328
1652
  route
@@ -1331,7 +1655,7 @@
1331
1655
  }
1332
1656
 
1333
1657
  const rootRouteId = '__root__';
1334
- const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
1658
+ const createRouteConfig = function (options, children, isRoot, parentId, parentPath) {
1335
1659
  if (options === void 0) {
1336
1660
  options = {};
1337
1661
  }
@@ -1371,53 +1695,194 @@
1371
1695
  addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
1372
1696
  createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath),
1373
1697
  generate: () => {
1374
- invariant(false, "routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. ");
1698
+ invariant(false, `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `);
1375
1699
  }
1376
1700
  };
1377
1701
  };
1378
1702
 
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
+
1379
1809
  const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
1380
1810
  function createRouteMatch(router, route, opts) {
1381
- const routeMatch = _extends({}, route, opts, {
1382
- 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({
1383
1833
  routeSearch: {},
1384
1834
  search: {},
1385
- childMatches: [],
1386
1835
  status: 'idle',
1387
1836
  routeLoaderData: {},
1388
1837
  loaderData: {},
1389
1838
  isFetching: false,
1390
- isInvalid: false,
1839
+ invalid: false,
1391
1840
  invalidAt: Infinity,
1392
- // pendingActions: [],
1393
- getIsInvalid: () => {
1841
+ get isInvalid() {
1394
1842
  const now = Date.now();
1395
- return routeMatch.isInvalid || routeMatch.invalidAt < now;
1396
- },
1843
+ return this.invalid || this.invalidAt < now;
1844
+ }
1845
+ });
1846
+ const routeMatch = {
1847
+ ...route,
1848
+ ...opts,
1849
+ store,
1850
+ // setStore,
1851
+ router,
1852
+ childMatches: [],
1397
1853
  __: {
1398
- abortController: new AbortController(),
1399
- latestId: '',
1400
- resolve: () => {},
1401
- notify: () => {
1402
- routeMatch.__.resolve();
1403
- routeMatch.router.notify();
1854
+ setParentMatch: parentMatch => {
1855
+ batch(() => {
1856
+ setStore(s => {
1857
+ s.parentMatch = parentMatch;
1858
+ });
1859
+ updateLoaderData();
1860
+ });
1404
1861
  },
1862
+ abortController: new AbortController(),
1405
1863
  validate: () => {
1406
- var _routeMatch$parentMat, _routeMatch$parentMat2;
1864
+ var _store$parentMatch2;
1407
1865
  // Validate the search params and stabilize them
1408
- const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.state.currentLocation.search;
1866
+ const parentSearch = ((_store$parentMatch2 = store.parentMatch) == null ? void 0 : _store$parentMatch2.store.search) ?? router.store.currentLocation.search;
1409
1867
  try {
1410
- var _validator;
1411
- const prevSearch = routeMatch.routeSearch;
1868
+ const prevSearch = store.routeSearch;
1412
1869
  const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
1413
- let nextSearch = replaceEqualDeep(prevSearch, (_validator = validator == null ? void 0 : validator(parentSearch)) != null ? _validator : {});
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
+ }
1414
1876
 
1415
- // Invalidate route matches when search param stability changes
1416
- if (prevSearch !== nextSearch) {
1417
- routeMatch.isInvalid = true;
1418
- }
1419
- routeMatch.routeSearch = nextSearch;
1420
- 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
+ });
1421
1886
  componentTypes.map(async type => {
1422
1887
  const component = routeMatch.options[type];
1423
1888
  if (typeof routeMatch.__[type] !== 'function') {
@@ -1430,8 +1895,11 @@
1430
1895
  cause: err
1431
1896
  });
1432
1897
  error.code = 'INVALID_SEARCH_PARAMS';
1433
- routeMatch.status = 'error';
1434
- routeMatch.error = error;
1898
+ setStore(s => {
1899
+ s.status = 'error';
1900
+ s.error = error;
1901
+ });
1902
+
1435
1903
  // Do not proceed with loading the route
1436
1904
  return;
1437
1905
  }
@@ -1442,7 +1910,7 @@
1442
1910
  (_routeMatch$__$abortC = routeMatch.__.abortController) == null ? void 0 : _routeMatch$__$abortC.abort();
1443
1911
  },
1444
1912
  invalidate: () => {
1445
- routeMatch.isInvalid = true;
1913
+ setStore(s => s.invalid = true);
1446
1914
  },
1447
1915
  hasLoaders: () => {
1448
1916
  return !!(route.options.loader || componentTypes.some(d => {
@@ -1457,17 +1925,17 @@
1457
1925
  // If this is a preload, add it to the preload cache
1458
1926
  if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
1459
1927
  // If the match is currently active, don't preload it
1460
- if (router.state.currentMatches.find(d => d.matchId === routeMatch.matchId)) {
1928
+ if (router.store.currentMatches.find(d => d.matchId === routeMatch.matchId)) {
1461
1929
  return;
1462
1930
  }
1463
- router.matchCache[routeMatch.matchId] = {
1931
+ router.store.matchCache[routeMatch.matchId] = {
1464
1932
  gc: now + loaderOpts.gcMaxAge,
1465
1933
  match: routeMatch
1466
1934
  };
1467
1935
  }
1468
1936
 
1469
1937
  // If the match is invalid, errored or idle, trigger it to load
1470
- if (routeMatch.status === 'success' && routeMatch.getIsInvalid() || routeMatch.status === 'error' || routeMatch.status === 'idle') {
1938
+ if (store.status === 'success' && store.isInvalid || store.status === 'error' || store.status === 'idle') {
1471
1939
  const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
1472
1940
  await routeMatch.fetch({
1473
1941
  maxAge
@@ -1476,29 +1944,30 @@
1476
1944
  },
1477
1945
  fetch: async opts => {
1478
1946
  const loadId = '' + Date.now() + Math.random();
1479
- routeMatch.__.latestId = loadId;
1947
+ latestId = loadId;
1480
1948
  const checkLatest = async () => {
1481
- if (loadId !== routeMatch.__.latestId) {
1949
+ if (loadId !== latestId) {
1482
1950
  // warning(true, 'Data loader is out of date!')
1483
1951
  return new Promise(() => {});
1484
1952
  }
1485
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
+ }
1486
1961
 
1487
- // If the match was in an error state, set it
1488
- // to a loading state again. Otherwise, keep it
1489
- // as loading or resolved
1490
- if (routeMatch.status === 'idle') {
1491
- routeMatch.status = 'loading';
1492
- }
1493
-
1494
- // We started loading the route, so it's no longer invalid
1495
- routeMatch.isInvalid = false;
1496
- 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 => {
1497
1966
  // We are now fetching, even if it's in the background of a
1498
1967
  // resolved state
1499
- routeMatch.isFetching = true;
1500
- routeMatch.__.resolve = resolve;
1501
- routeMatch.__.componentsPromise = (async () => {
1968
+ setStore(s => s.isFetching = true);
1969
+ resolve = r;
1970
+ componentsPromise = (async () => {
1502
1971
  // then run all component and data loaders in parallel
1503
1972
  // For each component type, potentially load it asynchronously
1504
1973
 
@@ -1510,49 +1979,52 @@
1510
1979
  }
1511
1980
  }));
1512
1981
  })();
1513
- routeMatch.__.dataPromise = Promise.resolve().then(async () => {
1982
+ dataPromise = Promise.resolve().then(async () => {
1514
1983
  try {
1515
- var _ref, _ref2, _opts$maxAge;
1516
1984
  if (routeMatch.options.loader) {
1517
1985
  const data = await router.loadMatchData(routeMatch);
1518
1986
  await checkLatest();
1519
- routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
1987
+ setLoaderData(data);
1520
1988
  }
1521
- routeMatch.error = undefined;
1522
- routeMatch.status = 'success';
1523
- routeMatch.updatedAt = Date.now();
1524
- 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);
1525
- return routeMatch.routeLoaderData;
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;
1526
1996
  } catch (err) {
1527
1997
  await checkLatest();
1528
1998
  {
1529
1999
  console.error(err);
1530
2000
  }
1531
- routeMatch.error = err;
1532
- routeMatch.status = 'error';
1533
- routeMatch.updatedAt = Date.now();
2001
+ setStore(s => {
2002
+ s.error = err;
2003
+ s.status = 'error';
2004
+ s.updatedAt = Date.now();
2005
+ });
1534
2006
  throw err;
1535
2007
  }
1536
2008
  });
1537
2009
  const after = async () => {
1538
2010
  await checkLatest();
1539
- routeMatch.isFetching = false;
2011
+ setStore(s => s.isFetching = false);
1540
2012
  delete routeMatch.__.loadPromise;
1541
- routeMatch.__.notify();
2013
+ resolve();
1542
2014
  };
1543
2015
  try {
1544
- await Promise.all([routeMatch.__.componentsPromise, routeMatch.__.dataPromise.catch(() => {})]);
2016
+ await Promise.all([componentsPromise, dataPromise.catch(() => {})]);
1545
2017
  after();
1546
- } catch (_unused) {
2018
+ } catch {
1547
2019
  after();
1548
2020
  }
1549
2021
  });
1550
2022
  await routeMatch.__.loadPromise;
1551
2023
  await checkLatest();
1552
2024
  }
1553
- });
2025
+ };
1554
2026
  if (!routeMatch.hasLoaders()) {
1555
- routeMatch.status = 'success';
2027
+ setStore(s => s.status = 'success');
1556
2028
  }
1557
2029
  return routeMatch;
1558
2030
  }
@@ -1582,7 +2054,9 @@
1582
2054
  }
1583
2055
  function stringifySearchWith(stringify) {
1584
2056
  return search => {
1585
- search = _extends({}, search);
2057
+ search = {
2058
+ ...search
2059
+ };
1586
2060
  if (search) {
1587
2061
  Object.keys(search).forEach(key => {
1588
2062
  const val = search[key];
@@ -1598,7 +2072,7 @@
1598
2072
  });
1599
2073
  }
1600
2074
  const searchStr = encode(search).toString();
1601
- return searchStr ? "?" + searchStr : '';
2075
+ return searchStr ? `?${searchStr}` : '';
1602
2076
  };
1603
2077
  }
1604
2078
 
@@ -1617,177 +2091,277 @@
1617
2091
  actions: {},
1618
2092
  loaders: {},
1619
2093
  lastUpdated: Date.now(),
1620
- isFetching: false,
1621
- isPreloading: false
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
+ }
1622
2101
  };
1623
2102
  }
1624
2103
  function createRouter(userOptions) {
1625
- var _userOptions$stringif, _userOptions$parseSea;
1626
- const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
1627
- const originalOptions = _extends({
2104
+ const originalOptions = {
1628
2105
  defaultLoaderGcMaxAge: 5 * 60 * 1000,
1629
2106
  defaultLoaderMaxAge: 0,
1630
2107
  defaultPreloadMaxAge: 2000,
1631
2108
  defaultPreloadDelay: 50,
1632
- context: undefined
1633
- }, userOptions, {
1634
- stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
1635
- parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
1636
- });
1637
- let router = {
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 = {
1638
2232
  types: undefined,
1639
2233
  // public api
1640
- history,
2234
+ history: (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory(),
2235
+ store,
2236
+ setStore,
1641
2237
  options: originalOptions,
1642
- listeners: [],
1643
- // Resolved after construction
1644
2238
  basepath: '',
1645
2239
  routeTree: undefined,
1646
2240
  routesById: {},
1647
- //
1648
- resolveNavigation: () => {},
1649
- matchCache: {},
1650
- state: getInitialRouterState(),
1651
2241
  reset: () => {
1652
- router.state = getInitialRouterState();
1653
- router.notify();
1654
- },
1655
- startedLoadingAt: Date.now(),
1656
- subscribe: listener => {
1657
- router.listeners.push(listener);
1658
- return () => {
1659
- router.listeners = router.listeners.filter(x => x !== listener);
1660
- };
2242
+ setStore(s => Object.assign(s, getInitialRouterState()));
1661
2243
  },
1662
2244
  getRoute: id => {
1663
2245
  return router.routesById[id];
1664
2246
  },
1665
- notify: () => {
1666
- const isFetching = router.state.status === 'loading' || router.state.currentMatches.some(d => d.isFetching);
1667
- const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.currentMatches.find(dd => dd.matchId === d.match.matchId));
1668
- if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
1669
- router.state = _extends({}, router.state, {
1670
- isFetching,
1671
- isPreloading
1672
- });
1673
- }
1674
- cascadeLoaderData(router.state.currentMatches);
1675
- router.listeners.forEach(listener => listener(router));
1676
- },
1677
2247
  dehydrate: () => {
1678
2248
  return {
1679
- state: _extends({}, pick(router.state, ['latestLocation', 'currentLocation', 'status', 'lastUpdated']), {
1680
- currentMatches: router.state.currentMatches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
1681
- }),
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
+ },
1682
2256
  context: router.options.context
1683
2257
  };
1684
2258
  },
1685
- hydrate: dehydratedState => {
1686
- // Update the location
1687
- router.state.latestLocation = dehydratedState.state.latestLocation;
1688
- router.state.currentLocation = dehydratedState.state.currentLocation;
2259
+ hydrate: dehydratedRouter => {
2260
+ setStore(s => {
2261
+ // Update the context TODO: make this part of state?
2262
+ router.options.context = dehydratedRouter.context;
1689
2263
 
1690
- // Update the context
1691
- router.options.context = dehydratedState.context;
1692
-
1693
- // Match the routes
1694
- const currentMatches = router.matchRoutes(router.state.latestLocation.pathname, {
1695
- strictParseParams: true
1696
- });
1697
- currentMatches.forEach((match, index) => {
1698
- const dehydratedMatch = dehydratedState.state.currentMatches[index];
1699
- invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
1700
- Object.assign(match, dehydratedMatch);
1701
- });
1702
- currentMatches.forEach(match => match.__.validate());
1703
- router.state = _extends({}, router.state, dehydratedState, {
1704
- currentMatches
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
+ });
1705
2278
  });
1706
2279
  },
1707
2280
  mount: () => {
1708
- if (!router.state.currentMatches.length) {
1709
- router.load();
1710
- }
1711
- const unsub = router.history.listen(event => {
1712
- router.load(router.__.parseLocation(event.location, router.state.latestLocation));
1713
- });
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
+ });
1714
2290
 
1715
- // addEventListener does not exist in React Native, but window does
1716
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
1717
- if (!isServer && window.addEventListener) {
1718
- // Listen to visibillitychange and focus
1719
- window.addEventListener('visibilitychange', router.onFocus, false);
1720
- window.addEventListener('focus', router.onFocus, false);
1721
- }
1722
- return () => {
1723
- unsub();
1724
- if (!isServer && window.removeEventListener) {
1725
- // Be sure to unsubscribe if a new handler is set
1726
- window.removeEventListener('visibilitychange', router.onFocus);
1727
- window.removeEventListener('focus', router.onFocus);
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);
1728
2298
  }
1729
- };
1730
- },
1731
- onFocus: () => {
1732
- router.load();
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
+ };
2307
+ }
2308
+ return () => {};
1733
2309
  },
1734
2310
  update: opts => {
1735
- var _trimPath;
1736
2311
  const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
1737
- if (!router.state.latestLocation || newHistory) {
2312
+ if (!store.latestLocation || newHistory) {
1738
2313
  if (opts != null && opts.history) {
1739
2314
  router.history = opts.history;
1740
2315
  }
1741
- router.state.latestLocation = router.__.parseLocation(router.history.location);
1742
- router.state.currentLocation = router.state.latestLocation;
2316
+ setStore(s => {
2317
+ s.latestLocation = parseLocation(router.history.location);
2318
+ s.currentLocation = s.latestLocation;
2319
+ });
1743
2320
  }
1744
2321
  Object.assign(router.options, opts);
1745
2322
  const {
1746
2323
  basepath,
1747
2324
  routeConfig
1748
2325
  } = router.options;
1749
- router.basepath = "/" + ((_trimPath = trimPath(basepath != null ? basepath : '')) != null ? _trimPath : '');
2326
+ router.basepath = `/${trimPath(basepath ?? '') ?? ''}`;
1750
2327
  if (routeConfig) {
1751
2328
  router.routesById = {};
1752
- router.routeTree = router.__.buildRouteTree(routeConfig);
2329
+ router.routeTree = buildRouteTree(routeConfig);
1753
2330
  }
1754
2331
  return router;
1755
2332
  },
1756
2333
  cancelMatches: () => {
1757
- var _router$state$pending;
1758
- [...router.state.currentMatches, ...((_router$state$pending = router.state.pendingMatches) != null ? _router$state$pending : [])].forEach(match => {
2334
+ [...store.currentMatches, ...(store.pendingMatches || [])].forEach(match => {
1759
2335
  match.cancel();
1760
2336
  });
1761
2337
  },
1762
2338
  load: async next => {
1763
- const id = Math.random();
1764
- router.startedLoadingAt = id;
1765
- if (next) {
1766
- // Ingest the new location
1767
- router.state.latestLocation = next;
1768
- }
2339
+ let now = Date.now();
2340
+ const startedAt = now;
2341
+ startedLoadingAt = startedAt;
1769
2342
 
1770
2343
  // Cancel any pending matches
1771
2344
  router.cancelMatches();
2345
+ let matches;
2346
+ batch(() => {
2347
+ if (next) {
2348
+ // Ingest the new location
2349
+ setStore(s => {
2350
+ s.latestLocation = next;
2351
+ });
2352
+ }
1772
2353
 
1773
- // Match the routes
1774
- const matches = router.matchRoutes(router.state.latestLocation.pathname, {
1775
- strictParseParams: true
1776
- });
1777
- if (typeof document !== 'undefined') {
1778
- router.state = _extends({}, router.state, {
1779
- status: 'loading',
1780
- pendingMatches: matches,
1781
- pendingLocation: router.state.latestLocation
2354
+ // Match the routes
2355
+ matches = router.matchRoutes(store.latestLocation.pathname, {
2356
+ strictParseParams: true
1782
2357
  });
1783
- } else {
1784
- router.state = _extends({}, router.state, {
1785
- status: 'loading',
1786
- currentMatches: matches,
1787
- currentLocation: router.state.latestLocation
2358
+ console.log('set loading', matches);
2359
+ setStore(s => {
2360
+ s.status = 'loading';
2361
+ s.pendingMatches = matches;
2362
+ s.pendingLocation = store.latestLocation;
1788
2363
  });
1789
- }
1790
- router.notify();
2364
+ });
1791
2365
 
1792
2366
  // Load the matches
1793
2367
  try {
@@ -1796,11 +2370,11 @@
1796
2370
  console.log(err);
1797
2371
  invariant(false, 'Matches failed to load due to error above ☝️. Navigation cancelled!');
1798
2372
  }
1799
- if (router.startedLoadingAt !== id) {
1800
- // Ignore side-effects of match loading
1801
- return router.navigationPromise;
2373
+ if (startedLoadingAt !== startedAt) {
2374
+ // Ignore side-effects of outdated side-effects
2375
+ return navigationPromise;
1802
2376
  }
1803
- const previousMatches = router.state.currentMatches;
2377
+ const previousMatches = store.currentMatches;
1804
2378
  const exiting = [],
1805
2379
  staying = [];
1806
2380
  previousMatches.forEach(d => {
@@ -1813,22 +2387,21 @@
1813
2387
  const entering = matches.filter(d => {
1814
2388
  return !previousMatches.find(dd => dd.matchId === d.matchId);
1815
2389
  });
1816
- const now = Date.now();
2390
+ now = Date.now();
1817
2391
  exiting.forEach(d => {
1818
- var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
1819
2392
  d.__.onExit == null ? void 0 : d.__.onExit({
1820
2393
  params: d.params,
1821
- search: d.routeSearch
2394
+ search: d.store.routeSearch
1822
2395
  });
1823
2396
 
1824
2397
  // Clear idle error states when match leaves
1825
- if (d.status === 'error' && !d.isFetching) {
1826
- d.status = 'idle';
1827
- d.error = undefined;
2398
+ if (d.store.status === 'error' && !d.store.isFetching) {
2399
+ d.store.status = 'idle';
2400
+ d.store.error = undefined;
1828
2401
  }
1829
- const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
2402
+ const gc = Math.max(d.options.loaderGcMaxAge ?? router.options.defaultLoaderGcMaxAge ?? 0, d.options.loaderMaxAge ?? router.options.defaultLoaderMaxAge ?? 0);
1830
2403
  if (gc > 0) {
1831
- router.matchCache[d.matchId] = {
2404
+ store.matchCache[d.matchId] = {
1832
2405
  gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
1833
2406
  match: d
1834
2407
  };
@@ -1837,59 +2410,64 @@
1837
2410
  staying.forEach(d => {
1838
2411
  d.options.onTransition == null ? void 0 : d.options.onTransition({
1839
2412
  params: d.params,
1840
- search: d.routeSearch
2413
+ search: d.store.routeSearch
1841
2414
  });
1842
2415
  });
1843
2416
  entering.forEach(d => {
1844
2417
  d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
1845
2418
  params: d.params,
1846
- search: d.search
2419
+ search: d.store.search
1847
2420
  });
1848
- delete router.matchCache[d.matchId];
2421
+ delete store.matchCache[d.matchId];
1849
2422
  });
1850
- if (router.startedLoadingAt !== id) {
2423
+ if (startedLoadingAt !== startedAt) {
1851
2424
  // Ignore side-effects of match loading
1852
2425
  return;
1853
2426
  }
1854
2427
  matches.forEach(match => {
1855
2428
  // Clear actions
1856
2429
  if (match.action) {
2430
+ // TODO: Check reactivity here
1857
2431
  match.action.current = undefined;
1858
2432
  match.action.submissions = [];
1859
2433
  }
1860
2434
  });
1861
- router.state = _extends({}, router.state, {
1862
- status: 'idle',
1863
- currentLocation: router.state.latestLocation,
1864
- currentMatches: matches,
1865
- pendingLocation: undefined,
1866
- pendingMatches: undefined
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
+ });
1867
2444
  });
1868
- router.notify();
1869
- router.resolveNavigation();
2445
+ resolveNavigation();
1870
2446
  },
1871
2447
  cleanMatchCache: () => {
1872
2448
  const now = Date.now();
1873
- Object.keys(router.matchCache).forEach(matchId => {
1874
- const entry = router.matchCache[matchId];
2449
+ setStore(s => {
2450
+ Object.keys(s.matchCache).forEach(matchId => {
2451
+ const entry = s.matchCache[matchId];
1875
2452
 
1876
- // Don't remove loading matches
1877
- if (entry.match.status === 'loading') {
1878
- return;
1879
- }
2453
+ // Don't remove loading matches
2454
+ if (entry.match.store.status === 'loading') {
2455
+ return;
2456
+ }
1880
2457
 
1881
- // Do not remove successful matches that are still valid
1882
- if (entry.gc > 0 && entry.gc > now) {
1883
- return;
1884
- }
2458
+ // Do not remove successful matches that are still valid
2459
+ if (entry.gc > 0 && entry.gc > now) {
2460
+ return;
2461
+ }
1885
2462
 
1886
- // Everything else gets removed
1887
- delete router.matchCache[matchId];
2463
+ // Everything else gets removed
2464
+ delete s.matchCache[matchId];
2465
+ });
1888
2466
  });
1889
2467
  },
1890
- loadRoute: async function loadRoute(navigateOpts) {
2468
+ loadRoute: async function (navigateOpts) {
1891
2469
  if (navigateOpts === void 0) {
1892
- navigateOpts = router.state.latestLocation;
2470
+ navigateOpts = store.latestLocation;
1893
2471
  }
1894
2472
  const next = router.buildNext(navigateOpts);
1895
2473
  const matches = router.matchRoutes(next.pathname, {
@@ -1898,10 +2476,9 @@
1898
2476
  await router.loadMatches(matches);
1899
2477
  return matches;
1900
2478
  },
1901
- preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
1902
- var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
2479
+ preloadRoute: async function (navigateOpts, loaderOpts) {
1903
2480
  if (navigateOpts === void 0) {
1904
- navigateOpts = router.state.latestLocation;
2481
+ navigateOpts = store.latestLocation;
1905
2482
  }
1906
2483
  const next = router.buildNext(navigateOpts);
1907
2484
  const matches = router.matchRoutes(next.pathname, {
@@ -1909,28 +2486,27 @@
1909
2486
  });
1910
2487
  await router.loadMatches(matches, {
1911
2488
  preload: true,
1912
- maxAge: (_ref3 = (_ref4 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref4 : router.options.defaultLoaderMaxAge) != null ? _ref3 : 0,
1913
- gcMaxAge: (_ref5 = (_ref6 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref6 : router.options.defaultLoaderGcMaxAge) != null ? _ref5 : 0
2489
+ maxAge: loaderOpts.maxAge ?? router.options.defaultPreloadMaxAge ?? router.options.defaultLoaderMaxAge ?? 0,
2490
+ gcMaxAge: loaderOpts.gcMaxAge ?? router.options.defaultPreloadGcMaxAge ?? router.options.defaultLoaderGcMaxAge ?? 0
1914
2491
  });
1915
2492
  return matches;
1916
2493
  },
1917
2494
  matchRoutes: (pathname, opts) => {
1918
- var _router$state$pending2;
1919
2495
  router.cleanMatchCache();
1920
2496
  const matches = [];
1921
2497
  if (!router.routeTree) {
1922
2498
  return matches;
1923
2499
  }
1924
- const existingMatches = [...router.state.currentMatches, ...((_router$state$pending2 = router.state.pendingMatches) != null ? _router$state$pending2 : [])];
2500
+ const existingMatches = [...store.currentMatches, ...(store.pendingMatches ?? [])];
1925
2501
  const recurse = async routes => {
1926
- var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
2502
+ var _foundRoute$childRout;
1927
2503
  const parentMatch = last(matches);
1928
- let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
1929
- 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;
1930
2506
  let foundRoutes = [];
1931
2507
  const findMatchInRoutes = (parentRoutes, routes) => {
1932
2508
  routes.some(route => {
1933
- var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
2509
+ var _route$childRoutes, _route$childRoutes2;
1934
2510
  if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
1935
2511
  return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
1936
2512
  }
@@ -1938,28 +2514,21 @@
1938
2514
  const matchParams = matchPathname(router.basepath, pathname, {
1939
2515
  to: route.fullPath,
1940
2516
  fuzzy,
1941
- caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
2517
+ caseSensitive: route.options.caseSensitive ?? router.options.caseSensitive
1942
2518
  });
1943
-
1944
- // console.log(
1945
- // router.basepath,
1946
- // route.fullPath,
1947
- // fuzzy,
1948
- // pathname,
1949
- // matchParams,
1950
- // )
1951
-
1952
2519
  if (matchParams) {
1953
2520
  let parsedParams;
1954
2521
  try {
1955
- var _route$options$parseP;
1956
- 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;
1957
2523
  } catch (err) {
1958
2524
  if (opts != null && opts.strictParseParams) {
1959
2525
  throw err;
1960
2526
  }
1961
2527
  }
1962
- params = _extends({}, params, parsedParams);
2528
+ params = {
2529
+ ...params,
2530
+ ...parsedParams
2531
+ };
1963
2532
  }
1964
2533
  if (!!matchParams) {
1965
2534
  foundRoutes = [...parentRoutes, route];
@@ -1973,10 +2542,10 @@
1973
2542
  return;
1974
2543
  }
1975
2544
  foundRoutes.forEach(foundRoute => {
1976
- var _router$matchCache$ma;
2545
+ var _store$matchCache$mat;
1977
2546
  const interpolatedPath = interpolatePath(foundRoute.routePath, params);
1978
2547
  const matchId = interpolatePath(foundRoute.routeId, params, true);
1979
- 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, {
1980
2549
  parentMatch,
1981
2550
  matchId,
1982
2551
  params,
@@ -1990,7 +2559,7 @@
1990
2559
  }
1991
2560
  };
1992
2561
  recurse([router.routeTree]);
1993
- cascadeLoaderData(matches);
2562
+ linkMatches(matches);
1994
2563
  return matches;
1995
2564
  },
1996
2565
  loadMatches: async (resolvedMatches, loaderOpts) => {
@@ -2015,32 +2584,31 @@
2015
2584
  }));
2016
2585
  const matchPromises = resolvedMatches.map(async match => {
2017
2586
  var _search$__data;
2018
- const search = match.search;
2587
+ const search = match.store.search;
2019
2588
  if ((_search$__data = search.__data) != null && _search$__data.matchId && search.__data.matchId !== match.matchId) {
2020
2589
  return;
2021
2590
  }
2022
2591
  match.load(loaderOpts);
2023
- if (match.status !== 'success' && match.__.loadPromise) {
2592
+ if (match.store.status !== 'success' && match.__.loadPromise) {
2024
2593
  // Wait for the first sign of activity from the match
2025
2594
  await match.__.loadPromise;
2026
2595
  }
2027
2596
  });
2028
- router.notify();
2029
2597
  await Promise.all(matchPromises);
2030
2598
  },
2031
2599
  loadMatchData: async routeMatch => {
2032
2600
  if (isServer || !router.options.useServerData) {
2033
- var _await$routeMatch$opt;
2034
- return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
2601
+ return (await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
2035
2602
  // parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
2036
2603
  params: routeMatch.params,
2037
- search: routeMatch.routeSearch,
2604
+ search: routeMatch.store.routeSearch,
2038
2605
  signal: routeMatch.__.abortController.signal
2039
- }))) != null ? _await$routeMatch$opt : {};
2606
+ }))) || {};
2040
2607
  } else {
2041
2608
  const next = router.buildNext({
2042
2609
  to: '.',
2043
- search: d => _extends({}, d != null ? d : {}, {
2610
+ search: d => ({
2611
+ ...(d ?? {}),
2044
2612
  __data: {
2045
2613
  matchId: routeMatch.matchId
2046
2614
  }
@@ -2069,16 +2637,15 @@
2069
2637
  }
2070
2638
  },
2071
2639
  invalidateRoute: opts => {
2072
- var _router$state$pending3;
2073
2640
  const next = router.buildNext(opts);
2074
2641
  const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
2075
- [...router.state.currentMatches, ...((_router$state$pending3 = router.state.pendingMatches) != null ? _router$state$pending3 : [])].forEach(match => {
2642
+ [...store.currentMatches, ...(store.pendingMatches ?? [])].forEach(match => {
2076
2643
  if (unloadedMatchIds.includes(match.matchId)) {
2077
2644
  match.invalidate();
2078
2645
  }
2079
2646
  });
2080
2647
  },
2081
- reload: () => router.__.navigate({
2648
+ reload: () => navigate({
2082
2649
  fromCurrent: true,
2083
2650
  replace: true,
2084
2651
  search: true
@@ -2087,26 +2654,28 @@
2087
2654
  return resolvePath(router.basepath, from, cleanPath(path));
2088
2655
  },
2089
2656
  matchRoute: (location, opts) => {
2090
- var _location$from;
2091
2657
  // const location = router.buildNext(opts)
2092
2658
 
2093
- location = _extends({}, location, {
2094
- to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
2095
- });
2659
+ location = {
2660
+ ...location,
2661
+ to: location.to ? router.resolvePath(location.from ?? '', location.to) : undefined
2662
+ };
2096
2663
  const next = router.buildNext(location);
2097
2664
  if (opts != null && opts.pending) {
2098
- if (!router.state.pendingLocation) {
2665
+ if (!store.pendingLocation) {
2099
2666
  return false;
2100
2667
  }
2101
- return !!matchPathname(router.basepath, router.state.pendingLocation.pathname, _extends({}, opts, {
2668
+ return !!matchPathname(router.basepath, store.pendingLocation.pathname, {
2669
+ ...opts,
2102
2670
  to: next.pathname
2103
- }));
2671
+ });
2104
2672
  }
2105
- return !!matchPathname(router.basepath, router.state.currentLocation.pathname, _extends({}, opts, {
2673
+ return matchPathname(router.basepath, store.currentLocation.pathname, {
2674
+ ...opts,
2106
2675
  to: next.pathname
2107
- }));
2676
+ });
2108
2677
  },
2109
- navigate: async _ref7 => {
2678
+ navigate: async _ref => {
2110
2679
  let {
2111
2680
  from,
2112
2681
  to = '.',
@@ -2114,7 +2683,7 @@
2114
2683
  hash,
2115
2684
  replace,
2116
2685
  params
2117
- } = _ref7;
2686
+ } = _ref;
2118
2687
  // If this link simply reloads the current route,
2119
2688
  // make sure it has a new key so it will trigger a data refresh
2120
2689
 
@@ -2124,11 +2693,11 @@
2124
2693
  const fromString = String(from);
2125
2694
  let isExternal;
2126
2695
  try {
2127
- new URL("" + toString);
2696
+ new URL(`${toString}`);
2128
2697
  isExternal = true;
2129
2698
  } catch (e) {}
2130
2699
  invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
2131
- return router.__.navigate({
2700
+ return navigate({
2132
2701
  from: fromString,
2133
2702
  to: toString,
2134
2703
  search,
@@ -2137,8 +2706,7 @@
2137
2706
  params
2138
2707
  });
2139
2708
  },
2140
- buildLink: _ref8 => {
2141
- var _preload, _ref9;
2709
+ buildLink: _ref2 => {
2142
2710
  let {
2143
2711
  from,
2144
2712
  to = '.',
@@ -2153,7 +2721,7 @@
2153
2721
  preloadGcMaxAge: userPreloadGcMaxAge,
2154
2722
  preloadDelay: userPreloadDelay,
2155
2723
  disabled
2156
- } = _ref8;
2724
+ } = _ref2;
2157
2725
  // If this link simply reloads the current route,
2158
2726
  // make sure it has a new key so it will trigger a data refresh
2159
2727
 
@@ -2161,7 +2729,7 @@
2161
2729
  // null for LinkUtils
2162
2730
 
2163
2731
  try {
2164
- new URL("" + to);
2732
+ new URL(`${to}`);
2165
2733
  return {
2166
2734
  type: 'external',
2167
2735
  href: to
@@ -2176,15 +2744,15 @@
2176
2744
  replace
2177
2745
  };
2178
2746
  const next = router.buildNext(nextOpts);
2179
- preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
2180
- const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
2747
+ preload = preload ?? router.options.defaultPreload;
2748
+ const preloadDelay = userPreloadDelay ?? router.options.defaultPreloadDelay ?? 0;
2181
2749
 
2182
2750
  // Compare path/hash for matches
2183
- const pathIsEqual = router.state.currentLocation.pathname === next.pathname;
2184
- const currentPathSplit = router.state.currentLocation.pathname.split('/');
2751
+ const pathIsEqual = store.currentLocation.pathname === next.pathname;
2752
+ const currentPathSplit = store.currentLocation.pathname.split('/');
2185
2753
  const nextPathSplit = next.pathname.split('/');
2186
2754
  const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
2187
- const hashIsEqual = router.state.currentLocation.hash === next.hash;
2755
+ const hashIsEqual = store.currentLocation.hash === next.hash;
2188
2756
  // Combine the matches based on user options
2189
2757
  const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
2190
2758
  const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
@@ -2200,8 +2768,8 @@
2200
2768
  router.invalidateRoute(nextOpts);
2201
2769
  }
2202
2770
 
2203
- // All is well? Navigate!)
2204
- router.__.navigate(nextOpts);
2771
+ // All is well? Navigate!
2772
+ navigate(nextOpts);
2205
2773
  }
2206
2774
  };
2207
2775
 
@@ -2254,143 +2822,15 @@
2254
2822
  };
2255
2823
  },
2256
2824
  buildNext: opts => {
2257
- const next = router.__.buildLocation(opts);
2825
+ const next = buildLocation(opts);
2258
2826
  const matches = router.matchRoutes(next.pathname);
2259
- const __preSearchFilters = matches.map(match => {
2260
- var _match$options$preSea;
2261
- return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
2262
- }).flat().filter(Boolean);
2263
- const __postSearchFilters = matches.map(match => {
2264
- var _match$options$postSe;
2265
- return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
2266
- }).flat().filter(Boolean);
2267
- 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,
2268
2831
  __preSearchFilters,
2269
2832
  __postSearchFilters
2270
- }));
2271
- },
2272
- __: {
2273
- buildRouteTree: rootRouteConfig => {
2274
- const recurseRoutes = (routeConfigs, parent) => {
2275
- return routeConfigs.map(routeConfig => {
2276
- const routeOptions = routeConfig.options;
2277
- const route = createRoute(routeConfig, routeOptions, parent, router);
2278
- const existingRoute = router.routesById[route.routeId];
2279
- if (existingRoute) {
2280
- {
2281
- console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
2282
- }
2283
- throw new Error();
2284
- }
2285
- router.routesById[route.routeId] = route;
2286
- const children = routeConfig.children;
2287
- route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
2288
- return route;
2289
- });
2290
- };
2291
- const routes = recurseRoutes([rootRouteConfig]);
2292
- return routes[0];
2293
- },
2294
- parseLocation: (location, previousLocation) => {
2295
- var _location$hash$split$;
2296
- const parsedSearch = router.options.parseSearch(location.search);
2297
- return {
2298
- pathname: location.pathname,
2299
- searchStr: location.search,
2300
- search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
2301
- hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
2302
- href: "" + location.pathname + location.search + location.hash,
2303
- state: location.state,
2304
- key: location.key
2305
- };
2306
- },
2307
- navigate: location => {
2308
- const next = router.buildNext(location);
2309
- return router.__.commitLocation(next, location.replace);
2310
- },
2311
- buildLocation: function buildLocation(dest) {
2312
- var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
2313
- if (dest === void 0) {
2314
- dest = {};
2315
- }
2316
- const fromPathname = dest.fromCurrent ? router.state.latestLocation.pathname : (_dest$from = dest.from) != null ? _dest$from : router.state.latestLocation.pathname;
2317
- let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
2318
- const fromMatches = router.matchRoutes(router.state.latestLocation.pathname, {
2319
- strictParseParams: true
2320
- });
2321
- const toMatches = router.matchRoutes(pathname);
2322
- const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
2323
- let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
2324
- if (nextParams) {
2325
- toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
2326
- Object.assign({}, nextParams, fn(nextParams));
2327
- });
2328
- }
2329
- pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
2330
-
2331
- // Pre filters first
2332
- const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.state.latestLocation.search) : router.state.latestLocation.search;
2333
-
2334
- // Then the link/navigate function
2335
- const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
2336
- : dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
2337
- : (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
2338
- : {};
2339
-
2340
- // Then post filters
2341
- const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
2342
- const search = replaceEqualDeep(router.state.latestLocation.search, postFilteredSearch);
2343
- const searchStr = router.options.stringifySearch(search);
2344
- let hash = dest.hash === true ? router.state.latestLocation.hash : functionalUpdate(dest.hash, router.state.latestLocation.hash);
2345
- hash = hash ? "#" + hash : '';
2346
- return {
2347
- pathname,
2348
- search,
2349
- searchStr,
2350
- state: router.state.latestLocation.state,
2351
- hash,
2352
- href: "" + pathname + searchStr + hash,
2353
- key: dest.key
2354
- };
2355
- },
2356
- commitLocation: (next, replace) => {
2357
- const id = '' + Date.now() + Math.random();
2358
- if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
2359
- let nextAction = 'replace';
2360
- if (!replace) {
2361
- nextAction = 'push';
2362
- }
2363
- const isSameUrl = router.__.parseLocation(history.location).href === next.href;
2364
- if (isSameUrl && !next.key) {
2365
- nextAction = 'replace';
2366
- }
2367
- if (nextAction === 'replace') {
2368
- history.replace({
2369
- pathname: next.pathname,
2370
- hash: next.hash,
2371
- search: next.searchStr
2372
- }, _extends({
2373
- id
2374
- }, next.state));
2375
- } else {
2376
- history.push({
2377
- pathname: next.pathname,
2378
- hash: next.hash,
2379
- search: next.searchStr
2380
- }, {
2381
- id
2382
- });
2383
- }
2384
- router.navigationPromise = new Promise(resolve => {
2385
- const previousNavigationResolve = router.resolveNavigation;
2386
- router.resolveNavigation = () => {
2387
- previousNavigationResolve();
2388
- resolve();
2389
- delete router.navigationPromise;
2390
- };
2391
- });
2392
- return router.navigationPromise;
2393
- }
2833
+ });
2394
2834
  }
2395
2835
  };
2396
2836
  router.update(userOptions);
@@ -2402,276 +2842,326 @@
2402
2842
  function isCtrlEvent(e) {
2403
2843
  return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
2404
2844
  }
2405
- function cascadeLoaderData(matches) {
2845
+ function linkMatches(matches) {
2406
2846
  matches.forEach((match, index) => {
2407
2847
  const parent = matches[index - 1];
2408
2848
  if (parent) {
2409
- match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
2849
+ match.__.setParentMatch(parent);
2850
+ } else {
2851
+ match.__.setParentMatch(undefined);
2410
2852
  }
2411
2853
  });
2412
2854
  }
2413
2855
 
2414
- 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"],
2415
- _excluded2 = ["pending", "caseSensitive", "children"],
2416
- _excluded3 = ["router"];
2417
2856
  function lazy(importer) {
2418
2857
  const lazyComp = /*#__PURE__*/React__namespace.lazy(importer);
2419
- let promise;
2420
- let resolvedComp;
2421
- const forwardedComp = /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2422
- const resolvedCompRef = React__namespace.useRef(resolvedComp || lazyComp);
2423
- return /*#__PURE__*/React__namespace.createElement(resolvedCompRef.current, _extends$2({}, ref ? {
2424
- ref
2425
- } : {}, props));
2426
- });
2427
- const finalComp = forwardedComp;
2428
- finalComp.preload = () => {
2429
- if (!promise) {
2430
- promise = importer().then(module => {
2431
- resolvedComp = module.default;
2432
- return resolvedComp;
2433
- });
2858
+ const finalComp = lazyComp;
2859
+ finalComp.preload = async () => {
2860
+ {
2861
+ await importer();
2434
2862
  }
2435
- return promise;
2436
2863
  };
2437
2864
  return finalComp;
2438
2865
  }
2439
2866
  //
2440
2867
 
2441
- function Link(props) {
2868
+ function useLinkProps(options) {
2442
2869
  const router = useRouter();
2443
- return /*#__PURE__*/React__namespace.createElement(router.Link, props);
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;
2906
+ return {
2907
+ href
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
+ });
2934
+ };
2935
+
2936
+ // Get the active props
2937
+ const resolvedActiveProps = isActive ? functionalUpdate(activeProps, {}) ?? {} : {};
2938
+
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
2955
+ },
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
+ };
2444
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
+ });
2445
2974
  const matchesContext = /*#__PURE__*/React__namespace.createContext(null);
2446
2975
  const routerContext = /*#__PURE__*/React__namespace.createContext(null);
2447
- function MatchesProvider(props) {
2448
- return /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, props);
2449
- }
2450
- const useRouterSubscription = router => {
2451
- shim.useSyncExternalStore(cb => router.subscribe(() => cb()), () => router.state, () => router.state);
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
+ }
2988
+
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);
2452
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
+ });
2453
3031
  function createReactRouter(opts) {
2454
- const makeRouteExt = (route, router) => {
2455
- return {
2456
- useRoute: function useRoute(subRouteId) {
2457
- if (subRouteId === void 0) {
2458
- subRouteId = '.';
2459
- }
2460
- const resolvedRouteId = router.resolvePath(route.routeId, subRouteId);
2461
- const resolvedRoute = router.getRoute(resolvedRouteId);
2462
- useRouterSubscription(router);
2463
- invariant(resolvedRoute, "Could not find a route for route \"" + resolvedRouteId + "\"! Did you forget to add it to your route config?");
2464
- return resolvedRoute;
2465
- },
2466
- linkProps: options => {
2467
- var _functionalUpdate, _functionalUpdate2;
2468
- const {
2469
- // custom props
2470
-
2471
- target,
2472
- activeProps = () => ({
2473
- className: 'active'
2474
- }),
2475
- inactiveProps = () => ({}),
2476
- disabled,
2477
- // element props
2478
- style,
2479
- className,
2480
- onClick,
2481
- onFocus,
2482
- onMouseEnter,
2483
- onMouseLeave
2484
- } = options,
2485
- rest = _objectWithoutPropertiesLoose(options, _excluded);
2486
- const linkInfo = route.buildLink(options);
2487
- if (linkInfo.type === 'external') {
2488
- const {
2489
- href
2490
- } = linkInfo;
2491
- return {
2492
- href
2493
- };
2494
- }
2495
- const {
2496
- handleClick,
2497
- handleFocus,
2498
- handleEnter,
2499
- handleLeave,
2500
- isActive,
2501
- next
2502
- } = linkInfo;
2503
- const reactHandleClick = e => {
2504
- if (React__namespace.startTransition)
2505
- // This is a hack for react < 18
2506
- React__namespace.startTransition(() => {
2507
- handleClick(e);
2508
- });else handleClick(e);
2509
- };
2510
- const composeHandlers = handlers => e => {
2511
- if (e.persist) e.persist();
2512
- handlers.forEach(handler => {
2513
- if (e.defaultPrevented) return;
2514
- if (handler) handler(e);
2515
- });
2516
- };
2517
-
2518
- // Get the active props
2519
- const resolvedActiveProps = isActive ? (_functionalUpdate = functionalUpdate(activeProps, {})) != null ? _functionalUpdate : {} : {};
2520
-
2521
- // Get the inactive props
2522
- const resolvedInactiveProps = isActive ? {} : (_functionalUpdate2 = functionalUpdate(inactiveProps, {})) != null ? _functionalUpdate2 : {};
2523
- return _extends$2({}, resolvedActiveProps, resolvedInactiveProps, rest, {
2524
- href: disabled ? undefined : next.href,
2525
- onClick: composeHandlers([reactHandleClick, onClick]),
2526
- onFocus: composeHandlers([handleFocus, onFocus]),
2527
- onMouseEnter: composeHandlers([handleEnter, onMouseEnter]),
2528
- onMouseLeave: composeHandlers([handleLeave, onMouseLeave]),
2529
- target,
2530
- style: _extends$2({}, style, resolvedActiveProps.style, resolvedInactiveProps.style),
2531
- className: [className, resolvedActiveProps.className, resolvedInactiveProps.className].filter(Boolean).join(' ') || undefined
2532
- }, disabled ? {
2533
- role: 'link',
2534
- 'aria-disabled': true
2535
- } : undefined, {
2536
- ['data-status']: isActive ? 'active' : undefined
2537
- });
2538
- },
2539
- Link: /*#__PURE__*/React__namespace.forwardRef((props, ref) => {
2540
- const linkProps = route.linkProps(props);
2541
- useRouterSubscription(router);
2542
- return /*#__PURE__*/React__namespace.createElement("a", _extends$2({
2543
- ref: ref
2544
- }, linkProps, {
2545
- children: typeof props.children === 'function' ? props.children({
2546
- isActive: linkProps['data-status'] === 'active'
2547
- }) : props.children
2548
- }));
2549
- }),
2550
- MatchRoute: opts => {
2551
- const {
2552
- pending,
2553
- caseSensitive
2554
- } = opts,
2555
- rest = _objectWithoutPropertiesLoose(opts, _excluded2);
2556
- const params = route.matchRoute(rest, {
2557
- pending,
2558
- caseSensitive
2559
- });
2560
- if (!params) {
2561
- return null;
2562
- }
2563
- return typeof opts.children === 'function' ? opts.children(params) : opts.children;
2564
- }
2565
- };
2566
- };
2567
- const coreRouter = createRouter(_extends$2({}, opts, {
2568
- createRouter: router => {
2569
- const routerExt = {
2570
- useState: () => {
2571
- useRouterSubscription(router);
2572
- return router.state;
2573
- },
2574
- useMatch: (routeId, opts) => {
2575
- var _opts$strict;
2576
- useRouterSubscription(router);
2577
- const nearestMatch = useNearestMatch();
2578
- const match = router.state.currentMatches.find(d => d.routeId === routeId);
2579
- if ((_opts$strict = opts == null ? void 0 : opts.strict) != null ? _opts$strict : true) {
2580
- invariant(match, "Could not find an active match for \"" + routeId + "\"!");
2581
- 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?");
2582
- }
2583
- return match;
2584
- }
2585
- };
2586
- const routeExt = makeRouteExt(router.getRoute(rootRouteId), router);
2587
- Object.assign(router, routerExt, routeExt);
2588
- },
2589
- createRoute: _ref => {
2590
- let {
2591
- router,
2592
- route
2593
- } = _ref;
2594
- const routeExt = makeRouteExt(route, router);
2595
- Object.assign(route, routeExt);
2596
- },
3032
+ const coreRouter = createRouter({
3033
+ ...opts,
2597
3034
  loadComponent: async component => {
2598
- if (component.preload && typeof document !== 'undefined') {
2599
- component.preload();
2600
- // return await component.preload()
3035
+ if (component.preload) {
3036
+ await component.preload();
2601
3037
  }
2602
-
2603
3038
  return component;
2604
3039
  }
2605
- }));
3040
+ });
2606
3041
  return coreRouter;
2607
3042
  }
2608
- function RouterProvider(_ref2) {
3043
+ function RouterProvider(_ref) {
2609
3044
  let {
2610
- router
2611
- } = _ref2,
2612
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded3);
3045
+ router,
3046
+ ...rest
3047
+ } = _ref;
2613
3048
  router.update(rest);
2614
- useRouterSubscription(router);
2615
- React__namespace.useEffect(() => {
2616
- return router.mount();
2617
- }, [router]);
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);
2618
3052
  return /*#__PURE__*/React__namespace.createElement(React__namespace.Fragment, null, /*#__PURE__*/React__namespace.createElement(routerContext.Provider, {
2619
3053
  value: {
2620
3054
  router: router
2621
3055
  }
2622
- }, /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
2623
- value: [undefined, ...router.state.currentMatches]
3056
+ }, /*#__PURE__*/React__namespace.createElement(matchesContext.Provider, {
3057
+ value: [undefined, ...currentMatches]
2624
3058
  }, /*#__PURE__*/React__namespace.createElement(Outlet, null))));
2625
3059
  }
2626
3060
  function useRouter() {
2627
3061
  const value = React__namespace.useContext(routerContext);
2628
3062
  warning(!value, 'useRouter must be used inside a <Router> component!');
2629
- useRouterSubscription(value.router);
2630
3063
  return value.router;
2631
3064
  }
3065
+ function useRouterStore(selector) {
3066
+ const router = useRouter();
3067
+ return __useStoreValue(() => router.store, selector);
3068
+ }
2632
3069
  function useMatches() {
2633
3070
  return React__namespace.useContext(matchesContext);
2634
3071
  }
2635
- function useMatch(routeId, opts) {
3072
+ function useMatch(opts) {
2636
3073
  const router = useRouter();
2637
- return router.useMatch(routeId, opts);
2638
- }
2639
- function useNearestMatch() {
2640
- const runtimeMatch = useMatches()[0];
2641
- invariant(runtimeMatch, "Could not find a nearest match!");
2642
- return runtimeMatch;
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;
2643
3082
  }
2644
3083
  function useRoute(routeId) {
2645
3084
  const router = useRouter();
2646
- return router.useRoute(routeId);
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);
2647
3092
  }
2648
- function useSearch() {
2649
- return useRouter().state.currentLocation.search;
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);
2650
3096
  }
2651
- function useParams() {
2652
- var _last;
2653
- return (_last = last(useRouter().state.currentMatches)) == null ? void 0 : _last.params;
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;
2654
3118
  }
2655
- function linkProps(props) {
3119
+ function useMatchRoute() {
2656
3120
  const router = useRouter();
2657
- return router.linkProps(props);
3121
+ return opts => {
3122
+ const {
3123
+ pending,
3124
+ caseSensitive,
3125
+ ...rest
3126
+ } = opts;
3127
+ return router.matchRoute(rest, {
3128
+ pending,
3129
+ caseSensitive
3130
+ });
3131
+ };
2658
3132
  }
2659
3133
  function MatchRoute(props) {
2660
- const router = useRouter();
2661
- return /*#__PURE__*/React__namespace.createElement(router.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);
2662
3140
  }
2663
3141
  function Outlet() {
2664
- var _ref3, _match$__$pendingComp, _match$__$errorCompon;
2665
3142
  const router = useRouter();
2666
3143
  const matches = useMatches().slice(1);
2667
3144
  const match = matches[0];
2668
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;
3150
+ }
3151
+ if (props.match.store.status === 'success') {
3152
+ return /*#__PURE__*/React__namespace.createElement(props.match.__.component ?? router.options.defaultComponent ?? Outlet);
3153
+ }
3154
+ if (props.match.store.status === 'loading') {
3155
+ throw props.match.__.loadPromise;
3156
+ }
3157
+ invariant(false, 'Idle routeMatch status encountered during rendering! You should never see this. File an issue!');
3158
+ }, []);
2669
3159
  if (!match) {
2670
3160
  return null;
2671
3161
  }
2672
- const PendingComponent = (_ref3 = (_match$__$pendingComp = match.__.pendingComponent) != null ? _match$__$pendingComp : router.options.defaultPendingComponent) != null ? _ref3 : defaultPending;
2673
- const errorComponent = (_match$__$errorCompon = match.__.errorComponent) != null ? _match$__$errorCompon : router.options.defaultErrorComponent;
2674
- return /*#__PURE__*/React__namespace.createElement(MatchesProvider, {
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, {
2675
3165
  value: matches
2676
3166
  }, /*#__PURE__*/React__namespace.createElement(React__namespace.Suspense, {
2677
3167
  fallback: /*#__PURE__*/React__namespace.createElement(PendingComponent, null)
@@ -2679,27 +3169,17 @@
2679
3169
  key: match.routeId,
2680
3170
  errorComponent: errorComponent,
2681
3171
  match: match
2682
- }, (() => {
2683
- if (match.status === 'error') {
2684
- throw match.error;
2685
- }
2686
- if (match.status === 'success') {
2687
- var _ref4, _ref5;
2688
- return /*#__PURE__*/React__namespace.createElement((_ref4 = (_ref5 = match.__.component) != null ? _ref5 : router.options.defaultComponent) != null ? _ref4 : Outlet);
2689
- }
2690
- throw match.__.loadPromise;
2691
- })())));
3172
+ }, /*#__PURE__*/React__namespace.createElement(Inner, {
3173
+ match: match
3174
+ }))));
2692
3175
  }
2693
3176
  class CatchBoundary extends React__namespace.Component {
2694
- constructor() {
2695
- super(...arguments);
2696
- this.state = {
2697
- error: false,
2698
- info: undefined
2699
- };
2700
- }
3177
+ state = {
3178
+ error: false,
3179
+ info: undefined
3180
+ };
2701
3181
  componentDidCatch(error, info) {
2702
- console.error("Error in route match: " + this.props.match.matchId);
3182
+ console.error(`Error in route match: ${this.props.match.matchId}`);
2703
3183
  console.error(error);
2704
3184
  this.setState({
2705
3185
  error,
@@ -2707,7 +3187,7 @@
2707
3187
  });
2708
3188
  }
2709
3189
  render() {
2710
- return /*#__PURE__*/React__namespace.createElement(CatchBoundaryInner, _extends$2({}, this.props, {
3190
+ return /*#__PURE__*/React__namespace.createElement(CatchBoundaryInner, _extends$1({}, this.props, {
2711
3191
  errorState: this.state,
2712
3192
  reset: () => this.setState({})
2713
3193
  }));
@@ -2718,19 +3198,18 @@
2718
3198
  // there has to be a better way to reset error boundaries when the
2719
3199
  // router's location key changes.
2720
3200
  function CatchBoundaryInner(props) {
2721
- var _props$errorComponent;
2722
3201
  const [activeErrorState, setActiveErrorState] = React__namespace.useState(props.errorState);
2723
3202
  const router = useRouter();
2724
- const errorComponent = (_props$errorComponent = props.errorComponent) != null ? _props$errorComponent : DefaultErrorBoundary;
3203
+ const errorComponent = props.errorComponent ?? DefaultErrorBoundary;
2725
3204
  React__namespace.useEffect(() => {
2726
3205
  if (activeErrorState) {
2727
- let prevKey = router.state.currentLocation.key;
2728
- return router.subscribe(() => {
2729
- if (router.state.currentLocation.key !== prevKey) {
2730
- prevKey = router.state.currentLocation.key;
3206
+ let prevKey = router.store.currentLocation.key;
3207
+ return createRoot(() => createEffect(() => {
3208
+ if (router.store.currentLocation.key !== prevKey) {
3209
+ prevKey = router.store.currentLocation.key;
2731
3210
  setActiveErrorState({});
2732
3211
  }
2733
- });
3212
+ }));
2734
3213
  }
2735
3214
  return;
2736
3215
  }, [activeErrorState]);
@@ -2740,15 +3219,15 @@
2740
3219
  }
2741
3220
  props.reset();
2742
3221
  }, [props.errorState.error]);
2743
- if (activeErrorState.error) {
3222
+ if (props.errorState.error) {
2744
3223
  return /*#__PURE__*/React__namespace.createElement(errorComponent, activeErrorState);
2745
3224
  }
2746
3225
  return props.children;
2747
3226
  }
2748
- function DefaultErrorBoundary(_ref6) {
3227
+ function DefaultErrorBoundary(_ref2) {
2749
3228
  let {
2750
3229
  error
2751
- } = _ref6;
3230
+ } = _ref2;
2752
3231
  return /*#__PURE__*/React__namespace.createElement("div", {
2753
3232
  style: {
2754
3233
  padding: '.5rem',
@@ -2781,38 +3260,61 @@
2781
3260
  unblock();
2782
3261
  transition.retry();
2783
3262
  } else {
2784
- router.state.currentLocation.pathname = window.location.pathname;
3263
+ router.store.currentLocation.pathname = window.location.pathname;
2785
3264
  }
2786
3265
  });
2787
3266
  return unblock;
2788
3267
  }, [when, message]);
2789
3268
  }
2790
- function Prompt(_ref7) {
3269
+ function Prompt(_ref3) {
2791
3270
  let {
2792
3271
  message,
2793
3272
  when,
2794
3273
  children
2795
- } = _ref7;
2796
- usePrompt(message, when != null ? when : true);
2797
- return children != null ? children : null;
2798
- }
3274
+ } = _ref3;
3275
+ usePrompt(message, when ?? true);
3276
+ return children ?? null;
3277
+ }
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
+ // }
2799
3295
 
2800
3296
  exports.DefaultErrorBoundary = DefaultErrorBoundary;
2801
3297
  exports.Link = Link;
2802
3298
  exports.MatchRoute = MatchRoute;
2803
- exports.MatchesProvider = MatchesProvider;
2804
3299
  exports.Outlet = Outlet;
2805
3300
  exports.Prompt = Prompt;
2806
3301
  exports.RouterProvider = RouterProvider;
3302
+ exports.__useStoreValue = __useStoreValue;
3303
+ exports.batch = batch;
2807
3304
  exports.cleanPath = cleanPath;
2808
3305
  exports.createBrowserHistory = createBrowserHistory;
3306
+ exports.createEffect = createEffect;
2809
3307
  exports.createHashHistory = createHashHistory;
3308
+ exports.createMemo = createMemo;
2810
3309
  exports.createMemoryHistory = createMemoryHistory;
2811
3310
  exports.createReactRouter = createReactRouter;
3311
+ exports.createRoot = createRoot;
2812
3312
  exports.createRoute = createRoute;
2813
3313
  exports.createRouteConfig = createRouteConfig;
2814
3314
  exports.createRouteMatch = createRouteMatch;
2815
3315
  exports.createRouter = createRouter;
3316
+ exports.createSignal = createSignal;
3317
+ exports.createStore = createStore;
2816
3318
  exports.decode = decode;
2817
3319
  exports.defaultParseSearch = defaultParseSearch;
2818
3320
  exports.defaultStringifySearch = defaultStringifySearch;
@@ -2820,31 +3322,39 @@
2820
3322
  exports.functionalUpdate = functionalUpdate;
2821
3323
  exports.interpolatePath = interpolatePath;
2822
3324
  exports.invariant = invariant;
3325
+ exports.isWrappable = isWrappable;
2823
3326
  exports.joinPaths = joinPaths;
2824
3327
  exports.last = last;
2825
3328
  exports.lazy = lazy;
2826
- exports.linkProps = linkProps;
2827
3329
  exports.matchByPath = matchByPath;
2828
3330
  exports.matchPathname = matchPathname;
2829
3331
  exports.matchesContext = matchesContext;
3332
+ exports.onCleanup = onCleanup;
2830
3333
  exports.parsePathname = parsePathname;
2831
3334
  exports.parseSearchWith = parseSearchWith;
2832
3335
  exports.pick = pick;
2833
- exports.replaceEqualDeep = replaceEqualDeep;
2834
3336
  exports.resolvePath = resolvePath;
2835
3337
  exports.rootRouteId = rootRouteId;
2836
3338
  exports.routerContext = routerContext;
3339
+ exports.sharedClone = sharedClone;
2837
3340
  exports.stringifySearchWith = stringifySearchWith;
2838
3341
  exports.trimPath = trimPath;
2839
3342
  exports.trimPathLeft = trimPathLeft;
2840
3343
  exports.trimPathRight = trimPathRight;
3344
+ exports.untrack = untrack;
3345
+ exports.unwrap = unwrap;
3346
+ exports.useAction = useAction;
3347
+ exports.useLinkProps = useLinkProps;
3348
+ exports.useLoaderData = useLoaderData;
2841
3349
  exports.useMatch = useMatch;
3350
+ exports.useMatchRoute = useMatchRoute;
2842
3351
  exports.useMatches = useMatches;
2843
- exports.useNearestMatch = useNearestMatch;
3352
+ exports.useNavigate = useNavigate;
2844
3353
  exports.useParams = useParams;
2845
3354
  exports.usePrompt = usePrompt;
2846
3355
  exports.useRoute = useRoute;
2847
3356
  exports.useRouter = useRouter;
3357
+ exports.useRouterStore = useRouterStore;
2848
3358
  exports.useSearch = useSearch;
2849
3359
  exports.warning = warning;
2850
3360