kdu-router 3.4.0-beta.0 → 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.
Files changed (49) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +11 -9
  3. package/dist/composables.js +253 -0
  4. package/dist/composables.mjs +244 -0
  5. package/dist/kdu-router.common.js +2682 -2572
  6. package/dist/kdu-router.esm.browser.js +2677 -2563
  7. package/dist/kdu-router.esm.browser.min.js +5 -5
  8. package/dist/kdu-router.esm.js +2685 -2572
  9. package/dist/kdu-router.js +2682 -2573
  10. package/dist/kdu-router.min.js +5 -5
  11. package/ketur/attributes.json +38 -38
  12. package/ketur/tags.json +20 -20
  13. package/package.json +115 -111
  14. package/src/components/link.js +224 -197
  15. package/src/components/view.js +155 -149
  16. package/src/composables/globals.js +34 -0
  17. package/src/composables/guards.js +68 -0
  18. package/src/composables/index.js +3 -0
  19. package/src/composables/useLink.js +113 -0
  20. package/src/composables/utils.js +11 -0
  21. package/src/create-matcher.js +226 -200
  22. package/src/create-route-map.js +220 -205
  23. package/src/entries/cjs.js +3 -0
  24. package/src/entries/esm.js +12 -0
  25. package/src/history/abstract.js +72 -68
  26. package/src/history/base.js +379 -400
  27. package/src/history/hash.js +152 -163
  28. package/src/history/html5.js +99 -94
  29. package/src/index.js +3 -277
  30. package/src/install.js +52 -52
  31. package/src/router.js +293 -0
  32. package/src/util/async.js +18 -18
  33. package/src/util/dom.js +3 -3
  34. package/src/util/errors.js +86 -85
  35. package/src/util/location.js +69 -69
  36. package/src/util/misc.js +6 -6
  37. package/src/util/params.js +37 -37
  38. package/src/util/path.js +74 -74
  39. package/src/util/push-state.js +46 -46
  40. package/src/util/query.js +113 -96
  41. package/src/util/resolve-components.js +109 -109
  42. package/src/util/route.js +151 -132
  43. package/src/util/scroll.js +175 -165
  44. package/src/util/state-key.js +22 -22
  45. package/src/util/warn.js +14 -14
  46. package/types/composables.d.ts +53 -0
  47. package/types/index.d.ts +25 -17
  48. package/types/kdu.d.ts +22 -22
  49. package/types/router.d.ts +564 -170
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 (process.env.NODE_ENV !== 'production' && !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,17 +1,25 @@
1
- import './kdu'
2
- import { KduRouter } from './router'
3
-
4
- export default KduRouter
5
-
6
- export {
7
- RouterMode,
8
- RawLocation,
9
- RedirectOption,
10
- RouterOptions,
11
- RouteConfig,
12
- RouteRecord,
13
- Location,
14
- Route,
15
- NavigationGuard,
16
- NavigationGuardNext
17
- } from './router'
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, RawLocation, 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
- }
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
+ }