From d6e108831ee7b264d3f36cbe446622e52cea5647 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Fri, 13 Oct 2023 12:22:15 -0700 Subject: [PATCH] refactor: move globals declaration Signed-off-by: Varun Patil --- src/bootstrap.ts | 69 --------------------- src/components/viewer/Viewer.vue | 2 +- src/globals.d.ts | 100 +++++++++++++++++++++++++++++++ src/vue-globals.d.ts | 32 ---------- 4 files changed, 101 insertions(+), 102 deletions(-) create mode 100644 src/globals.d.ts delete mode 100644 src/vue-globals.d.ts diff --git a/src/bootstrap.ts b/src/bootstrap.ts index fa995526..d6806928 100644 --- a/src/bootstrap.ts +++ b/src/bootstrap.ts @@ -13,81 +13,12 @@ import VueVirtualScroller from 'vue-virtual-scroller'; // Locals import router from './router'; -// Types -import type { Route } from 'vue-router'; -import type { IPhoto, IRow } from './types'; -import type PlyrType from 'plyr'; -import type videojsType from 'video.js'; - // CSS for components import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'; // Global CSS import './styles/global.scss'; -// Global exposed variables -declare global { - var __webpack_nonce__: string; - var __webpack_public_path__: string; - - var OC: Nextcloud.Common.OC; - var OCP: Nextcloud.Common.OCP; - var OCA: { - Files?: { - Sidebar?: any; - App?: any; - }; - Theming?: { - name: string; - enabledThemes: any[]; - }; - }; - - var _m: { - mode: 'admin' | 'user'; - route: Route; - - modals: { - editMetadata: (photos: IPhoto[], sections?: number[]) => void; - updateAlbums: (photos: IPhoto[]) => void; - sharePhoto: (photo: IPhoto) => void; - shareNodeLink: (path: string, immediate?: boolean) => Promise; - moveToFolder: (photos: IPhoto[]) => void; - moveToFace: (photos: IPhoto[]) => void; - showSettings: () => void; - }; - - sidebar: { - open: (photo: IPhoto | number, filename?: string, forceNative?: boolean) => void; - close: () => void; - setTab: (tab: string) => void; - getWidth: () => number; - }; - - viewer: { - open: (anchorPhoto: IPhoto, rows: IRow[]) => Promise; - openStatic(photo: IPhoto, list: IPhoto[], thumbSize?: 256 | 512): Promise; - close: () => void; - isOpen: boolean; - currentPhoto: IPhoto | null; - }; - - video: { - videojs: typeof videojsType; - Plyr: typeof PlyrType; - clientId: string; - clientIdPersistent: string; - }; - - window: { - innerWidth: number; // cache - innerHeight: number; // cache - }; - - photoswipe?: unknown; // debugging only - }; -} - // Initialize global memories object globalThis._m = { mode: 'user', diff --git a/src/components/viewer/Viewer.vue b/src/components/viewer/Viewer.vue index a0b48546..f63e7595 100644 --- a/src/components/viewer/Viewer.vue +++ b/src/components/viewer/Viewer.vue @@ -490,7 +490,7 @@ export default defineComponent({ }); // Debugging only - _m.photoswipe = this.photoswipe; + _m.viewer.photoswipe = this.photoswipe; // Monkey patch for focus trapping in sidebar const psKeyboard = this.photoswipe.keyboard as any; diff --git a/src/globals.d.ts b/src/globals.d.ts new file mode 100644 index 00000000..6fc1d456 --- /dev/null +++ b/src/globals.d.ts @@ -0,0 +1,100 @@ +import type { Route } from 'vue-router'; +import type { translate, translatePlural } from '@nextcloud/l10n'; +import type PlyrType from 'plyr'; +import type videojsType from 'video.js'; + +import type { IPhoto, IRow } from './types'; +import type { c, initState } from './services/utils'; + +// Global exposed variables +declare global { + var __webpack_nonce__: string; + var __webpack_public_path__: string; + + var OC: Nextcloud.Common.OC; + var OCP: Nextcloud.Common.OCP; + var OCA: { + Files?: { + Sidebar?: any; + App?: any; + }; + Theming?: { + name: string; + enabledThemes: any[]; + }; + }; + + /** Global Memories object. Initialized in src/bootstrap.ts */ + var _m: { + mode: 'admin' | 'user'; + route: Route; + + modals: { + editMetadata: (photos: IPhoto[], sections?: number[]) => void; + updateAlbums: (photos: IPhoto[]) => void; + sharePhoto: (photo: IPhoto) => void; + shareNodeLink: (path: string, immediate?: boolean) => Promise; + moveToFolder: (photos: IPhoto[]) => void; + moveToFace: (photos: IPhoto[]) => void; + showSettings: () => void; + }; + + sidebar: { + open: (photo: IPhoto | number, filename?: string, forceNative?: boolean) => void; + close: () => void; + setTab: (tab: string) => void; + getWidth: () => number; + }; + + viewer: { + open: (anchorPhoto: IPhoto, rows: IRow[]) => Promise; + openStatic(photo: IPhoto, list: IPhoto[], thumbSize?: 256 | 512): Promise; + close: () => void; + isOpen: boolean; + currentPhoto: IPhoto | null; + photoswipe?: unknown; // debugging only + }; + + video: { + videojs: typeof videojsType; + Plyr: typeof PlyrType; + clientId: string; + clientIdPersistent: string; + }; + + window: { + innerWidth: number; // cache + innerHeight: number; // cache + }; + }; +} + +// GlobalMixin.ts types, present on all components +declare module 'vue' { + interface ComponentCustomProperties { + t: typeof translate; + n: typeof translatePlural; + + c: typeof c; + initState: typeof initState; + + routeIsBase: boolean; + routeIsFavorites: boolean; + routeIsVideos: boolean; + routeIsFolders: boolean; + routeIsAlbums: boolean; + routeIsPeople: boolean; + routeIsRecognize: boolean; + routeIsRecognizeUnassigned: boolean; + routeIsFaceRecognition: boolean; + routeIsArchive: boolean; + routeIsPlaces: boolean; + routeIsMap: boolean; + routeIsTags: boolean; + routeIsExplore: boolean; + routeIsAlbumShare: boolean; + routeIsPublic: boolean; + } +} + +export {}; diff --git a/src/vue-globals.d.ts b/src/vue-globals.d.ts deleted file mode 100644 index f9168546..00000000 --- a/src/vue-globals.d.ts +++ /dev/null @@ -1,32 +0,0 @@ -import type { c, initState } from './services/utils'; -import type { translate, translatePlural } from '@nextcloud/l10n'; - -declare module 'vue' { - interface ComponentCustomProperties { - // GlobalMixin.ts - t: typeof translate; - n: typeof translatePlural; - - c: typeof c; - initState: typeof initState; - - routeIsBase: boolean; - routeIsFavorites: boolean; - routeIsVideos: boolean; - routeIsFolders: boolean; - routeIsAlbums: boolean; - routeIsPeople: boolean; - routeIsRecognize: boolean; - routeIsRecognizeUnassigned: boolean; - routeIsFaceRecognition: boolean; - routeIsArchive: boolean; - routeIsPlaces: boolean; - routeIsMap: boolean; - routeIsTags: boolean; - routeIsExplore: boolean; - routeIsAlbumShare: boolean; - routeIsPublic: boolean; - } -} - -export {};