From 559a13069a32dd81a41aa4feed4fcba25f39df62 Mon Sep 17 00:00:00 2001 From: Dominik Schmidt Date: Wed, 11 Jan 2023 23:48:48 +0100 Subject: [PATCH] wip --- .../design-system/src/directives/OcTooltip.ts | 59 ++++++------- packages/web-app-files/package.json | 2 +- packages/web-app-files/src/fileSideBars.ts | 3 +- .../web-app-files/src/router/deprecated.ts | 5 +- packages/web-app-files/src/router/utils.ts | 9 +- .../web-app-files/src/search/sdk/index.ts | 6 +- .../web-app-files/src/search/sdk/preview.ts | 6 +- .../tests/unit/components/Search/List.spec.ts | 2 - .../tests/unit/router/utils.spec.ts | 31 +++---- .../tests/unit/search/sdk.spec.ts | 12 +-- packages/web-pkg/package.json | 2 +- .../appDefaults/useAppNavigation.ts | 5 +- .../src/composables/router/useActiveApp.ts | 3 +- .../src/composables/router/useRouteMeta.ts | 4 +- .../src/composables/router/useRouteParam.ts | 9 +- .../src/composables/router/useRouteQuery.ts | 8 +- .../src/composables/router/useRouter.ts | 4 +- packages/web-pkg/src/index.ts | 1 + packages/web-pkg/src/types/index.ts | 1 + packages/web-pkg/src/types/router.ts | 3 + .../unit/composables/router/useRouter.spec.ts | 4 +- packages/web-runtime/package.json | 2 +- packages/web-runtime/src/App.vue | 24 +++--- .../src/components/Topbar/TopBar.vue | 2 +- packages/web-runtime/src/container/api.ts | 11 +-- .../src/container/application/classic.ts | 4 +- .../src/container/application/index.ts | 4 +- .../web-runtime/src/container/bootstrap.ts | 8 +- packages/web-runtime/src/container/types.ts | 5 +- packages/web-runtime/src/defaults/vue.js | 2 - packages/web-runtime/src/index.ts | 6 +- .../web-runtime/src/layouts/Application.vue | 4 +- .../web-runtime/src/pages/oidcCallback.vue | 5 +- packages/web-runtime/src/router/helpers.ts | 19 +++-- packages/web-runtime/src/router/index.ts | 11 +-- .../web-runtime/src/router/patchCleanPath.ts | 36 ++++---- .../src/services/auth/authService.ts | 10 ++- packages/web-test-helpers/package.json | 2 +- pnpm-lock.yaml | 85 ++++++------------- 39 files changed, 198 insertions(+), 221 deletions(-) create mode 100644 packages/web-pkg/src/types/index.ts create mode 100644 packages/web-pkg/src/types/router.ts diff --git a/packages/design-system/src/directives/OcTooltip.ts b/packages/design-system/src/directives/OcTooltip.ts index ddce940f63a..3b7cf58fcc9 100644 --- a/packages/design-system/src/directives/OcTooltip.ts +++ b/packages/design-system/src/directives/OcTooltip.ts @@ -1,5 +1,3 @@ -import tippy from 'tippy.js' -import merge from 'deepmerge' import __logger from '../utils/logger' export const hideOnEsc = { @@ -48,36 +46,33 @@ export const destroy = (_tippy) => { } const initOrUpdate = (el, { value = {} }: any, { elm }) => { - if (Object.prototype.toString.call(value) !== '[object Object]') { - value = { content: value } - } - - if (value.content !== 0 && !value.content) { - destroy(elm.tooltip) - elm.tooltip = null - return - } - - const props = merge.all([ - { - ignoreAttributes: true, - aria: { - content: null, - expanded: false - } - }, - value - ]) - - if (!elm.tooltip) { - elm.tooltip = tippy(el, { - ...props, - plugins: [hideOnEsc, ariaHidden] - }) - return - } - - elm.tooltip.setProps(props) + // if (Object.prototype.toString.call(value) !== '[object Object]') { + // value = { content: value } + // } + // if (value.content !== 0 && !value.content) { + // console.log('elm', elm, value) + // destroy(elm.tooltip) + // elm.tooltip = null + // return + // } + // const props = merge.all([ + // { + // ignoreAttributes: true, + // aria: { + // content: null, + // expanded: false + // } + // }, + // value + // ]) + // if (!elm?.tooltip) { + // elm.tooltip = tippy(el, { + // ...props, + // plugins: [hideOnEsc, ariaHidden] + // }) + // return + // } + // elm.tooltip.setProps(props) } export default { diff --git a/packages/web-app-files/package.json b/packages/web-app-files/package.json index 01a16e7fb45..e011a543e20 100644 --- a/packages/web-app-files/package.json +++ b/packages/web-app-files/package.json @@ -26,7 +26,7 @@ "uuid": "^9.0.0", "vue-concurrency": "4.0.0", "vue-gettext": "2.1.12", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vuex": "4.1.0", "web-app-files": "workspace:*", "web-app-search": "workspace:*", diff --git a/packages/web-app-files/src/fileSideBars.ts b/packages/web-app-files/src/fileSideBars.ts index 24e7998a15a..67b1ac36bca 100644 --- a/packages/web-app-files/src/fileSideBars.ts +++ b/packages/web-app-files/src/fileSideBars.ts @@ -18,7 +18,8 @@ import { spaceRoleEditor, spaceRoleManager } from 'web-client/src/helpers/share' import { Panel } from '../../web-pkg/src/components/sideBar' import { Resource, User } from 'web-client' -import Router from 'vue-router' +import { Router } from 'web-pkg/src/types/router' + function $gettext(msg: string): string { return msg diff --git a/packages/web-app-files/src/router/deprecated.ts b/packages/web-app-files/src/router/deprecated.ts index 96a50c20b76..d0e9ad1b08f 100644 --- a/packages/web-app-files/src/router/deprecated.ts +++ b/packages/web-app-files/src/router/deprecated.ts @@ -1,4 +1,5 @@ -import VueRouter, { RouteConfig, Route, Location, RouteMeta } from 'vue-router' +import { RouteConfig, Route, Location, RouteMeta } from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import { createLocationSpaces } from './spaces' import { createLocationShares } from './shares' import { createLocationCommon } from './common' @@ -100,7 +101,7 @@ export const buildRoutes = (): RouteConfig[] => * @param comparatives */ export const isLocationActive = ( - router: VueRouter, + router: Router, ...comparatives: [Location, ...Location[]] ): boolean => { const [first, ...rest] = comparatives.map((c) => { diff --git a/packages/web-app-files/src/router/utils.ts b/packages/web-app-files/src/router/utils.ts index fb05096d6fc..5ec59f08711 100644 --- a/packages/web-app-files/src/router/utils.ts +++ b/packages/web-app-files/src/router/utils.ts @@ -1,8 +1,9 @@ -import VueRouter, { Location } from 'vue-router' +import { Location } from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import merge from 'lodash-es/merge' export interface ActiveRouteDirectorFunc { - (router: VueRouter, ...comparatives: T[]): boolean + (router: Router, ...comparatives: T[]): boolean } /** @@ -13,7 +14,7 @@ export interface ActiveRouteDirectorFunc { * @param comparatives */ export const isLocationActive = ( - router: VueRouter, + router: Router, ...comparatives: [Location, ...Location[]] ): boolean => { const { href: currentHref } = router.resolve(router.currentRoute) @@ -47,7 +48,7 @@ export const isLocationActive = ( export const isLocationActiveDirector = ( ...defaultComparatives: [Location, ...Location[]] ): ActiveRouteDirectorFunc => { - return (router: VueRouter, ...comparatives: T[]): boolean => { + return (router: Router, ...comparatives: T[]): boolean => { if (!comparatives.length) { return isLocationActive(router, ...defaultComparatives) } diff --git a/packages/web-app-files/src/search/sdk/index.ts b/packages/web-app-files/src/search/sdk/index.ts index 14efc43f8a3..888cddbf473 100644 --- a/packages/web-app-files/src/search/sdk/index.ts +++ b/packages/web-app-files/src/search/sdk/index.ts @@ -3,7 +3,7 @@ import Preview from './preview' import List from './list' import { EventBus } from 'web-pkg/src/services/eventBus' import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' function $gettext(msg) { return msg @@ -14,9 +14,9 @@ export default class Provider extends EventBus implements SearchProvider { public readonly previewSearch: SearchPreview public readonly listSearch: SearchList private readonly store: Store - private readonly router: VueRouter + private readonly router: Router - constructor(store: Store, router: VueRouter) { + constructor(store: Store, router: Router) { super() this.id = 'files.sdk' diff --git a/packages/web-app-files/src/search/sdk/preview.ts b/packages/web-app-files/src/search/sdk/preview.ts index 5ebbffa6c33..2c7d31ec2d4 100644 --- a/packages/web-app-files/src/search/sdk/preview.ts +++ b/packages/web-app-files/src/search/sdk/preview.ts @@ -4,7 +4,7 @@ import { clientService } from 'web-pkg/src/services' import { buildResource } from 'web-client/src/helpers' import { Cache } from 'web-pkg/src/helpers/cache' import { Component } from 'vue' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import { DavProperties } from 'web-client/src/webdav/constants' import { Store } from 'vuex' @@ -13,10 +13,10 @@ export const previewSearchLimit = 8 export default class Preview implements SearchPreview { public readonly component: Component private readonly cache: Cache - private readonly router: VueRouter + private readonly router: Router private readonly store: Store - constructor(store: Store, router: VueRouter) { + constructor(store: Store, router: Router) { this.component = PreviewComponent this.router = router this.store = store diff --git a/packages/web-app-files/tests/unit/components/Search/List.spec.ts b/packages/web-app-files/tests/unit/components/Search/List.spec.ts index fa77aefca12..0b167d11d51 100644 --- a/packages/web-app-files/tests/unit/components/Search/List.spec.ts +++ b/packages/web-app-files/tests/unit/components/Search/List.spec.ts @@ -1,5 +1,4 @@ import { describe } from '@jest/globals' -// import VueRouter from 'vue-router' // import List from 'web-app-files/src/components/Search/List.vue' // // const stubs = { @@ -98,7 +97,6 @@ describe('List component', () => { // } // }, // store: createStore(files), -// router: new VueRouter(), // stubs, // mock: { // webdav: { diff --git a/packages/web-app-files/tests/unit/router/utils.spec.ts b/packages/web-app-files/tests/unit/router/utils.spec.ts index 234a8449d16..627f4c40d51 100644 --- a/packages/web-app-files/tests/unit/router/utils.spec.ts +++ b/packages/web-app-files/tests/unit/router/utils.spec.ts @@ -3,18 +3,19 @@ import { isLocationActiveDirector, createLocation } from '../../../src/router/utils' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' +import { mock } from 'jest-mock-extended' describe('utils', () => { describe('isLocationActive', () => { it('returns true if one location is active', () => { - const fakeRouter = { + const fakeRouter = mock({ currentRoute: { name: 'foo' }, resolve: (r) => ({ href: r.name }) - } + }) - expect(isLocationActive(fakeRouter as VueRouter, { name: 'foo' })).toBe(true) - expect(isLocationActive(fakeRouter as VueRouter, { name: 'foo' }, { name: 'bar' })).toBe(true) + expect(isLocationActive(fakeRouter, { name: 'foo' })).toBe(true) + expect(isLocationActive(fakeRouter, { name: 'foo' }, { name: 'bar' })).toBe(true) }) it('returns false if all locations inactive', () => { @@ -23,8 +24,8 @@ describe('utils', () => { resolve: (r) => ({ href: r.name }) } - expect(isLocationActive(fakeRouter as VueRouter, { name: 'bar' })).toBe(false) - expect(isLocationActive(fakeRouter as VueRouter, { name: 'bar' }, { name: 'baz' })).toBe( + expect(isLocationActive(fakeRouter, { name: 'bar' })).toBe(false) + expect(isLocationActive(fakeRouter, { name: 'bar' }, { name: 'baz' })).toBe( false ) }) @@ -32,32 +33,32 @@ describe('utils', () => { describe('isLocationActiveDirector', () => { test('director can be created and be used to check active locations', () => { - const fakeRouter = { + const fakeRouter = mock({ currentRoute: { name: 'unknown' }, resolve: (r) => ({ href: r.name }) - } + }) const isFilesLocationActive = isLocationActiveDirector( { name: 'foo' }, { name: 'bar' }, { name: 'baz' } ) - expect(isFilesLocationActive(fakeRouter as VueRouter)).toBe(false) + expect(isFilesLocationActive(fakeRouter)).toBe(false) fakeRouter.currentRoute.name = 'bar' - expect(isFilesLocationActive(fakeRouter as VueRouter)).toBe(true) - expect(isFilesLocationActive(fakeRouter as VueRouter, 'foo', 'bar')).toBe(true) + expect(isFilesLocationActive(fakeRouter)).toBe(true) + expect(isFilesLocationActive(fakeRouter, 'foo', 'bar')).toBe(true) }) test('director closure only allows to check known locations and throws if unknown', () => { - const fakeRouter = { + const fakeRouter = mock({ currentRoute: { name: 'baz' }, resolve: (r) => ({ href: r.name }) - } + }) const isFilesLocationActive = isLocationActiveDirector({ name: 'foo' }, { name: 'bar' }) - expect(() => isFilesLocationActive(fakeRouter as VueRouter, 'unknown')).toThrow() + expect(() => isFilesLocationActive(fakeRouter, 'unknown')).toThrow() }) }) diff --git a/packages/web-app-files/tests/unit/search/sdk.spec.ts b/packages/web-app-files/tests/unit/search/sdk.spec.ts index ac0ee5f9a08..a5e316b99ab 100644 --- a/packages/web-app-files/tests/unit/search/sdk.spec.ts +++ b/packages/web-app-files/tests/unit/search/sdk.spec.ts @@ -1,8 +1,8 @@ import { SDKSearch } from '../../../src/search' import { clientService } from 'web-pkg/src/services' import { Store } from 'vuex' -import VueRouter from 'vue-router' -import { mockDeep } from 'jest-mock-extended' +import { Router } from 'web-pkg/src/types/router' +import { mock, mockDeep } from 'jest-mock-extended' const searchMock = jest.fn() jest.spyOn(clientService, 'owncloudSdk', 'get').mockImplementation( @@ -35,7 +35,7 @@ const storeWithoutFileSearch = mockDeep>({ describe('SDKProvider', () => { it('is only available if announced via capabilities', () => { - const search = new SDKSearch(storeWithoutFileSearch, {} as unknown as VueRouter) + const search = new SDKSearch(storeWithoutFileSearch, mock()) expect(search.available).toBe(false) }) @@ -48,14 +48,14 @@ describe('SDKProvider', () => { ].forEach((v) => { const search = new SDKSearch(store, { currentRoute: { name: v.route } - } as unknown as VueRouter) + } as unknown as Router) expect(!!search.previewSearch.available).toBe(!!v.available) }) }) it('can search', async () => { - const search = new SDKSearch(store, jest.fn() as unknown as VueRouter) + const search = new SDKSearch(store, mock()) const files = [ { id: 'foo', name: 'foo' }, { id: 'bar', name: 'bar' }, @@ -75,7 +75,7 @@ describe('SDKProvider', () => { }) describe('SDKProvider listSearch', () => { it('can search', async () => { - const search = new SDKSearch(store, jest.fn() as unknown as VueRouter) + const search = new SDKSearch(store, mock()) const files = [ { id: 'foo', name: 'foo' }, { id: 'bar', name: 'bar' }, diff --git a/packages/web-pkg/package.json b/packages/web-pkg/package.json index 0c8913a56e7..9a1a9e9d8af 100644 --- a/packages/web-pkg/package.json +++ b/packages/web-pkg/package.json @@ -11,7 +11,7 @@ "luxon": "^2.4.0", "qs": "^6.10.3", "uuid": "^9.0.0", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vuex": "4.1.0", "web-client": "npm:@ownclouders/web-client", "web-pkg": "npm:@ownclouders/web-pkg" diff --git a/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts b/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts index 1bfd72ec3de..e4e4eeb4444 100644 --- a/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts +++ b/packages/web-pkg/src/composables/appDefaults/useAppNavigation.ts @@ -1,5 +1,6 @@ import { unref } from 'vue' -import VueRouter, { Location } from 'vue-router' +import { Location } from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import { MaybeRef } from '../../utils' import { FileContext } from './types' @@ -8,7 +9,7 @@ import { Resource } from 'web-client' import { useFileRouteReplace } from '../router/useFileRouteReplace' interface AppNavigationOptions { - router: VueRouter + router: Router currentFileContext: MaybeRef } diff --git a/packages/web-pkg/src/composables/router/useActiveApp.ts b/packages/web-pkg/src/composables/router/useActiveApp.ts index 4b3fbff4b59..4f35b7f82c7 100644 --- a/packages/web-pkg/src/composables/router/useActiveApp.ts +++ b/packages/web-pkg/src/composables/router/useActiveApp.ts @@ -1,6 +1,5 @@ import { computed, ComputedRef, unref } from 'vue' -import { useRoute } from './useRoute' -import { Route } from 'vue-router' +import { useRoute } from 'vue-router' export const activeApp = (route: Route): string => { return route.path.split('/')[1] diff --git a/packages/web-pkg/src/composables/router/useRouteMeta.ts b/packages/web-pkg/src/composables/router/useRouteMeta.ts index eb57fd45cbb..f258a49b9e2 100644 --- a/packages/web-pkg/src/composables/router/useRouteMeta.ts +++ b/packages/web-pkg/src/composables/router/useRouteMeta.ts @@ -1,7 +1,7 @@ import { computed, Ref, unref } from 'vue' -import { useRoute } from './useRoute' +import { useRoute } from 'vue-router' export const useRouteMeta = (key: string, defaultValue?: string): Ref => { const route = useRoute() - return computed(() => unref(route).meta[key] || defaultValue) + return computed(() => unref(route).meta[key] as string || defaultValue) } diff --git a/packages/web-pkg/src/composables/router/useRouteParam.ts b/packages/web-pkg/src/composables/router/useRouteParam.ts index 4be616d21b6..af284edc878 100644 --- a/packages/web-pkg/src/composables/router/useRouteParam.ts +++ b/packages/web-pkg/src/composables/router/useRouteParam.ts @@ -1,4 +1,4 @@ -import { customRef, Ref } from 'vue' +import { customRef, Ref, unref } from 'vue' import { useRouter } from './useRouter' import { ParamValue } from './types' @@ -11,15 +11,16 @@ export const useRouteParam = (name: string, defaultValue?: ParamValue): Ref { +export const useRouter = (): Router => { const hack = (window as any).__HACK__router if (hack) { return hack diff --git a/packages/web-pkg/src/index.ts b/packages/web-pkg/src/index.ts index 0062a8eea8d..4082c482d81 100644 --- a/packages/web-pkg/src/index.ts +++ b/packages/web-pkg/src/index.ts @@ -5,4 +5,5 @@ export * from './helpers' export * from './http' export * from './observer' export * from './services' +export * from './types' export * from './utils' diff --git a/packages/web-pkg/src/types/index.ts b/packages/web-pkg/src/types/index.ts new file mode 100644 index 00000000000..398cae73496 --- /dev/null +++ b/packages/web-pkg/src/types/index.ts @@ -0,0 +1 @@ +export * from './router' diff --git a/packages/web-pkg/src/types/router.ts b/packages/web-pkg/src/types/router.ts new file mode 100644 index 00000000000..20dd41553be --- /dev/null +++ b/packages/web-pkg/src/types/router.ts @@ -0,0 +1,3 @@ +import { createRouter } from 'vue-router' + +export type Router = ReturnType diff --git a/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts b/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts index 7c743d4a511..d526620c70c 100644 --- a/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts +++ b/packages/web-pkg/tests/unit/composables/router/useRouter.spec.ts @@ -1,5 +1,5 @@ import { useRouter } from 'web-pkg/src/composables' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import { createRouter, getComposableWrapper } from 'web-test-helpers' describe('useRouter', () => { @@ -10,7 +10,7 @@ describe('useRouter', () => { const mocks = { $router: router } getComposableWrapper( () => { - expect(useRouter()).toBeInstanceOf(VueRouter) + expect(useRouter()).toBeInstanceOf(Router) }, { mocks } ) diff --git a/packages/web-runtime/package.json b/packages/web-runtime/package.json index 95ed4d375d5..e8d0fc14c5f 100644 --- a/packages/web-runtime/package.json +++ b/packages/web-runtime/package.json @@ -43,7 +43,7 @@ "vue-gettext": "2.1.12", "vue-inline-svg": "3.1.0", "vue-meta": "^2.2.2", - "vue-router": "3.6.5", + "vue-router": "4.1.6", "vue-select": "4.0.0-beta.6", "vuex": "4.1.0", "vuex-router-sync": "^5.0.0", diff --git a/packages/web-runtime/src/App.vue b/packages/web-runtime/src/App.vue index b2db66d97a4..3f78be2a0fa 100644 --- a/packages/web-runtime/src/App.vue +++ b/packages/web-runtime/src/App.vue @@ -104,18 +104,18 @@ export default defineComponent({ } }, watch: { - $route: { - immediate: true, - handler: function (to) { - const extracted = this.extractPageTitleFromRoute(to) - if (!extracted) { - return - } - const { shortDocumentTitle, fullDocumentTitle } = extracted - this.announceRouteChange(shortDocumentTitle) - document.title = fullDocumentTitle - } - }, + // $route: { + // immediate: true, + // handler: function (to) { + // const extracted = this.extractPageTitleFromRoute(to) + // if (!extracted) { + // return + // } + // const { shortDocumentTitle, fullDocumentTitle } = extracted + // this.announceRouteChange(shortDocumentTitle) + // document.title = fullDocumentTitle + // } + // }, capabilities: { immediate: true, handler: function (caps) { diff --git a/packages/web-runtime/src/components/Topbar/TopBar.vue b/packages/web-runtime/src/components/Topbar/TopBar.vue index 9f0f1cc8309..a4fda8589eb 100644 --- a/packages/web-runtime/src/components/Topbar/TopBar.vue +++ b/packages/web-runtime/src/components/Topbar/TopBar.vue @@ -57,7 +57,7 @@ export default { ...mapGetters(['configuration', 'user']), activeRoutePath() { - return this.$router.resolve(this.$route).location.path + return this.$router.resolve(this.$route).path }, appMenuItems() { diff --git a/packages/web-runtime/src/container/api.ts b/packages/web-runtime/src/container/api.ts index b9e4ff2ddb0..0a640968b17 100644 --- a/packages/web-runtime/src/container/api.ts +++ b/packages/web-runtime/src/container/api.ts @@ -1,4 +1,5 @@ -import VueRouter, { RouteConfig } from 'vue-router' +import { RouteConfig } from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import clone from 'lodash-es/clone' import { RuntimeApi, @@ -18,7 +19,7 @@ import { App, Component, h } from 'vue' * @param router * @param routes */ -const announceRoutes = (applicationId: string, router: VueRouter, routes: RouteConfig[]): void => { +const announceRoutes = (applicationId: string, router: Router, routes: RouteConfig[]): void => { if (!isArray(routes)) { throw new ApiError("routes can't be blank") } @@ -205,7 +206,7 @@ const requestStore = (store: Store): Store => { * * @param router */ -const requestRouter = (router: VueRouter): VueRouter => { +const requestRouter = (router: Router): Router => { if (isEqual(process.env.NODE_ENV, 'development')) { console.warn('requestRouter // router api is deprecated, use with caution') } @@ -238,7 +239,7 @@ export const buildRuntimeApi = ({ applicationId: string store: Store translations: unknown - router: VueRouter + router: Router supportedLanguages: { [key: string]: string } }): RuntimeApi => { if (!applicationName) { @@ -262,7 +263,7 @@ export const buildRuntimeApi = ({ announceExtension: (extension: { [key: string]: unknown }): void => announceExtension(applicationId, store, extension), requestStore: (): Store => requestStore(store), - requestRouter: (): VueRouter => requestRouter(router), + requestRouter: (): Router => requestRouter(router), openPortal: ( instance: App, toApp: string, diff --git a/packages/web-runtime/src/container/application/classic.ts b/packages/web-runtime/src/container/application/classic.ts index 4f8e18da68c..9dbb4a8c009 100644 --- a/packages/web-runtime/src/container/application/classic.ts +++ b/packages/web-runtime/src/container/application/classic.ts @@ -4,7 +4,7 @@ import Vue, { App } from 'vue' import { isFunction, isObject } from 'lodash-es' import { NextApplication } from './next' import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import { RuntimeError } from '../error' type VueConstructor = typeof Vue @@ -78,7 +78,7 @@ export const convertClassicApplication = async ({ }: { applicationScript: ClassicApplicationScript store: Store - router: VueRouter + router: Router translations: unknown supportedLanguages: { [key: string]: string } }): Promise => { diff --git a/packages/web-runtime/src/container/application/index.ts b/packages/web-runtime/src/container/application/index.ts index 9afc1e9842a..43ad46a5b2c 100644 --- a/packages/web-runtime/src/container/application/index.ts +++ b/packages/web-runtime/src/container/application/index.ts @@ -1,5 +1,5 @@ import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import { NextApplication } from './next' import { convertClassicApplication } from './classic' import { ClassicApplicationScript } from '../types' @@ -54,7 +54,7 @@ export const buildApplication = async ({ }: { applicationPath: string store: Store - router: VueRouter + router: Router translations: unknown supportedLanguages: { [key: string]: string } configurationManager: ConfigurationManager diff --git a/packages/web-runtime/src/container/bootstrap.ts b/packages/web-runtime/src/container/bootstrap.ts index 544bee7438c..722076ab4bc 100644 --- a/packages/web-runtime/src/container/bootstrap.ts +++ b/packages/web-runtime/src/container/bootstrap.ts @@ -2,7 +2,7 @@ import { registerClient } from '../services/clientRegistration' import { RuntimeConfiguration } from './types' import { buildApplication, NextApplication } from './application' import { Store } from 'vuex' -import VueRouter from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import Vue from 'vue' import { loadTheme } from '../helpers/theme' import OwnCloud from 'owncloud-sdk' @@ -121,7 +121,7 @@ export const initializeApplications = async ({ runtimeConfiguration: RuntimeConfiguration configurationManager: ConfigurationManager store: Store - router: VueRouter + router: Router translations: unknown supportedLanguages: { [key: string]: string } }): Promise => { @@ -325,7 +325,7 @@ export const announceAuthService = ({ vue: VueConstructor configurationManager: ConfigurationManager store: Store - router: VueRouter + router: Router }): void => { authService.initialize(configurationManager, clientService, store, router) vue.prototype.$authService = authService @@ -344,7 +344,7 @@ export const announceDefaults = ({ router }: { store: Store - router: VueRouter + router: Router }): void => { // set home route const appIds = store.getters.appIds diff --git a/packages/web-runtime/src/container/types.ts b/packages/web-runtime/src/container/types.ts index a10ac590755..c3cec8bd1d7 100644 --- a/packages/web-runtime/src/container/types.ts +++ b/packages/web-runtime/src/container/types.ts @@ -1,5 +1,6 @@ import { Store } from 'vuex' -import VueRouter, { RouteConfig } from 'vue-router' +import { RouteConfig } from 'vue-router' +import { Router } from 'web-pkg/src/types/router' import Vue, { Component } from 'vue' /** shim configuration for now, should be typed in a later step */ @@ -83,7 +84,7 @@ export interface RuntimeApi { announceStore: (applicationStore: Store) => void announceExtension: (extension: { [key: string]: unknown }) => void requestStore: () => Store - requestRouter: () => VueRouter + requestRouter: () => Router openPortal: ( instance: typeof Vue.prototype, toApp: string, diff --git a/packages/web-runtime/src/defaults/vue.js b/packages/web-runtime/src/defaults/vue.js index f3728b95861..25cd87891f6 100644 --- a/packages/web-runtime/src/defaults/vue.js +++ b/packages/web-runtime/src/defaults/vue.js @@ -4,11 +4,9 @@ import Avatar from '../components/Avatar.vue' import focusMixin from '../mixins/focusMixin' import lifecycleMixin from '../mixins/lifecycleMixin' import VueMeta from 'vue-meta' -import VueRouter from 'vue-router' import Vuex from 'vuex' Vue.use(Vuex) -Vue.use(VueRouter) Vue.use(WebPlugin) Vue.use(VueMeta, { refreshOnceOnNavigation: true diff --git a/packages/web-runtime/src/index.ts b/packages/web-runtime/src/index.ts index a3491f89516..1b1b3372b72 100644 --- a/packages/web-runtime/src/index.ts +++ b/packages/web-runtime/src/index.ts @@ -64,13 +64,12 @@ export const bootstrap = async (configurationPath: string): Promise => { announceDefaults({ store, router }) } -export const renderSuccess = (): void => { +export const renderSuccess = async (): Promise => { Vue.prototype.$store = store const applications = Array.from(applicationStore.values()) const instance = createApp({ store, - router, render() { return h(pages.success) } @@ -82,6 +81,9 @@ export const renderSuccess = (): void => { wormhole: instance.config.globalProperties.$wormhole }) + // install router instance + instance.use(router) + // mount App instance.mount('#owncloud') applications.forEach((application) => application.mounted(instance)) diff --git a/packages/web-runtime/src/layouts/Application.vue b/packages/web-runtime/src/layouts/Application.vue index bfc10c05898..258a8a4187b 100644 --- a/packages/web-runtime/src/layouts/Application.vue +++ b/packages/web-runtime/src/layouts/Application.vue @@ -59,8 +59,8 @@ export default defineComponent({ watch( useRoute(), (route) => { - if (route.matched.length) { - route.matched.forEach((match) => { + if (unref(route).matched.length) { + unref(route).matched.forEach((match) => { const keys = Object.keys(match.components).filter((key) => key !== 'default') if (keys.length) { console.warn( diff --git a/packages/web-runtime/src/pages/oidcCallback.vue b/packages/web-runtime/src/pages/oidcCallback.vue index fb798d86aa9..ab29971bdee 100644 --- a/packages/web-runtime/src/pages/oidcCallback.vue +++ b/packages/web-runtime/src/pages/oidcCallback.vue @@ -17,8 +17,9 @@