From 8382587262b4f0a495351a352a6a1660ccd33622 Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Thu, 23 Jan 2020 12:37:49 +0100 Subject: [PATCH] feat: type inject --- explorations/html5.ts | 4 ---- package.json | 8 ++++---- src/history/html5.ts | 4 ++++ src/index.ts | 28 +++++++++++++++++++++++++--- yarn.lock | 38 ++++++++++++++++++++++---------------- 5 files changed, 55 insertions(+), 27 deletions(-) diff --git a/explorations/html5.ts b/explorations/html5.ts index 0cd262a9..5fa31df4 100644 --- a/explorations/html5.ts +++ b/explorations/html5.ts @@ -16,10 +16,6 @@ declare global { window.h = routerHistory window.r = router -if ('scrollRestoration' in history) { - history.scrollRestoration = 'manual' -} - const app = createApp() app.provide('state', globalState) app.use(RouterPlugin, router) diff --git a/package.json b/package.json index 35b701fe..325bc164 100644 --- a/package.json +++ b/package.json @@ -24,13 +24,13 @@ "@rollup/plugin-replace": "^2.3.0", "@types/jest": "^24.9.0", "@types/jsdom": "^12.2.4", - "@types/webpack": "^4.41.2", + "@types/webpack": "^4.41.3", "@types/webpack-env": "^1.15.0", "@vue/compiler-sfc": "^3.0.0-alpha.2", - "axios": "^0.19.1", + "axios": "^0.19.2", "browserstack-local": "^1.4.4", "chromedriver": "^79.0.0", - "codecov": "^3.6.1", + "codecov": "^3.6.2", "consola": "^2.11.3", "css-loader": "^3.4.2", "dotenv": "^8.2.0", @@ -51,7 +51,7 @@ "ts-jest": "^24.2.0", "ts-loader": "^6.2.1", "ts-node": "^8.6.2", - "typescript": "^3.7.4", + "typescript": "^3.7.5", "vue": "^3.0.0-alpha.2", "vue-loader": "^16.0.0-alpha.2", "webpack": "^4.41.5", diff --git a/src/history/html5.ts b/src/history/html5.ts index f2d4102a..e58b8a3f 100644 --- a/src/history/html5.ts +++ b/src/history/html5.ts @@ -259,6 +259,10 @@ function useHistoryStateNavigation(base: string) { } export default function createHistory(base: string = ''): RouterHistory { + if ('scrollRestoration' in history) { + history.scrollRestoration = 'manual' + } + const historyNavigation = useHistoryStateNavigation(base) const historyListeners = useHistoryListeners( base, diff --git a/src/index.ts b/src/index.ts index b89505f1..f4dfc0ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,9 +5,24 @@ import createMemoryHistory from './history/memory' import createHashHistory from './history/hash' import View from './components/View' import Link from './components/Link' +import { RouteLocationNormalized } from './types' -export { RouteLocationNormalized } from './types' -export { Router } from './router' +declare module '@vue/runtime-core' { + function inject(name: 'router'): Router + function inject(name: 'route'): RouteLocationNormalized +} + +// @ts-ignore: we are not importing it so it complains +declare module '@vue/runtime-dom' { + function inject(name: 'router'): Router + function inject(name: 'route'): RouteLocationNormalized +} + +// @ts-ignore: we are not importing it so it complains +declare module 'vue' { + function inject(name: 'router'): Router + function inject(name: 'route'): RouteLocationNormalized +} export function RouterPlugin(app: App, router: Router) { // TODO: remove as any @@ -34,4 +49,11 @@ export function RouterPlugin(app: App, router: Router) { app.provide('route', router.currentRoute) } -export { createHistory, createMemoryHistory, createHashHistory, createRouter } +export { + createHistory, + createMemoryHistory, + createHashHistory, + createRouter, + RouteLocationNormalized, + Router, +} diff --git a/yarn.lock b/yarn.lock index 5080acb3..44448e9e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -480,10 +480,10 @@ "@types/source-list-map" "*" source-map "^0.6.1" -"@types/webpack@^4.41.2": - version "4.41.2" - resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.2.tgz#c6faf0111de27afdffe1158dac559e447c273516" - integrity sha512-DNMQOfEvwzWRRyp6Wy9QVCgJ3gkelZsuBE2KUD318dg95s9DKGiT5CszmmV58hq8jk89I9NClre48AEy1MWAJA== +"@types/webpack@^4.41.3": + version "4.41.3" + resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.3.tgz#30c2251db1d69a45bbffd79c0577dd9baf50e7ba" + integrity sha512-dH+BZ6pHBZFrXpnif0YU/PbmUq3lQrvRPnqkxsciSIzvG/DE+Vm/Wrjn56T7V3+B5ryQa5fw0oGnHL8tk4ll6w== dependencies: "@types/anymatch" "*" "@types/node" "*" @@ -1027,10 +1027,10 @@ aws4@^1.8.0: resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.9.0.tgz#24390e6ad61386b0a747265754d2a17219de862c" integrity sha512-Uvq6hVe90D0B2WEnUqtdgY1bATGz3mw33nH9Y+dmA+w5DHvUmBgkr5rM/KCHpCsiFNRUfokW/szpPPgMK2hm4A== -axios@^0.19.1: - version "0.19.1" - resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.1.tgz#8a6a04eed23dfe72747e1dd43c604b8f1677b5aa" - integrity sha512-Yl+7nfreYKaLRvAvjNPkvfjnQHJM1yLBY3zhqAwcJSwR/6ETkanUgylgtIvkvz0xJ+p/vZuNw8X7Hnb7Whsbpw== +axios@^0.19.2: + version "0.19.2" + resolved "https://registry.yarnpkg.com/axios/-/axios-0.19.2.tgz#3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27" + integrity sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA== dependencies: follow-redirects "1.5.10" @@ -1558,16 +1558,17 @@ code-point-at@^1.0.0: resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" integrity sha1-DQcLTQQ6W+ozovGkDi7bPZpMz3c= -codecov@^3.6.1: - version "3.6.1" - resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.6.1.tgz#f39fc49413445555f81f8e3ca5730992843b4517" - integrity sha512-IUJB6WG47nWK7o50etF8jBadxdMw7DmoQg05yIljstXFBGB6clOZsIj6iD4P82T2YaIU3qq+FFu8K9pxgkCJDQ== +codecov@^3.6.2: + version "3.6.2" + resolved "https://registry.yarnpkg.com/codecov/-/codecov-3.6.2.tgz#9503533d744233f6864f8f3ead9435d285ed3f47" + integrity sha512-i1VYZYY3M8Lodk/QRsIWYVimkuhl0oMSiM2itxbTbEIjB0PCSWP1cI7cscu5P0MayggoTl6I/jkXV2go8Ub8/Q== dependencies: argv "^0.0.2" ignore-walk "^3.0.1" js-yaml "^3.13.1" teeny-request "^3.11.3" urlgrey "^0.4.4" + validator "^12.1.0" collection-visit@^1.0.0: version "1.0.0" @@ -7203,10 +7204,10 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^3.7.4: - version "3.7.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.4.tgz#1743a5ec5fef6a1fa9f3e4708e33c81c73876c19" - integrity sha512-A25xv5XCtarLwXpcDNZzCGvW2D1S3/bACratYBx2sax8PefsFhlYmkQicKHvpYflFS8if4zne5zT5kpJ7pzuvw== +typescript@^3.7.5: + version "3.7.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae" + integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw== uglify-js@3.4.x: version "3.4.10" @@ -7374,6 +7375,11 @@ validate-npm-package-license@^3.0.1: spdx-correct "^3.0.0" spdx-expression-parse "^3.0.0" +validator@^12.1.0: + version "12.1.0" + resolved "https://registry.yarnpkg.com/validator/-/validator-12.1.0.tgz#a3a7315d5238cbc15e46ad8d5e479aafa7119925" + integrity sha512-gIC2RBuFRi574Rb9vewGCJ7TCLxHXNx6EKthEgs+Iz0pYa9a9Te1VLG/bGLsAyGWrqR5FfR7tbFUI7FEF2LiGA== + vary@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/vary/-/vary-1.1.2.tgz#2299f02c6ded30d4a5961b0b9f74524a18f634fc" -- 2.47.3