@tanstack/router-core 0.0.1-beta.5 → 0.0.1-beta.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/build/cjs/actions.js +94 -0
  3. package/build/cjs/actions.js.map +1 -0
  4. package/build/cjs/history.js +163 -0
  5. package/build/cjs/history.js.map +1 -0
  6. package/build/cjs/{packages/router-core/src/index.js → index.js} +26 -11
  7. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  8. package/build/cjs/interop.js +175 -0
  9. package/build/cjs/interop.js.map +1 -0
  10. package/build/cjs/{packages/router-core/src/path.js → path.js} +23 -48
  11. package/build/cjs/path.js.map +1 -0
  12. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
  13. package/build/cjs/qss.js.map +1 -0
  14. package/build/cjs/route.js +33 -0
  15. package/build/cjs/route.js.map +1 -0
  16. package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -18
  17. package/build/cjs/routeConfig.js.map +1 -0
  18. package/build/cjs/routeMatch.js +237 -0
  19. package/build/cjs/routeMatch.js.map +1 -0
  20. package/build/cjs/router.js +821 -0
  21. package/build/cjs/router.js.map +1 -0
  22. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
  23. package/build/cjs/searchParams.js.map +1 -0
  24. package/build/cjs/store.js +54 -0
  25. package/build/cjs/store.js.map +1 -0
  26. package/build/cjs/utils.js +47 -0
  27. package/build/cjs/utils.js.map +1 -0
  28. package/build/esm/index.js +1384 -2059
  29. package/build/esm/index.js.map +1 -1
  30. package/build/stats-html.html +59 -49
  31. package/build/stats-react.json +248 -193
  32. package/build/types/index.d.ts +385 -317
  33. package/build/umd/index.development.js +1486 -2142
  34. package/build/umd/index.development.js.map +1 -1
  35. package/build/umd/index.production.js +1 -1
  36. package/build/umd/index.production.js.map +1 -1
  37. package/package.json +6 -4
  38. package/src/actions.ts +157 -0
  39. package/src/frameworks.ts +2 -2
  40. package/src/history.ts +199 -0
  41. package/src/index.ts +4 -7
  42. package/src/interop.ts +169 -0
  43. package/src/link.ts +87 -44
  44. package/src/path.ts +12 -8
  45. package/src/route.ts +36 -229
  46. package/src/routeConfig.ts +99 -102
  47. package/src/routeInfo.ts +28 -25
  48. package/src/routeMatch.ts +294 -322
  49. package/src/router.ts +1047 -884
  50. package/src/store.ts +52 -0
  51. package/src/utils.ts +14 -72
  52. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  53. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  54. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  55. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  56. package/build/cjs/node_modules/history/index.js +0 -815
  57. package/build/cjs/node_modules/history/index.js.map +0 -1
  58. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  59. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  60. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  61. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  62. package/build/cjs/packages/router-core/src/route.js +0 -161
  63. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  64. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  65. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  66. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  67. package/build/cjs/packages/router-core/src/router.js +0 -797
  68. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  69. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  70. package/build/cjs/packages/router-core/src/utils.js +0 -118
  71. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
package/src/store.ts ADDED
@@ -0,0 +1,52 @@
1
+ import { produce, setAutoFreeze } from 'immer'
2
+
3
+ setAutoFreeze(false)
4
+
5
+ export type Store<TState> = {
6
+ state: TState
7
+ subscribe: (listener: (next: TState, prev: TState) => void) => () => void
8
+ setState: (updater: (cb: TState) => void) => void
9
+ }
10
+
11
+ let queue: ((...args: any[]) => void)[] = []
12
+ let batching = false
13
+
14
+ function flush() {
15
+ if (batching) return
16
+ queue.forEach((cb) => cb())
17
+ queue = []
18
+ }
19
+
20
+ export function createStore<TState>(initialState: TState, debug?: boolean) {
21
+ const listeners = new Set<(next: TState, prev: TState) => void>()
22
+
23
+ const store: Store<TState> = {
24
+ state: initialState,
25
+ subscribe: (listener) => {
26
+ listeners.add(listener)
27
+ return () => listeners.delete(listener)
28
+ },
29
+ setState: (updater) => {
30
+ const previous = store.state
31
+ store.state = produce((d) => {
32
+ updater(d)
33
+ })(previous)
34
+
35
+ if (debug) console.log(store.state)
36
+
37
+ queue.push(() =>
38
+ listeners.forEach((listener) => listener(store.state, previous)),
39
+ )
40
+ flush()
41
+ },
42
+ }
43
+
44
+ return store
45
+ }
46
+
47
+ export function batch(cb: () => void) {
48
+ batching = true
49
+ cb()
50
+ batching = false
51
+ flush()
52
+ }
package/src/utils.ts CHANGED
@@ -24,11 +24,11 @@ export type Expand<T> = T extends object
24
24
  : never
25
25
  : T
26
26
 
27
- // type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
28
- // k: infer I,
29
- // ) => any
30
- // ? I
31
- // : never
27
+ export type UnionToIntersection<U> = (
28
+ U extends any ? (k: U) => void : never
29
+ ) extends (k: infer I) => any
30
+ ? I
31
+ : never
32
32
 
33
33
  export type Values<O> = O[ValueKeys<O>]
34
34
  export type ValueKeys<O> = Extract<keyof O, PropertyKey>
@@ -40,9 +40,9 @@ export type DeepAwaited<T> = T extends Promise<infer A>
40
40
  : T
41
41
 
42
42
  export type PathParamMask<TRoutePath extends string> =
