@tanstack/router-core 0.0.1-beta.41 → 0.0.1-beta.49
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.
- package/LICENSE +21 -0
- package/build/cjs/actions.js +94 -0
- package/build/cjs/actions.js.map +1 -0
- package/build/cjs/history.js +163 -0
- package/build/cjs/history.js.map +1 -0
- package/build/cjs/index.js +18 -20
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/interop.js +175 -0
- package/build/cjs/interop.js.map +1 -0
- package/build/cjs/path.js +4 -5
- package/build/cjs/path.js.map +1 -1
- package/build/cjs/route.js +16 -138
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/routeConfig.js +1 -7
- package/build/cjs/routeConfig.js.map +1 -1
- package/build/cjs/routeMatch.js +194 -199
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +726 -703
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/store.js +54 -0
- package/build/cjs/store.js.map +1 -0
- package/build/esm/index.js +1305 -1114
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +229 -192
- package/build/types/index.d.ts +172 -109
- package/build/umd/index.development.js +1381 -2331
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +4 -4
- package/src/actions.ts +157 -0
- package/src/history.ts +199 -0
- package/src/index.ts +4 -7
- package/src/interop.ts +169 -0
- package/src/link.ts +2 -2
- package/src/route.ts +34 -239
- package/src/routeConfig.ts +3 -34
- package/src/routeInfo.ts +6 -21
- package/src/routeMatch.ts +270 -285
- package/src/router.ts +967 -963
- package/src/store.ts +52 -0
- package/build/cjs/sharedClone.js +0 -122
- package/build/cjs/sharedClone.js.map +0 -1
- package/src/sharedClone.ts +0 -118
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/build/cjs/sharedClone.js
DELETED
|
@@ -1,122 +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
|
-
/**
|
|
16
|
-
* This function returns `a` if `b` is deeply equal.
|
|
17
|
-
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
18
|
-
* This can be used for structural sharing between JSON values for example.
|
|
19
|
-
*/
|
|
20
|
-
function sharedClone(prev, next, touchAll) {
|
|
21
|
-
const things = new Map();
|
|
22
|
-
function recurse(prev, next) {
|
|
23
|
-
if (prev === next) {
|
|
24
|
-
return prev;
|
|
25
|
-
}
|
|
26
|
-
if (things.has(next)) {
|
|
27
|
-
return things.get(next);
|
|
28
|
-
}
|
|
29
|
-
const prevIsArray = Array.isArray(prev);
|
|
30
|
-
const nextIsArray = Array.isArray(next);
|
|
31
|
-
const prevIsObj = isPlainObject(prev);
|
|
32
|
-
const nextIsObj = isPlainObject(next);
|
|
33
|
-
const isArray = prevIsArray && nextIsArray;
|
|
34
|
-
const isObj = prevIsObj && nextIsObj;
|
|
35
|
-
const isSameStructure = isArray || isObj;
|
|
36
|
-
|
|
37
|
-
// Both are arrays or objects
|
|
38
|
-
if (isSameStructure) {
|
|
39
|
-
const aSize = isArray ? prev.length : Object.keys(prev).length;
|
|
40
|
-
const bItems = isArray ? next : Object.keys(next);
|
|
41
|
-
const bSize = bItems.length;
|
|
42
|
-
const copy = isArray ? [] : {};
|
|
43
|
-
let equalItems = 0;
|
|
44
|
-
for (let i = 0; i < bSize; i++) {
|
|
45
|
-
const key = isArray ? i : bItems[i];
|
|
46
|
-
if (copy[key] === prev[key]) {
|
|
47
|
-
equalItems++;
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
if (aSize === bSize && equalItems === aSize) {
|
|
51
|
-
things.set(next, prev);
|
|
52
|
-
return prev;
|
|
53
|
-
}
|
|
54
|
-
things.set(next, copy);
|
|
55
|
-
for (let i = 0; i < bSize; i++) {
|
|
56
|
-
const key = isArray ? i : bItems[i];
|
|
57
|
-
if (typeof bItems[i] === 'function') {
|
|
58
|
-
copy[key] = prev[key];
|
|
59
|
-
} else {
|
|
60
|
-
copy[key] = recurse(prev[key], next[key]);
|
|
61
|
-
}
|
|
62
|
-
if (copy[key] === prev[key]) {
|
|
63
|
-
equalItems++;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return copy;
|
|
67
|
-
}
|
|
68
|
-
if (nextIsArray) {
|
|
69
|
-
const copy = [];
|
|
70
|
-
things.set(next, copy);
|
|
71
|
-
for (let i = 0; i < next.length; i++) {
|
|
72
|
-
copy[i] = recurse(undefined, next[i]);
|
|
73
|
-
}
|
|
74
|
-
return copy;
|
|
75
|
-
}
|
|
76
|
-
if (nextIsObj) {
|
|
77
|
-
const copy = {};
|
|
78
|
-
things.set(next, copy);
|
|
79
|
-
const nextKeys = Object.keys(next);
|
|
80
|
-
for (let i = 0; i < nextKeys.length; i++) {
|
|
81
|
-
const key = nextKeys[i];
|
|
82
|
-
copy[key] = recurse(undefined, next[key]);
|
|
83
|
-
}
|
|
84
|
-
return copy;
|
|
85
|
-
}
|
|
86
|
-
return next;
|
|
87
|
-
}
|
|
88
|
-
return recurse(prev, next);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
92
|
-
function isPlainObject(o) {
|
|
93
|
-
if (!hasObjectPrototype(o)) {
|
|
94
|
-
return false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// If has modified constructor
|
|
98
|
-
const ctor = o.constructor;
|
|
99
|
-
if (typeof ctor === 'undefined') {
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// If has modified prototype
|
|
104
|
-
const prot = ctor.prototype;
|
|
105
|
-
if (!hasObjectPrototype(prot)) {
|
|
106
|
-
return false;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
// If constructor does not have an Object-specific method
|
|
110
|
-
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
// Most likely a plain Object
|
|
115
|
-
return true;
|
|
116
|
-
}
|
|
117
|
-
function hasObjectPrototype(o) {
|
|
118
|
-
return Object.prototype.toString.call(o) === '[object Object]';
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
exports.sharedClone = sharedClone;
|
|
122
|
-
//# sourceMappingURL=sharedClone.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sharedClone.js","sources":["../../src/sharedClone.ts"],"sourcesContent":["/**\n * This function returns `a` if `b` is deeply equal.\n * If not, it will replace any deeply equal children of `b` with those of `a`.\n * This can be used for structural sharing between JSON values for example.\n */\nexport function sharedClone<T>(prev: any, next: T, touchAll?: boolean): T {\n const things = new Map()\n\n function recurse(prev: any, next: any) {\n if (prev === next) {\n return prev\n }\n\n if (things.has(next)) {\n return things.get(next)\n }\n\n const prevIsArray = Array.isArray(prev)\n const nextIsArray = Array.isArray(next)\n const prevIsObj = isPlainObject(prev)\n const nextIsObj = isPlainObject(next)\n\n const isArray = prevIsArray && nextIsArray\n const isObj = prevIsObj && nextIsObj\n\n const isSameStructure = isArray || isObj\n\n // Both are arrays or objects\n if (isSameStructure) {\n const aSize = isArray ? prev.length : Object.keys(prev).length\n const bItems = isArray ? next : Object.keys(next)\n const bSize = bItems.length\n const copy: any = isArray ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < bSize; i++) {\n const key = isArray ? i : bItems[i]\n if (copy[key] === prev[key]) {\n equalItems++\n }\n }\n if (aSize === bSize && equalItems === aSize) {\n things.set(next, prev)\n return prev\n }\n things.set(next, copy)\n for (let i = 0; i < bSize; i++) {\n const key = isArray ? i : bItems[i]\n if (typeof bItems[i] === 'function') {\n copy[key] = prev[key]\n } else {\n copy[key] = recurse(prev[key], next[key])\n }\n if (copy[key] === prev[key]) {\n equalItems++\n }\n }\n\n return copy\n }\n\n if (nextIsArray) {\n const copy: any[] = []\n things.set(next, copy)\n for (let i = 0; i < next.length; i++) {\n copy[i] = recurse(undefined, next[i])\n }\n return copy as T\n }\n\n if (nextIsObj) {\n const copy = {} as any\n things.set(next, copy)\n const nextKeys = Object.keys(next)\n for (let i = 0; i < nextKeys.length; i++) {\n const key = nextKeys[i]!\n copy[key] = recurse(undefined, next[key])\n }\n return copy as T\n }\n\n return next\n }\n\n return recurse(prev, next)\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nfunction isPlainObject(o: any) {\n if (!hasObjectPrototype(o)) {\n return false\n }\n\n // If has modified constructor\n const ctor = o.constructor\n if (typeof ctor === 'undefined') {\n return true\n }\n\n // If has modified prototype\n const prot = ctor.prototype\n if (!hasObjectPrototype(prot)) {\n return false\n }\n\n // If constructor does not have an Object-specific method\n if (!prot.hasOwnProperty('isPrototypeOf')) {\n return false\n }\n\n // Most likely a plain Object\n return true\n}\n\nfunction hasObjectPrototype(o: any) {\n return Object.prototype.toString.call(o) === '[object Object]'\n}\n"],"names":["sharedClone","prev","next","touchAll","things","Map","recurse","has","get","prevIsArray","Array","isArray","nextIsArray","prevIsObj","isPlainObject","nextIsObj","isObj","isSameStructure","aSize","length","Object","keys","bItems","bSize","copy","equalItems","i","key","set","undefined","nextKeys","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,WAAW,CAAIC,IAAS,EAAEC,IAAO,EAAEC,QAAkB,EAAK;AACxE,EAAA,MAAMC,MAAM,GAAG,IAAIC,GAAG,EAAE,CAAA;AAExB,EAAA,SAASC,OAAO,CAACL,IAAS,EAAEC,IAAS,EAAE;IACrC,IAAID,IAAI,KAAKC,IAAI,EAAE;AACjB,MAAA,OAAOD,IAAI,CAAA;AACb,KAA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,CAAA;AAC3B,EAAA,IAAI,CAACJ,kBAAkB,CAACG,IAAI,CAAC,EAAE;AAC7B,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;;AAEA;AACA,EAAA,IAAI,CAACA,IAAI,CAACE,cAAc,CAAC,eAAe,CAAC,EAAE;AACzC,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;;AAEA;AACA,EAAA,OAAO,IAAI,CAAA;AACb,CAAA;AAEA,SAASL,kBAAkB,CAACD,CAAM,EAAE;EAClC,OAAOX,MAAM,CAACgB,SAAS,CAACE,QAAQ,CAACC,IAAI,CAACR,CAAC,CAAC,KAAK,iBAAiB,CAAA;AAChE;;;;"}
|
package/src/sharedClone.ts
DELETED
|
@@ -1,118 +0,0 @@
|
|
|
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
|
-
}
|