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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/build/cjs/{packages/router-core/src/index.js → index.js} +25 -8
  2. package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
  3. package/build/cjs/{packages/router-core/src/path.js → path.js} +19 -43
  4. package/build/cjs/path.js.map +1 -0
  5. package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
  6. package/build/cjs/qss.js.map +1 -0
  7. package/build/cjs/route.js +155 -0
  8. package/build/cjs/route.js.map +1 -0
  9. package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +14 -13
  10. package/build/cjs/routeConfig.js.map +1 -0
  11. package/build/cjs/routeMatch.js +242 -0
  12. package/build/cjs/routeMatch.js.map +1 -0
  13. package/build/cjs/router.js +807 -0
  14. package/build/cjs/router.js.map +1 -0
  15. package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +10 -12
  16. package/build/cjs/searchParams.js.map +1 -0
  17. package/build/cjs/sharedClone.js +122 -0
  18. package/build/cjs/sharedClone.js.map +1 -0
  19. package/build/cjs/utils.js +47 -0
  20. package/build/cjs/utils.js.map +1 -0
  21. package/build/esm/index.js +890 -1739
  22. package/build/esm/index.js.map +1 -1
  23. package/build/stats-html.html +59 -49
  24. package/build/stats-react.json +196 -178
  25. package/build/types/index.d.ts +287 -283
  26. package/build/umd/index.development.js +1233 -922
  27. package/build/umd/index.development.js.map +1 -1
  28. package/build/umd/index.production.js +1 -1
  29. package/build/umd/index.production.js.map +1 -1
  30. package/package.json +4 -2
  31. package/src/frameworks.ts +2 -2
  32. package/src/index.ts +1 -1
  33. package/src/link.ts +86 -43
  34. package/src/path.ts +12 -8
  35. package/src/route.ts +170 -158
  36. package/src/routeConfig.ts +105 -77
  37. package/src/routeInfo.ts +26 -8
  38. package/src/routeMatch.ts +204 -217
  39. package/src/router.ts +680 -503
  40. package/src/sharedClone.ts +118 -0
  41. package/src/utils.ts +14 -72
  42. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -33
  43. package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +0 -1
  44. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
  45. package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
  46. package/build/cjs/node_modules/history/index.js +0 -815
  47. package/build/cjs/node_modules/history/index.js.map +0 -1
  48. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
  49. package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
  50. package/build/cjs/packages/router-core/src/path.js.map +0 -1
  51. package/build/cjs/packages/router-core/src/qss.js.map +0 -1
  52. package/build/cjs/packages/router-core/src/route.js +0 -161
  53. package/build/cjs/packages/router-core/src/route.js.map +0 -1
  54. package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
  55. package/build/cjs/packages/router-core/src/routeMatch.js +0 -266
  56. package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
  57. package/build/cjs/packages/router-core/src/router.js +0 -789
  58. package/build/cjs/packages/router-core/src/router.js.map +0 -1
  59. package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
  60. package/build/cjs/packages/router-core/src/utils.js +0 -118
  61. package/build/cjs/packages/router-core/src/utils.js.map +0 -1
@@ -0,0 +1,118 @@
1
+ /**
2
+ * This function returns `a` if `b` is deeply equal.
3
+ * If not, it will replace any deeply equal children of `b` with those of `a`.
4
+ * This can be used for structural sharing between JSON values for example.
5
+ */
6
+ export function sharedClone<T>(prev: any, next: T, touchAll?: boolean): T {
7
+ const things = new Map()
8
+
9
+ function recurse(prev: any, next: any) {
10
+ if (prev === next) {
11
+ return prev
12
+ }
13
+
14
+ if (things.has(next)) {
15
+ return things.get(next)
16
+ }
17
+
18
+ const prevIsArray = Array.isArray(prev)
19
+ const nextIsArray = Array.isArray(next)
20
+ const prevIsObj = isPlainObject(prev)
21
+ const nextIsObj = isPlainObject(next)
22
+
23
+ const isArray = prevIsArray && nextIsArray
24
+ const isObj = prevIsObj && nextIsObj
25
+
26
+ const isSameStructure = isArray || isObj
27
+
28
+ // Both are arrays or objects
29
+ if (isSameStructure) {
30
+ const aSize = isArray ? prev.length : Object.keys(prev).length
31
+ const bItems = isArray ? next : Object.keys(next)
32
+ const bSize = bItems.length
33
+ const copy: any = isArray ? [] : {}
34
+
35
+ let equalItems = 0
36
+
37
+ for (let i = 0; i < bSize; i++) {
38
+ const key = isArray ? i : bItems[i]
39
+ if (copy[key] === prev[key]) {
40
+ equalItems++
41
+ }
42
+ }
43
+ if (aSize === bSize && equalItems === aSize) {
44
+ things.set(next, prev)
45
+ return prev
46
+ }
47
+ things.set(next, copy)
48
+ for (let i = 0; i < bSize; i++) {
49
+ const key = isArray ? i : bItems[i]
50
+ if (typeof bItems[i] === 'function') {
51
+ copy[key] = prev[key]
52
+ } else {
53
+ copy[key] = recurse(prev[key], next[key])
54
+ }
55
+ if (copy[key] === prev[key]) {
56
+ equalItems++
57
+ }
58
+ }
59
+
60
+ return copy
61
+ }
62
+
63
+ if (nextIsArray) {
64
+ const copy: any[] = []
65
+ things.set(next, copy)
66
+ for (let i = 0; i < next.length; i++) {
67
+ copy[i] = recurse(undefined, next[i])
68
+ }
69
+ return copy as T
70
+ }
71
+
72
+ if (nextIsObj) {
73
+ const copy = {} as any
74
+ things.set(next, copy)
75
+ const nextKeys = Object.keys(next)
76
+ for (let i = 0; i < nextKeys.length; i++) {
77
+ const key = nextKeys[i]!
78
+ copy[key] = recurse(undefined, next[key])
79
+ }
80
+ return copy as T
81
+ }
82
+
83
+ return next
84
+ }
85
+
86
+ return recurse(prev, next)
87
+ }
88
+
89
+ // Copied from: https://github.com/jonschlinkert/is-plain-object
90
+ function isPlainObject(o: any) {
91
+ if (!hasObjectPrototype(o)) {
92
+ return false
93
+ }
94
+
95
+ // If has modified constructor
96
+ const ctor = o.constructor
97
+ if (typeof ctor === 'undefined') {
98
+ return true
99
+ }
100
+
101
+ // If has modified prototype
102
+ const prot = ctor.prototype
103
+ if (!hasObjectPrototype(prot)) {
104
+ return false
105
+ }
106
+
107
+ // If constructor does not have an Object-specific method
108
+ if (!prot.hasOwnProperty('isPrototypeOf')) {
109
+ return false
110
+ }
111
+
112
+ // Most likely a plain Object
113
+ return true
114
+ }
115
+
116
+ function hasObjectPrototype(o: any) {
117
+ return Object.prototype.toString.call(o) === '[object Object]'
118
+ }
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;;;;"}