@tanstack/router-core 0.0.1-beta.194 → 0.0.1-beta.196
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/build/cjs/fileRoute.js.map +1 -1
- package/build/cjs/index.js +7 -4
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +1 -1
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/utils.js +2 -0
- package/build/cjs/utils.js.map +1 -1
- package/build/esm/index.js +4 -210
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +194 -189
- package/build/types/index.d.ts +1 -1
- package/build/types/route.d.ts +21 -21
- package/build/types/routeInfo.d.ts +1 -1
- package/build/types/router.d.ts +10 -4
- package/build/umd/index.development.js +2102 -2019
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +21 -11
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -1
- package/src/fileRoute.ts +1 -8
- package/src/index.ts +1 -1
- package/src/route.ts +5 -47
- package/src/routeInfo.ts +1 -3
- package/src/router.ts +14 -10
- package/src/utils.ts +1 -0
- package/build/cjs/history.js +0 -228
- package/build/cjs/history.js.map +0 -1
- package/build/types/history.d.ts +0 -36
- package/src/history.ts +0 -300
package/build/cjs/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N\nexport type IsAnyBoolean<T> = 1 extends 0 & T ? true : false\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type PickAsPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>\nexport type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never\nexport type PickExtra<T, K> = {\n [TKey in keyof K as string extends TKey\n ? never\n : TKey extends keyof T\n ? never\n : TKey]: K[TKey]\n}\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\n// type Compute<T> = { [K in keyof T]: T[K] } | never\n\n// type AllKeys<T> = T extends any ? keyof T : never\n\n// export type MergeUnion<T, Keys extends keyof T = keyof T> = Compute<\n// {\n// [K in Keys]: T[Keys]\n// } & {\n// [K in AllKeys<T>]?: T extends any\n// ? K extends keyof T\n// ? T[K]\n// : never\n// : never\n// }\n// >\n\nexport type DeepMerge<A, B> = {\n [K in keyof (A & B)]: K extends keyof B\n ? B[K]\n : K extends keyof A\n ? A[K]\n : never\n} & (A extends Record<string, any>\n ? Pick<A, Exclude<keyof A, keyof B>>\n : never) &\n (B extends Record<string, any> ? Pick<B, Exclude<keyof B, keyof A>> : never)\n\nexport type DeepMergeAll<T extends any[]> = T extends [\n infer Left,\n ...infer Rest,\n]\n ? Rest extends any[]\n ? DeepMerge<Left, DeepMergeAll<Rest>>\n : Left\n : {}\n\nexport type Values<O> = O[ValueKeys<O>]\nexport type ValueKeys<O> = Extract<keyof O, PropertyKey>\n\nexport type DeepAwaited<T> = T extends Promise<infer A>\n ? DeepAwaited<A>\n : T extends Record<infer A, Promise<infer B>>\n ? { [K in A]: DeepAwaited<B> }\n : T\n\nexport type PathParamMask<TRoutePath extends string> =\n TRoutePath extends `${infer L}/$${infer C}/${infer R}`\n ? PathParamMask<`${L}/${string}/${R}`>\n : TRoutePath extends `${infer L}/$${infer C}`\n ? PathParamMask<`${L}/${string}`>\n : TRoutePath\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type PickExtract<T, U> = {\n [K in keyof T as T[K] extends U ? K : never]: T[K]\n}\n\nexport type PickExclude<T, U> = {\n [K in keyof T as T[K] extends U ? never : K]: T[K]\n}\n\nexport function last<T>(arr: T[]) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous as TResult)\n }\n\n return updater\n}\n\nexport function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {\n return keys.reduce((obj: any, key: K) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\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 immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = Array.isArray(prev) && Array.isArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevSize = array ? prev.length : Object.keys(prev).length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key]) {\n equalItems++\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function 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\nexport function partialDeepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n return !Object.keys(b).some((key) => !partialDeepEqual(a[key], b[key]))\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return (\n a.length === b.length &&\n a.every((item, index) => partialDeepEqual(item, b[index]))\n )\n }\n\n return false\n}\n"],"names":["last","arr","length","isFunction","d","functionalUpdate","updater","previous","pick","parent","keys","reduce","obj","key","replaceEqualDeep","prev","_next","next","array","Array","isArray","isPlainObject","prevSize","Object","nextItems","nextSize","copy","equalItems","i","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call","partialDeepEqual","a","b","some","every","item","index"],"mappings":";;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export type NoInfer<T> = [T][T extends any ? 0 : never]\nexport type IsAny<T, Y, N = T> = 1 extends 0 & T ? Y : N\nexport type IsAnyBoolean<T> = 1 extends 0 & T ? true : false\nexport type IsKnown<T, Y, N> = unknown extends T ? N : Y\nexport type PickAsRequired<T, K extends keyof T> = Omit<T, K> &\n Required<Pick<T, K>>\nexport type PickAsPartial<T, K extends keyof T> = Omit<T, K> &\n Partial<Pick<T, K>>\nexport type PickUnsafe<T, K> = K extends keyof T ? Pick<T, K> : never\nexport type PickExtra<T, K> = {\n [TKey in keyof K as string extends TKey\n ? never\n : TKey extends keyof T\n ? never\n : TKey]: K[TKey]\n}\n\nexport type PickRequired<T> = {\n [K in keyof T as undefined extends T[K] ? never : K]: T[K]\n}\n\n// export type Expand<T> = T\nexport type Expand<T> = T extends object\n ? T extends infer O\n ? { [K in keyof O]: O[K] }\n : never\n : T\n\nexport type UnionToIntersection<U> = (\n U extends any ? (k: U) => void : never\n) extends (k: infer I) => any\n ? I\n : never\n\n// type Compute<T> = { [K in keyof T]: T[K] } | never\n\n// type AllKeys<T> = T extends any ? keyof T : never\n\n// export type MergeUnion<T, Keys extends keyof T = keyof T> = Compute<\n// {\n// [K in Keys]: T[Keys]\n// } & {\n// [K in AllKeys<T>]?: T extends any\n// ? K extends keyof T\n// ? T[K]\n// : never\n// : never\n// }\n// >\n\nexport type DeepMerge<A, B> = {\n [K in keyof (A & B)]: K extends keyof B\n ? B[K]\n : K extends keyof A\n ? A[K]\n : never\n} & (A extends Record<string, any>\n ? Pick<A, Exclude<keyof A, keyof B>>\n : never) &\n (B extends Record<string, any> ? Pick<B, Exclude<keyof B, keyof A>> : never)\n\nexport type DeepMergeAll<T extends any[]> = T extends [\n infer Left,\n ...infer Rest,\n]\n ? Rest extends any[]\n ? DeepMerge<Left, DeepMergeAll<Rest>>\n : Left\n : {}\n\nexport type Values<O> = O[ValueKeys<O>]\nexport type ValueKeys<O> = Extract<keyof O, PropertyKey>\n\nexport type DeepAwaited<T> = T extends Promise<infer A>\n ? DeepAwaited<A>\n : T extends Record<infer A, Promise<infer B>>\n ? { [K in A]: DeepAwaited<B> }\n : T\n\nexport type PathParamMask<TRoutePath extends string> =\n TRoutePath extends `${infer L}/$${infer C}/${infer R}`\n ? PathParamMask<`${L}/${string}/${R}`>\n : TRoutePath extends `${infer L}/$${infer C}`\n ? PathParamMask<`${L}/${string}`>\n : TRoutePath\n\nexport type Timeout = ReturnType<typeof setTimeout>\n\nexport type Updater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev?: TPrevious) => TResult)\n\nexport type NonNullableUpdater<TPrevious, TResult = TPrevious> =\n | TResult\n | ((prev: TPrevious) => TResult)\n\nexport type PickExtract<T, U> = {\n [K in keyof T as T[K] extends U ? K : never]: T[K]\n}\n\nexport type PickExclude<T, U> = {\n [K in keyof T as T[K] extends U ? never : K]: T[K]\n}\n\nexport function last<T>(arr: T[]) {\n return arr[arr.length - 1]\n}\n\nfunction isFunction(d: any): d is Function {\n return typeof d === 'function'\n}\n\nexport function functionalUpdate<TResult>(\n updater: Updater<TResult> | NonNullableUpdater<TResult>,\n previous: TResult,\n): TResult {\n if (isFunction(updater)) {\n return updater(previous as TResult)\n }\n\n return updater\n}\n\nexport function pick<T, K extends keyof T>(parent: T, keys: K[]): Pick<T, K> {\n return keys.reduce((obj: any, key: K) => {\n obj[key] = parent[key]\n return obj\n }, {} as any)\n}\n\n/**\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 immutable JSON values for example.\n * Do not use this with signals\n */\nexport function replaceEqualDeep<T>(prev: any, _next: T): T {\n if (prev === _next) {\n return prev\n }\n\n const next = _next as any\n\n const array = Array.isArray(prev) && Array.isArray(next)\n\n if (array || (isPlainObject(prev) && isPlainObject(next))) {\n const prevSize = array ? prev.length : Object.keys(prev).length\n const nextItems = array ? next : Object.keys(next)\n const nextSize = nextItems.length\n const copy: any = array ? [] : {}\n\n let equalItems = 0\n\n for (let i = 0; i < nextSize; i++) {\n const key = array ? i : nextItems[i]\n copy[key] = replaceEqualDeep(prev[key], next[key])\n if (copy[key] === prev[key]) {\n equalItems++\n }\n }\n\n return prevSize === nextSize && equalItems === prevSize ? prev : copy\n }\n\n return next\n}\n\n// Copied from: https://github.com/jonschlinkert/is-plain-object\nexport function 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\nexport function partialDeepEqual(a: any, b: any): boolean {\n if (a === b) {\n return true\n }\n\n if (typeof a !== typeof b) {\n return false\n }\n\n if (isPlainObject(a) && isPlainObject(b)) {\n return !Object.keys(b).some((key) => !partialDeepEqual(a[key], b[key]))\n }\n\n if (Array.isArray(a) && Array.isArray(b)) {\n return (\n a.length === b.length &&\n a.every((item, index) => partialDeepEqual(item, b[index]))\n )\n }\n\n return false\n}\n"],"names":["last","arr","length","isFunction","d","functionalUpdate","updater","previous","pick","parent","keys","reduce","obj","key","replaceEqualDeep","prev","_next","next","array","Array","isArray","isPlainObject","prevSize","Object","nextItems","nextSize","copy","equalItems","i","o","hasObjectPrototype","ctor","constructor","prot","prototype","hasOwnProperty","toString","call","partialDeepEqual","a","b","some","every","item","index"],"mappings":";;;;;;;;;;;;;;AAqBA;;AAaA;;AAEA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAwDO,SAASA,IAAIA,CAAIC,GAAQ,EAAE;AAChC,EAAA,OAAOA,GAAG,CAACA,GAAG,CAACC,MAAM,GAAG,CAAC,CAAC,CAAA;AAC5B,CAAA;AAEA,SAASC,UAAUA,CAACC,CAAM,EAAiB;EACzC,OAAO,OAAOA,CAAC,KAAK,UAAU,CAAA;AAChC,CAAA;AAEO,SAASC,gBAAgBA,CAC9BC,OAAuD,EACvDC,QAAiB,EACR;AACT,EAAA,IAAIJ,UAAU,CAACG,OAAO,CAAC,EAAE;IACvB,OAAOA,OAAO,CAACC,QAAmB,CAAC,CAAA;AACrC,GAAA;AAEA,EAAA,OAAOD,OAAO,CAAA;AAChB,CAAA;AAEO,SAASE,IAAIA,CAAuBC,MAAS,EAAEC,IAAS,EAAc;EAC3E,OAAOA,IAAI,CAACC,MAAM,CAAC,CAACC,GAAQ,EAAEC,GAAM,KAAK;AACvCD,IAAAA,GAAG,CAACC,GAAG,CAAC,GAAGJ,MAAM,CAACI,GAAG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EAEA,IAAInB,aAAa,CAACkB,CAAC,CAAC,IAAIlB,aAAa,CAACmB,CAAC,CAAC,EAAE;IACxC,OAAO,CAACjB,MAAM,CAACb,IAAI,CAAC8B,CAAC,CAAC,CAACC,IAAI,CAAE5B,GAAG,IAAK,CAACyB,gBAAgB,CAACC,CAAC,CAAC1B,GAAG,CAAC,EAAE2B,CAAC,CAAC3B,GAAG,CAAC,CAAC,CAAC,CAAA;AACzE,GAAA;AAEA,EAAA,IAAIM,KAAK,CAACC,OAAO,CAACmB,CAAC,CAAC,IAAIpB,KAAK,CAACC,OAAO,CAACoB,CAAC,CAAC,EAAE;IACxC,OACED,CAAC,CAACrC,MAAM,KAAKsC,CAAC,CAACtC,MAAM,IACrBqC,CAAC,CAACG,KAAK,CAAC,CAACC,IAAI,EAAEC,KAAK,KAAKN,gBAAgB,CAACK,IAAI,EAAEH,CAAC,CAACI,KAAK,CAAC,CAAC,CAAC,CAAA;AAE9D,GAAA;AAEA,EAAA,OAAO,KAAK,CAAA;AACd;;;;;;;;;"}
|
package/build/esm/index.js
CHANGED
|
@@ -8,220 +8,14 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
+
import { createMemoryHistory, createBrowserHistory } from '@tanstack/history';
|
|
12
|
+
export * from '@tanstack/history';
|
|
11
13
|
import invariant from 'tiny-invariant';
|
|
12
14
|
export { default as invariant } from 'tiny-invariant';
|
|
13
15
|
export { default as warning } from 'tiny-warning';
|
|
14
16
|
import { Store } from '@tanstack/store';
|
|
15
17
|
|
|
16
|
-
//
|
|
17
|
-
// This implementation attempts to be more lightweight by
|
|
18
|
-
// making assumptions about the way TanStack Router works
|
|
19
|
-
|
|
20
|
-
const pushStateEvent = 'pushstate';
|
|
21
|
-
const popStateEvent = 'popstate';
|
|
22
|
-
const beforeUnloadEvent = 'beforeunload';
|
|
23
|
-
const beforeUnloadListener = event => {
|
|
24
|
-
event.preventDefault();
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
return event.returnValue = '';
|
|
27
|
-
};
|
|
28
|
-
const stopBlocking = () => {
|
|
29
|
-
removeEventListener(beforeUnloadEvent, beforeUnloadListener, {
|
|
30
|
-
capture: true
|
|
31
|
-
});
|
|
32
|
-
};
|
|
33
|
-
function createHistory(opts) {
|
|
34
|
-
let location = opts.getLocation();
|
|
35
|
-
let unsub = () => {};
|
|
36
|
-
let subscribers = new Set();
|
|
37
|
-
let blockers = [];
|
|
38
|
-
let queue = [];
|
|
39
|
-
const tryFlush = () => {
|
|
40
|
-
if (blockers.length) {
|
|
41
|
-
blockers[0]?.(tryFlush, () => {
|
|
42
|
-
blockers = [];
|
|
43
|
-
stopBlocking();
|
|
44
|
-
});
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
while (queue.length) {
|
|
48
|
-
queue.shift()?.();
|
|
49
|
-
}
|
|
50
|
-
if (!opts.subscriber) {
|
|
51
|
-
onUpdate();
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
const queueTask = task => {
|
|
55
|
-
queue.push(task);
|
|
56
|
-
tryFlush();
|
|
57
|
-
};
|
|
58
|
-
const onUpdate = () => {
|
|
59
|
-
location = opts.getLocation();
|
|
60
|
-
subscribers.forEach(subscriber => subscriber());
|
|
61
|
-
};
|
|
62
|
-
return {
|
|
63
|
-
get location() {
|
|
64
|
-
return location;
|
|
65
|
-
},
|
|
66
|
-
subscribe: cb => {
|
|
67
|
-
if (subscribers.size === 0) {
|
|
68
|
-
unsub = typeof opts.subscriber === 'function' ? opts.subscriber(onUpdate) : () => {};
|
|
69
|
-
}
|
|
70
|
-
subscribers.add(cb);
|
|
71
|
-
return () => {
|
|
72
|
-
subscribers.delete(cb);
|
|
73
|
-
if (subscribers.size === 0) {
|
|
74
|
-
unsub();
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
},
|
|
78
|
-
push: (path, state) => {
|
|
79
|
-
assignKey(state);
|
|
80
|
-
queueTask(() => {
|
|
81
|
-
opts.pushState(path, state);
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
replace: (path, state) => {
|
|
85
|
-
assignKey(state);
|
|
86
|
-
queueTask(() => {
|
|
87
|
-
opts.replaceState(path, state);
|
|
88
|
-
});
|
|
89
|
-
},
|
|
90
|
-
go: index => {
|
|
91
|
-
queueTask(() => {
|
|
92
|
-
opts.go(index);
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
back: () => {
|
|
96
|
-
queueTask(() => {
|
|
97
|
-
opts.back();
|
|
98
|
-
});
|
|
99
|
-
},
|
|
100
|
-
forward: () => {
|
|
101
|
-
queueTask(() => {
|
|
102
|
-
opts.forward();
|
|
103
|
-
});
|
|
104
|
-
},
|
|
105
|
-
createHref: str => opts.createHref(str),
|
|
106
|
-
block: cb => {
|
|
107
|
-
blockers.push(cb);
|
|
108
|
-
if (blockers.length === 1) {
|
|
109
|
-
addEventListener(beforeUnloadEvent, beforeUnloadListener, {
|
|
110
|
-
capture: true
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
return () => {
|
|
114
|
-
blockers = blockers.filter(b => b !== cb);
|
|
115
|
-
if (!blockers.length) {
|
|
116
|
-
stopBlocking();
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
function assignKey(state) {
|
|
123
|
-
state.key = createRandomKey();
|
|
124
|
-
// if (state.__actualLocation) {
|
|
125
|
-
// state.__actualLocation.state = {
|
|
126
|
-
// ...state.__actualLocation.state,
|
|
127
|
-
// key,
|
|
128
|
-
// }
|
|
129
|
-
// }
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function createBrowserHistory(opts) {
|
|
133
|
-
const getHref = opts?.getHref ?? (() => `${window.location.pathname}${window.location.search}${window.location.hash}`);
|
|
134
|
-
const createHref = opts?.createHref ?? (path => path);
|
|
135
|
-
const getLocation = () => parseLocation(getHref(), window.history.state);
|
|
136
|
-
return createHistory({
|
|
137
|
-
getLocation,
|
|
138
|
-
subscriber: onUpdate => {
|
|
139
|
-
window.addEventListener(pushStateEvent, onUpdate);
|
|
140
|
-
window.addEventListener(popStateEvent, onUpdate);
|
|
141
|
-
var pushState = window.history.pushState;
|
|
142
|
-
window.history.pushState = function () {
|
|
143
|
-
let res = pushState.apply(history, arguments);
|
|
144
|
-
onUpdate();
|
|
145
|
-
return res;
|
|
146
|
-
};
|
|
147
|
-
var replaceState = window.history.replaceState;
|
|
148
|
-
window.history.replaceState = function () {
|
|
149
|
-
let res = replaceState.apply(history, arguments);
|
|
150
|
-
onUpdate();
|
|
151
|
-
return res;
|
|
152
|
-
};
|
|
153
|
-
return () => {
|
|
154
|
-
window.history.pushState = pushState;
|
|
155
|
-
window.history.replaceState = replaceState;
|
|
156
|
-
window.removeEventListener(pushStateEvent, onUpdate);
|
|
157
|
-
window.removeEventListener(popStateEvent, onUpdate);
|
|
158
|
-
};
|
|
159
|
-
},
|
|
160
|
-
pushState: (path, state) => {
|
|
161
|
-
window.history.pushState(state, '', createHref(path));
|
|
162
|
-
},
|
|
163
|
-
replaceState: (path, state) => {
|
|
164
|
-
window.history.replaceState(state, '', createHref(path));
|
|
165
|
-
},
|
|
166
|
-
back: () => window.history.back(),
|
|
167
|
-
forward: () => window.history.forward(),
|
|
168
|
-
go: n => window.history.go(n),
|
|
169
|
-
createHref: path => createHref(path)
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
function createHashHistory() {
|
|
173
|
-
return createBrowserHistory({
|
|
174
|
-
getHref: () => window.location.hash.substring(1),
|
|
175
|
-
createHref: path => `#${path}`
|
|
176
|
-
});
|
|
177
|
-
}
|
|
178
|
-
function createMemoryHistory(opts = {
|
|
179
|
-
initialEntries: ['/']
|
|
180
|
-
}) {
|
|
181
|
-
const entries = opts.initialEntries;
|
|
182
|
-
let index = opts.initialIndex ?? entries.length - 1;
|
|
183
|
-
let currentState = {
|
|
184
|
-
key: createRandomKey()
|
|
185
|
-
};
|
|
186
|
-
const getLocation = () => parseLocation(entries[index], currentState);
|
|
187
|
-
return createHistory({
|
|
188
|
-
getLocation,
|
|
189
|
-
subscriber: false,
|
|
190
|
-
pushState: (path, state) => {
|
|
191
|
-
currentState = state;
|
|
192
|
-
entries.push(path);
|
|
193
|
-
index++;
|
|
194
|
-
},
|
|
195
|
-
replaceState: (path, state) => {
|
|
196
|
-
currentState = state;
|
|
197
|
-
entries[index] = path;
|
|
198
|
-
},
|
|
199
|
-
back: () => {
|
|
200
|
-
index--;
|
|
201
|
-
},
|
|
202
|
-
forward: () => {
|
|
203
|
-
index = Math.min(index + 1, entries.length - 1);
|
|
204
|
-
},
|
|
205
|
-
go: n => window.history.go(n),
|
|
206
|
-
createHref: path => path
|
|
207
|
-
});
|
|
208
|
-
}
|
|
209
|
-
function parseLocation(href, state) {
|
|
210
|
-
let hashIndex = href.indexOf('#');
|
|
211
|
-
let searchIndex = href.indexOf('?');
|
|
212
|
-
return {
|
|
213
|
-
href,
|
|
214
|
-
pathname: href.substring(0, hashIndex > 0 ? searchIndex > 0 ? Math.min(hashIndex, searchIndex) : hashIndex : searchIndex > 0 ? searchIndex : href.length),
|
|
215
|
-
hash: hashIndex > -1 ? href.substring(hashIndex) : '',
|
|
216
|
-
search: searchIndex > -1 ? href.slice(searchIndex, hashIndex === -1 ? undefined : hashIndex) : '',
|
|
217
|
-
state: state || {}
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// Thanks co-pilot!
|
|
222
|
-
function createRandomKey() {
|
|
223
|
-
return (Math.random() + 1).toString(36).substring(7);
|
|
224
|
-
}
|
|
18
|
+
// export type Expand<T> = T
|
|
225
19
|
|
|
226
20
|
// type Compute<T> = { [K in keyof T]: T[K] } | never
|
|
227
21
|
|
|
@@ -2112,5 +1906,5 @@ function isDehydratedDeferred(obj) {
|
|
|
2112
1906
|
return typeof obj === 'object' && obj !== null && !(obj instanceof Promise) && !obj.then && '__deferredState' in obj;
|
|
2113
1907
|
}
|
|
2114
1908
|
|
|
2115
|
-
export { FileRoute, PathParamError, RootRoute, Route, Router, RouterContext, SearchParamError, cleanPath, componentTypes,
|
|
1909
|
+
export { FileRoute, PathParamError, RootRoute, Route, Router, RouterContext, SearchParamError, cleanPath, componentTypes, createRouteMask, decode, defaultParseSearch, defaultStringifySearch, defer, encode, functionalUpdate, interpolatePath, isDehydratedDeferred, isMatchInvalid, isPlainObject, isRedirect, joinPaths, last, lazyFn, matchByPath, matchPathname, parsePathname, parseSearchWith, partialDeepEqual, pick, redirect, replaceEqualDeep, resolvePath, restoreScrollPositions, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, watchScrollPositions };
|
|
2116
1910
|
//# sourceMappingURL=index.js.map
|