43
- TRoutePath extends `${infer L}/:${infer C}/${infer R}`
43
+ TRoutePath extends `${infer L}/$${infer C}/${infer R}`
44
44
  ? PathParamMask<`${L}/${string}/${R}`>
45
- : TRoutePath extends `${infer L}/:${infer C}`
45
+ : TRoutePath extends `${infer L}/$${infer C}`
46
46
  ? PathParamMask<`${L}/${string}`>
47
47
  : TRoutePath
48
48
 
@@ -60,71 +60,6 @@ export type PickExclude<T, U> = {
60
60
  [K in keyof T as T[K] extends U ? never : K]: T[K]
61
61
  }
62
62
 
63
- /**
64
- * This function returns `a` if `b` is deeply equal.
65
- * If not, it will replace any deeply equal children of `b` with those of `a`.
66
- * This can be used for structural sharing between JSON values for example.
67
- */
68
- export function replaceEqualDeep(prev: any, next: any) {
69
- if (prev === next) {
70
- return prev
71
- }
72
-
73
- const array = Array.isArray(prev) && Array.isArray(next)
74
-
75
- if (array || (isPlainObject(prev) && isPlainObject(next))) {
76
- const aSize = array ? prev.length : Object.keys(prev).length
77
- const bItems = array ? next : Object.keys(next)
78
- const bSize = bItems.length
79
- const copy: any = array ? [] : {}
80
-
81
- let equalItems = 0
82
-
83
- for (let i = 0; i < bSize; i++) {
84
- const key = array ? i : bItems[i]
85
- copy[key] = replaceEqualDeep(prev[key], next[key])
86
- if (copy[key] === prev[key]) {
87
- equalItems++
88
- }
89
- }
90
-
91
- return aSize === bSize && equalItems === aSize ? prev : copy
92
- }
93
-
94
- return next
95
- }
96
-
97
- // Copied from: https://github.com/jonschlinkert/is-plain-object
98
- function isPlainObject(o: any) {
99
- if (!hasObjectPrototype(o)) {
100
- return false
101
- }
102
-
103
- // If has modified constructor
104
- const ctor = o.constructor
105
- if (typeof ctor === 'undefined') {
106
- return true
107
- }
108
-
109
- // If has modified prototype
110
- const prot = ctor.prototype
111
- if (!hasObjectPrototype(prot)) {
112
- return false
113
- }
114
-
115
- // If constructor does not have an Object-specific method
116
- if (!prot.hasOwnProperty('isPrototypeOf')) {
117
- return false
118
- }
119
-
120
- // Most likely a plain Object
121
- return true
122
- }
123
-
124
- function hasObjectPrototype(o: any) {
125
- return Object.prototype.toString.call(o) === '[object Object]'
126
- }
127
-
128
63
  export function last<T>(arr: T[]) {
129
64
  return arr[arr.length - 1]
130
65
  }
@@ -155,3 +90,10 @@ export function functionalUpdate<TResult>(
155
90
 
156
91
  return updater
157
92
  }
93
+
94
+ export function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {
95
+ return keys.reduce((obj: any, key: K) => {
96
+ obj[key] = parent[key]
97
+ return obj
98
+ }, {} as any)
99
+ }
@@ -1,33 +0,0 @@
1
- /**
2
- * router-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
-
20
- for (var key in source) {
21
- if (Object.prototype.hasOwnProperty.call(source, key)) {
22
- target[key] = source[key];
23
- }
24
- }
25
- }
26
-
27
- return target;
28
- };
29
- return _extends.apply(this, arguments);
30
- }
31
-
32
- exports["extends"] = _extends;
33
- //# sourceMappingURL=_rollupPluginBabelHelpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"_rollupPluginBabelHelpers.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,33 +0,0 @@
1
- /**
2
- * router-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- 'use strict';
12
-
13
- Object.defineProperty(exports, '__esModule', { value: true });
14
-
15
- function _extends() {
16
- _extends = Object.assign ? Object.assign.bind() : function (target) {
17
- for (var i = 1; i < arguments.length; i++) {
18
- var source = arguments[i];
19
-
20
- for (var key in source) {
21
- if (Object.prototype.hasOwnProperty.call(source, key)) {
22
- target[key] = source[key];
23
- }
24
- }
25
- }
26
-
27
- return target;
28
- };
29
- return _extends.apply(this, arguments);
30
- }
31
-
32
- exports["default"] = _extends;
33
- //# sourceMappingURL=extends.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"extends.js","sources":["../../../../../../../../../node_modules/@babel/runtime/helpers/esm/extends.js"],"sourcesContent":["export default function _extends() {\n _extends = Object.assign ? Object.assign.bind() : function (target) {\n for (var i = 1; i < arguments.length; i++) {\n var source = arguments[i];\n\n for (var key in source) {\n if (Object.prototype.hasOwnProperty.call(source, key)) {\n target[key] = source[key];\n }\n }\n }\n\n return target;\n };\n return _extends.apply(this, arguments);\n}"],"names":[],"mappings":";;;;;;;;;;;;;;AAAe,SAAS,QAAQ,GAAG;AACnC,EAAE,QAAQ,GAAG,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,UAAU,MAAM,EAAE;AACtE,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;AAC/C,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;AAChC;AACA,MAAM,KAAK,IAAI,GAAG,IAAI,MAAM,EAAE;AAC9B,QAAQ,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE;AAC/D,UAAU,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;AACpC,SAAS;AACT,OAAO;AACP,KAAK;AACL;AACA,IAAI,OAAO,MAAM,CAAC;AAClB,GAAG,CAAC;AACJ,EAAE,OAAO,QAAQ,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AACzC;;;;"}