Apps
File manager
Nested folders, grid and list views, uploads with progress, drag to move, storage by kind and a file panel.
Folders nest through parentId. Files carry owner, sharedWith, createdAt, updatedBy and an optional previewUrl (uploaded images get an object URL, so they preview without a server).
Every app follows the same pattern: typed models in types/models/, demo data in mocks/, state and actions in a composable under composables/apps/, page-only components in components/pages/<app>/ and UI strings in locales/<code>/apps.json. Read the apps overview once and every app looks familiar.
Files
File | Role |
|---|---|
pages/file-manager.vue | The page: sidebar, browser and file panel. |
composables/apps/useFileManager.ts | Files, folders, filters, sorting, uploads and trash. |
types/models/files.ts | Files, folders and the provider. |
config/files.config.ts | Sections, file kinds, folder colours and the default view. |
utils/files.ts | Pure rules, unit tested. |
components/pages/file-manager/ | FileManagerSidebar, FileManagerBrowser, FileManagerFileCard, FileManagerFolderCard, FileManagerFilePanel, FileManagerUploads, FileManagerToolbar, FileManagerSelectionBar. |
Data and provider
export interface FilesProvider {
load: () => Promise<FileManagerState>
saveFile: (file: FileEntry) => Promise<void>
removeFile: (id: string) => Promise<void>
saveFolder: (folder: FileFolder) => Promise<void>
removeFolder: (id: string) => Promise<void>
}
Connect your backend
The page calls useFileManager() with the mock provider. Write a provider that calls your API with useApi() and pass it in the page. The composable loads it through useAsyncData and applies every change optimistically, so the interface does not wait for the server.
import type { FileManagerState, FilesProvider } from '~/types/models/files'
export function createFilesApiProvider(): FilesProvider {
const api = useApi()
return {
load: () => api<FileManagerState>('/files'),
saveFile: (file) => api(`/files/${file.id}`, { method: 'PUT', body: file }),
removeFile: (id) => api(`/files/${id}`, { method: 'DELETE' }),
saveFolder: (folder) => api(`/folders/${folder.id}`, { method: 'PUT', body: folder }),
removeFolder: (id) => api(`/folders/${id}`, { method: 'DELETE' }),
}
}
<script setup lang="ts">
import { createFilesApiProvider } from '~/providers/files'
const { ... } = useFileManager({ provider: createFilesApiProvider() })
</script>
Keep ids in your data and labels in the locales: folders, labels and tags resolve their names through apps.<app>.* unless you give them a raw title. See Connect your API for the token, validation errors and the actions the demo only fakes.
Configuration
FILE_SECTIONS
The sections of the sidebar.
const FILE_SECTIONS: FileSectionConfig[]
FILE_KINDS
File kinds with their extensions, icon and colour.
const FILE_KINDS: FileKindConfig[]
FILE_FOLDER_COLORS
The colours a folder can take.
const FILE_FOLDER_COLORS: string[]
FILE_DEFAULT_VIEW
grid or list. The user’s choice persists in the files-view cookie.
const FILE_DEFAULT_VIEW: FileViewSettings
FILE_RECENT_DAYS
How many days a file counts as recent.
const FILE_RECENT_DAYS: 7
FILE_UPLOAD_STEP_MS
The step of the simulated upload progress. Remove it when you upload for real.
const FILE_UPLOAD_STEP_MS: 120
Rules
Pure functions in utils/, unit tested. Use them in your backend too if you want the same answers.
fileKind()
The kind of a file.
fileKind(name: string, kinds: FileKindConfig[]): FileKind
matchesFileFilters()
Whether a file passes the filters.
matchesFileFilters(file: FileEntry, filters: FileFilters, kinds: FileKindConfig[], now: number, recentDays: number): boolean
sortFiles()
Sorts files.
sortFiles(files: FileEntry[], sort: FileSort): FileEntry[]
folderPath()
The breadcrumb of a folder.
folderPath(folders: FileFolder[], folderId: string | null): FileFolder[]
folderDescendants()
Every folder inside a folder.
folderDescendants(folders: FileFolder[], folderId: string): string[]
storageBreakdown()
Storage used by kind.
storageBreakdown(files: FileEntry[], quota: number, kinds: FileKindConfig[]): { used: number; quota: number; percent: number; kinds: { kind: FileKind; color: string; size: number; percent: number; }[]; }usedquotapercentkindsHow it works
- The page is a
BaseSplitViewwithfixed="detail": sections, root folders and storage innav, the browser inlistandFileManagerFilePanel(preview, rename, details, access and activity) indetail. - The browser has the path, search, kind and sort menus, a compact view toggle, a bulk bar, a drop zone, folder tiles and a grid or
BaseDataTablelist. - Cards can be dragged onto a folder to move them. Uploads show their progress in
FileManagerUploads. - Moving to the trash shows an undo toast; deleting a folder, deleting forever and emptying the trash confirm with
useConfirm().