kdu-router 3.5.4 → 3.6.0
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 -21
- package/README.md +11 -11
- package/dist/composables.js +253 -0
- package/dist/composables.mjs +244 -0
- package/dist/kdu-router.common.js +2668 -2665
- package/dist/kdu-router.esm.browser.js +2676 -2670
- package/dist/kdu-router.esm.browser.min.js +5 -5
- package/dist/kdu-router.esm.js +2680 -2674
- package/dist/kdu-router.js +2675 -2672
- package/dist/kdu-router.min.js +5 -5
- package/ketur/attributes.json +38 -38
- package/ketur/tags.json +20 -20
- package/package.json +115 -90
- package/src/components/link.js +224 -224
- package/src/components/view.js +155 -155
- package/src/composables/globals.js +34 -0
- package/src/composables/guards.js +68 -0
- package/src/composables/index.js +3 -0
- package/src/composables/useLink.js +113 -0
- package/src/composables/utils.js +11 -0
- package/src/create-matcher.js +226 -226
- package/src/create-route-map.js +220 -220
- package/src/entries/cjs.js +3 -0
- package/src/entries/esm.js +12 -0
- package/src/history/abstract.js +72 -72
- package/src/history/base.js +379 -379
- package/src/history/hash.js +152 -152
- package/src/history/html5.js +99 -99
- package/src/index.js +3 -293
- package/src/install.js +52 -52
- package/src/router.js +293 -0
- package/src/util/async.js +18 -18
- package/src/util/dom.js +3 -3
- package/src/util/errors.js +86 -86
- package/src/util/location.js +69 -69
- package/src/util/misc.js +6 -6
- package/src/util/params.js +37 -37
- package/src/util/path.js +74 -74
- package/src/util/push-state.js +46 -46
- package/src/util/query.js +113 -113
- package/src/util/resolve-components.js +109 -109
- package/src/util/route.js +151 -151
- package/src/util/scroll.js +175 -175
- package/src/util/state-key.js +22 -22
- package/src/util/warn.js +14 -14
- package/types/composables.d.ts +53 -0
- package/types/index.d.ts +25 -21
- package/types/kdu.d.ts +22 -22
- package/types/router.d.ts +564 -211
package/src/util/state-key.js
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import { inBrowser } from './dom'
|
|
3
|
-
|
|
4
|
-
// use User Timing api (if present) for more accurate key precision
|
|
5
|
-
const Time =
|
|
6
|
-
inBrowser && window.performance && window.performance.now
|
|
7
|
-
? window.performance
|
|
8
|
-
: Date
|
|
9
|
-
|
|
10
|
-
export function genStateKey (): string {
|
|
11
|
-
return Time.now().toFixed(3)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let _key: string = genStateKey()
|
|
15
|
-
|
|
16
|
-
export function getStateKey () {
|
|
17
|
-
return _key
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export function setStateKey (key: string) {
|
|
21
|
-
return (_key = key)
|
|
22
|
-
}
|
|
1
|
+
/* @flow */
|
|
2
|
+
import { inBrowser } from './dom'
|
|
3
|
+
|
|
4
|
+
// use User Timing api (if present) for more accurate key precision
|
|
5
|
+
const Time =
|
|
6
|
+
inBrowser && window.performance && window.performance.now
|
|
7
|
+
? window.performance
|
|
8
|
+
: Date
|
|
9
|
+
|
|
10
|
+
export function genStateKey (): string {
|
|
11
|
+
return Time.now().toFixed(3)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let _key: string = genStateKey()
|
|
15
|
+
|
|
16
|
+
export function getStateKey () {
|
|
17
|
+
return _key
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function setStateKey (key: string) {
|
|
21
|
+
return (_key = key)
|
|
22
|
+
}
|
package/src/util/warn.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
|
|
3
|
-
export function assert (condition: any, message: string) {
|
|
4
|
-
if (!condition) {
|
|
5
|
-
throw new Error(`[kdu-router] ${message}`)
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function warn (condition: any, message: string) {
|
|
10
|
-
if (!condition) {
|
|
11
|
-
typeof console !== 'undefined' && console.warn(`[kdu-router] ${message}`)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
1
|
+
/* @flow */
|
|
2
|
+
|
|
3
|
+
export function assert (condition: any, message: string) {
|
|
4
|
+
if (!condition) {
|
|
5
|
+
throw new Error(`[kdu-router] ${message}`)
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export function warn (condition: any, message: string) {
|
|
10
|
+
if (!condition) {
|
|
11
|
+
typeof console !== 'undefined' && console.warn(`[kdu-router] ${message}`)
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
declare module 'kdu-router/composables' {
|
|
2
|
+
import type { ComputedRef, Ref } from 'kdu'
|
|
3
|
+
import type { Route, NavigationGuard, default as KduRouter } from 'kdu-router'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the current route location. Equivalent to using `$route` inside templates.
|
|
7
|
+
*/
|
|
8
|
+
export function useRoute(): Route
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the router instance. Equivalent to using `$router` inside templates.
|
|
12
|
+
*/
|
|
13
|
+
export function useRouter(): KduRouter
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Add a navigation guard that triggers whenever the current location is about to be updated. Similar to beforeRouteUpdate but can be used in any component. The guard is removed when the component is unmounted.
|
|
17
|
+
*
|
|
18
|
+
* @param updateGuard
|
|
19
|
+
*/
|
|
20
|
+
export function onBeforeRouteUpdate(updateGuard: NavigationGuard): void
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Add a navigation guard that triggers whenever the component for the current location is about to be left. Similar to beforeRouteLeave but can be used in any component. The guard is removed when the component is unmounted.
|
|
24
|
+
*
|
|
25
|
+
* @param leaveGuard
|
|
26
|
+
*/
|
|
27
|
+
export function onBeforeRouteLeave(leaveGuard: NavigationGuard): void
|
|
28
|
+
|
|
29
|
+
export interface RouterLinkOptions {
|
|
30
|
+
/**
|
|
31
|
+
* Route Location the link should navigate to when clicked on.
|
|
32
|
+
*/
|
|
33
|
+
to: Route | Ref<Route>
|
|
34
|
+
/**
|
|
35
|
+
* Calls `router.replace` instead of `router.push`.
|
|
36
|
+
*/
|
|
37
|
+
replace?: boolean
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Kdu Router 4 `useLink()` function. Note the active behavior is different from Kdu Router 3 as highlighted in the
|
|
42
|
+
* migration guide (https://kdujs-router.web.app/guide/migration/index.html#removal-of-the-exact-prop-in-router-link)
|
|
43
|
+
*
|
|
44
|
+
* @param props - object containing a `to` property with the location
|
|
45
|
+
*/
|
|
46
|
+
export function useLink(props: RouterLinkOptions): {
|
|
47
|
+
route: ComputedRef<Route>,
|
|
48
|
+
isActive: ComputedRef<boolean>,
|
|
49
|
+
isExactActive: ComputedRef<boolean>,
|
|
50
|
+
href: ComputedRef<string>,
|
|
51
|
+
navigate: () => Promise<void>,
|
|
52
|
+
}
|
|
53
|
+
}
|
package/types/index.d.ts
CHANGED
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
import './kdu'
|
|
2
|
-
import { KduRouter } from './router'
|
|
3
|
-
|
|
4
|
-
export default KduRouter
|
|
5
|
-
|
|
6
|
-
export {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
1
|
+
import './kdu'
|
|
2
|
+
import { KduRouter, RouterLink, RouterView } from './router'
|
|
3
|
+
|
|
4
|
+
export default KduRouter
|
|
5
|
+
// TODO: does this really work with the new keyword?
|
|
6
|
+
export { RouterView, RouterLink }
|
|
7
|
+
|
|
8
|
+
export type {
|
|
9
|
+
RouterMode,
|
|
10
|
+
RouteMeta,
|
|
11
|
+
RawLocation,
|
|
12
|
+
RedirectOption,
|
|
13
|
+
RouterOptions,
|
|
14
|
+
RouteConfig,
|
|
15
|
+
RouteRecord,
|
|
16
|
+
RouteRecordPublic,
|
|
17
|
+
Location,
|
|
18
|
+
Route,
|
|
19
|
+
NavigationGuard,
|
|
20
|
+
NavigationGuardNext,
|
|
21
|
+
NavigationFailureType,
|
|
22
|
+
NavigationFailure
|
|
23
|
+
} from './router'
|
|
24
|
+
|
|
25
|
+
import './composables'
|
package/types/kdu.d.ts
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Augment the typings of Kdu.js
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import Kdu from 'kdu'
|
|
6
|
-
import KduRouter, { Route,
|
|
7
|
-
|
|
8
|
-
declare module 'kdu/types/kdu' {
|
|
9
|
-
interface Kdu {
|
|
10
|
-
$router: KduRouter
|
|
11
|
-
$route: Route
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
declare module 'kdu/types/options' {
|
|
16
|
-
interface ComponentOptions<V extends Kdu> {
|
|
17
|
-
router?: KduRouter
|
|
18
|
-
beforeRouteEnter?: NavigationGuard<V>
|
|
19
|
-
beforeRouteLeave?: NavigationGuard<V>
|
|
20
|
-
beforeRouteUpdate?: NavigationGuard<V>
|
|
21
|
-
}
|
|
22
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Augment the typings of Kdu.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import Kdu from 'kdu'
|
|
6
|
+
import KduRouter, { Route, NavigationGuard } from './index'
|
|
7
|
+
|
|
8
|
+
declare module 'kdu/types/kdu' {
|
|
9
|
+
interface Kdu {
|
|
10
|
+
$router: KduRouter
|
|
11
|
+
$route: Route
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare module 'kdu/types/options' {
|
|
16
|
+
interface ComponentOptions<V extends Kdu> {
|
|
17
|
+
router?: KduRouter
|
|
18
|
+
beforeRouteEnter?: NavigationGuard<V>
|
|
19
|
+
beforeRouteLeave?: NavigationGuard<V>
|
|
20
|
+
beforeRouteUpdate?: NavigationGuard<V>
|
|
21
|
+
}
|
|
22
|
+
}
|