|
| 1 | +--- |
| 2 | +outline: deep |
| 3 | +--- |
| 4 | + |
| 5 | +# Assets |
| 6 | + |
| 7 | +Browse, preview, upload, rename, and delete the files in a directory, built as a **Preact** SPA — a framework-neutral port of Nuxt DevTools' Assets tab. |
| 8 | + |
| 9 | +Package: `@devframes/plugin-assets` · framework: **Preact** |
| 10 | + |
| 11 | +## What it does |
| 12 | + |
| 13 | +Search and filter by extension, switch between a thumbnail grid (grouped by folder) and a file tree, and open a details panel with a live preview (image, video, audio, font, or text), file metadata, and ready-to-copy usage snippets (`<img>`, CSS `background-image`, `@font-face`, a download link). Drag-and-drop files to upload them, or select multiple assets to delete them together. A live file watcher keeps every connected client's listing in sync with changes made outside the UI. |
| 14 | + |
| 15 | +The standalone server requires devframe's trust handshake by default because it can read, write, and delete real files. Uploads, renames, deletes, and folder creation are enabled by default — pass `{ write: false }` (or `--read-only` on the standalone CLI) for a browse-only deployment. |
| 16 | + |
| 17 | +## Standalone |
| 18 | + |
| 19 | +```sh |
| 20 | +pnpx @devframes/plugin-assets # manages <cwd>/public |
| 21 | +pnpx @devframes/plugin-assets --read-only # disable upload / rename / delete / mkdir |
| 22 | +``` |
| 23 | + |
| 24 | +## Mount into a Vite host |
| 25 | + |
| 26 | +```ts |
| 27 | +// vite.config.ts |
| 28 | +import { assetsVitePlugin } from '@devframes/plugin-assets/vite' |
| 29 | +import { defineConfig } from 'vite' |
| 30 | + |
| 31 | +export default defineConfig({ |
| 32 | + plugins: [ |
| 33 | + assetsVitePlugin(), |
| 34 | + ], |
| 35 | +}) |
| 36 | +``` |
| 37 | + |
| 38 | +## Programmatic |
| 39 | + |
| 40 | +`createAssetsDevframe(options)` returns a definition you can deploy through any adapter: |
| 41 | + |
| 42 | +```ts |
| 43 | +import { createAssetsDevframe } from '@devframes/plugin-assets' |
| 44 | + |
| 45 | +export default createAssetsDevframe({ |
| 46 | + dir: 'static', // defaults to `<cwd>/public` |
| 47 | + write: true, |
| 48 | + uploadExtensions: ['png', 'jpg', 'svg', 'webp'], // defaults to Nuxt DevTools' own allow-list, or '*' for any |
| 49 | +}) |
| 50 | +``` |
| 51 | + |
| 52 | +| Option | Default | Description | |
| 53 | +|--------|---------|-------------| |
| 54 | +| `dir` | `<cwd>/public` | Directory this devframe manages. | |
| 55 | +| `write` | `true` | Enable upload, rename, delete, and folder creation from the UI. | |
| 56 | +| `uploadExtensions` | Nuxt DevTools' allow-list | Extensions `upload` accepts, or `'*'` for any. | |
| 57 | +| `build` | `false` | Register the `build` CLI subcommand. See [why it's off by default](#static-export) below. | |
| 58 | + |
| 59 | +## RPC surface |
| 60 | + |
| 61 | +All functions are namespaced `devframes:plugin:assets:*`: |
| 62 | + |
| 63 | +| Function | Type | Notes | |
| 64 | +|----------|------|-------| |
| 65 | +| `list` | `query`, `snapshot: true` | Every file under the managed directory, with type, size, and last-modified time. | |
| 66 | +| `capabilities` | `query`, `snapshot: true` | Whether write actions are enabled, and the upload allow-list — lets the UI gate itself proactively. | |
| 67 | +| `read-image-meta` | `query` | Width, height, and orientation for an image asset. | |
| 68 | +| `read-text` | `query` | Truncated text content, for preview or editing. | |
| 69 | +| `upload` | `action` | Allocates a streaming upload slot; the client pipes the file's bytes over the paired channel. | |
| 70 | +| `rename` | `action` | Renames an asset within its folder, preserving its extension. | |
| 71 | +| `delete` | `action` | Deletes one or more assets in a single call. | |
| 72 | +| `mkdir` | `action` | Creates a folder, including missing parents. | |
| 73 | +| `write-text` | `action` | Overwrites a text asset's content in place (the details panel's inline editor). | |
| 74 | +| `open-in-editor` / `reveal-in-folder` | `action` | Launch the asset in your editor, or reveal its containing folder in the OS file manager. Always registered, regardless of `write`. | |
| 75 | + |
| 76 | +`upload` / `rename` / `delete` / `mkdir` / `write-text` are registered only when `write` is enabled. |
| 77 | + |
| 78 | +## Static export |
| 79 | + |
| 80 | +Every devframe's `build` CLI subcommand is disabled here by default (`capabilities: { build: false }`). Real byte serving for previews goes through `ctx.views.hostStatic()`, which only mounts real files under a live adapter (`cli` / `vite` / `embedded`) — a static export can never copy those bytes, and every write action is inherently excluded from a static dump. Rather than ship a broken, preview-less, write-less shell of the tool, the `build` command is simply not registered. Pass `{ build: true }` to `createAssetsDevframe()` (and `{ force: true }` if calling `createBuild()` directly) if that degraded export is still useful to you — the file listing itself still bakes into the static RPC dump. |
| 81 | + |
| 82 | +## Source |
| 83 | + |
| 84 | +[`plugins/assets`](https://github.com/devframes/devframe/tree/main/plugins/assets) |
0 commit comments