refactor: move globals declaration

Signed-off-by: Varun Patil <radialapps@gmail.com>
pull/877/head
Varun Patil 2023-10-13 12:22:15 -07:00
parent 43d3668119
commit d6e108831e
4 changed files with 101 additions and 102 deletions

View File

@ -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<void>;
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<void>;
openStatic(photo: IPhoto, list: IPhoto[], thumbSize?: 256 | 512): Promise<void>;
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',

View File

@ -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;

100
src/globals.d.ts vendored 100644
View File

@ -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<void>;
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<void>;
openStatic(photo: IPhoto, list: IPhoto[], thumbSize?: 256 | 512): Promise<void>;
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 {};

32
src/vue-globals.d.ts vendored
View File

@ -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 {};