filecove 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/LICENSE +21 -0
- package/README.md +65 -2
- package/THIRD_PARTY_NOTICES.md +63 -0
- package/dist/components/buttons/toolbar-actions.d.ts +28 -0
- package/dist/components/buttons/tooltip-icon-button.d.ts +14 -0
- package/dist/components/downloads/download-panel.d.ts +23 -0
- package/dist/components/drag/drag-preview.d.ts +24 -0
- package/dist/components/file-manager/announcer.d.ts +14 -0
- package/dist/components/file-manager/content/file-grid.d.ts +8 -0
- package/dist/components/file-manager/content/file-list.d.ts +9 -0
- package/dist/components/file-manager/content/folder-view.d.ts +83 -0
- package/dist/components/file-manager/content/item-icon.d.ts +16 -0
- package/dist/components/file-manager/content/no-sections.d.ts +11 -0
- package/dist/components/file-manager/content/search-results.d.ts +40 -0
- package/dist/components/file-manager/content/search-tabs.d.ts +29 -0
- package/dist/components/file-manager/content/trash-bar.d.ts +13 -0
- package/dist/components/file-manager/context-menu/context-menu.d.ts +20 -0
- package/dist/components/file-manager/dialogs/conflict-step.d.ts +28 -0
- package/dist/components/file-manager/dialogs/delete-dialog.d.ts +49 -0
- package/dist/components/file-manager/dialogs/image-viewer.d.ts +42 -0
- package/dist/components/file-manager/dialogs/name-dialog.d.ts +41 -0
- package/dist/components/file-manager/dialogs/paste-dialog.d.ts +39 -0
- package/dist/components/file-manager/dialogs/preview-dialog.d.ts +75 -0
- package/dist/components/file-manager/dialogs/restore-dialog.d.ts +41 -0
- package/dist/components/file-manager/dialogs/shortcuts-dialog.d.ts +36 -0
- package/dist/components/file-manager/dialogs/transfer-dialog.d.ts +71 -0
- package/dist/components/file-manager/dialogs/upload-dialog.d.ts +34 -0
- package/dist/components/file-manager/file-manager.d.ts +320 -0
- package/dist/components/file-manager/find-layer.d.ts +29 -0
- package/dist/components/file-manager/header-bar/header-bar.d.ts +65 -0
- package/dist/components/file-manager/header-bar/history-menu.d.ts +18 -0
- package/dist/components/file-manager/header-bar/path-bar.d.ts +19 -0
- package/dist/components/file-manager/header-bar/path-field.d.ts +23 -0
- package/dist/components/file-manager/header-bar/search-field.d.ts +27 -0
- package/dist/components/file-manager/header-bar/search-sections-menu.d.ts +25 -0
- package/dist/components/file-manager/header-bar/view-menu.d.ts +39 -0
- package/dist/components/file-manager/notice-bar.d.ts +36 -0
- package/dist/components/file-manager/properties-pane.d.ts +53 -0
- package/dist/components/file-manager/resize-edge.d.ts +39 -0
- package/dist/components/file-manager/selection-bar.d.ts +15 -0
- package/dist/components/file-manager/sidebar/location-item.d.ts +36 -0
- package/dist/components/file-manager/sidebar/main-menu.d.ts +23 -0
- package/dist/components/file-manager/sidebar/sidebar.d.ts +80 -0
- package/dist/components/icons/check-badge.d.ts +3 -0
- package/dist/components/icons/create-icon.d.ts +20 -0
- package/dist/components/icons/file-icon.d.ts +19 -0
- package/dist/components/icons/icon-provider.d.ts +21 -0
- package/dist/components/icons/icon-slot.d.ts +6 -0
- package/dist/components/icons/icon.d.ts +19 -0
- package/dist/components/icons/locked-icon.d.ts +9 -0
- package/dist/components/media-manager/asset-delete.d.ts +29 -0
- package/dist/components/media-manager/asset-hold.d.ts +32 -0
- package/dist/components/media-manager/asset-option.d.ts +74 -0
- package/dist/components/media-manager/asset-trail.d.ts +13 -0
- package/dist/components/media-manager/choice-list.d.ts +29 -0
- package/dist/components/media-manager/choices-pane.d.ts +50 -0
- package/dist/components/media-manager/choose-bar.d.ts +26 -0
- package/dist/components/media-manager/drop-zone.d.ts +7 -0
- package/dist/components/media-manager/group-check.d.ts +13 -0
- package/dist/components/media-manager/group-create.d.ts +20 -0
- package/dist/components/media-manager/group-path.d.ts +24 -0
- package/dist/components/media-manager/library-list.d.ts +23 -0
- package/dist/components/media-manager/media-asset.d.ts +65 -0
- package/dist/components/media-manager/media-edit-many.d.ts +33 -0
- package/dist/components/media-manager/media-fields.d.ts +31 -0
- package/dist/components/media-manager/media-filter-chips.d.ts +17 -0
- package/dist/components/media-manager/media-filters-dialog.d.ts +39 -0
- package/dist/components/media-manager/media-filters.d.ts +37 -0
- package/dist/components/media-manager/media-form.d.ts +29 -0
- package/dist/components/media-manager/media-frame.d.ts +77 -0
- package/dist/components/media-manager/media-grid.d.ts +114 -0
- package/dist/components/media-manager/media-group.d.ts +29 -0
- package/dist/components/media-manager/media-header.d.ts +80 -0
- package/dist/components/media-manager/media-manager.d.ts +309 -0
- package/dist/components/media-manager/media-move.d.ts +30 -0
- package/dist/components/media-manager/media-picker.d.ts +140 -0
- package/dist/components/media-manager/media-picture.d.ts +26 -0
- package/dist/components/media-manager/media-process.d.ts +26 -0
- package/dist/components/media-manager/media-row.d.ts +13 -0
- package/dist/components/media-manager/media-step.d.ts +33 -0
- package/dist/components/media-manager/media-tile.d.ts +15 -0
- package/dist/components/media-manager/media-upload.d.ts +46 -0
- package/dist/components/media-manager/open-button.d.ts +15 -0
- package/dist/components/media-manager/picker-frame.d.ts +33 -0
- package/dist/components/media-manager/selection-bar.d.ts +25 -0
- package/dist/components/media-manager/upload-tile.d.ts +17 -0
- package/dist/components/properties/properties-panel.d.ts +53 -0
- package/dist/components/properties/property-display.d.ts +15 -0
- package/dist/components/properties/property-editor.d.ts +26 -0
- package/dist/components/properties/property-input.d.ts +36 -0
- package/dist/components/transfers/transfer-panel.d.ts +25 -0
- package/dist/components/ui/backdrop.d.ts +7 -0
- package/dist/components/ui/button-base.d.ts +7 -0
- package/dist/components/ui/button.d.ts +18 -0
- package/dist/components/ui/checkbox.d.ts +24 -0
- package/dist/components/ui/chip.d.ts +18 -0
- package/dist/components/ui/circular-progress.d.ts +14 -0
- package/dist/components/ui/collapse.d.ts +9 -0
- package/dist/components/ui/dialog.d.ts +40 -0
- package/dist/components/ui/divider.d.ts +4 -0
- package/dist/components/ui/icon-button.d.ts +12 -0
- package/dist/components/ui/linear-progress.d.ts +13 -0
- package/dist/components/ui/link.d.ts +4 -0
- package/dist/components/ui/menu.d.ts +77 -0
- package/dist/components/ui/root-providers.d.ts +16 -0
- package/dist/components/ui/text-field.d.ts +38 -0
- package/dist/components/ui/text.d.ts +21 -0
- package/dist/components/ui/tooltip.d.ts +24 -0
- package/dist/components/uploads/upload-panel.d.ts +31 -0
- package/dist/contexts/asset-look-context.d.ts +1 -0
- package/dist/contexts/cut-context.d.ts +6 -0
- package/dist/contexts/data-context.d.ts +12 -0
- package/dist/contexts/direction-context.d.ts +2 -0
- package/dist/contexts/drag-context.d.ts +36 -0
- package/dist/contexts/icon-context.d.ts +10 -0
- package/dist/contexts/locale-context.d.ts +2 -0
- package/dist/contexts/moving-context.d.ts +7 -0
- package/dist/create-icon-D2vnnBQX.js +40 -0
- package/dist/create-icon-D2vnnBQX.js.map +1 -0
- package/dist/hooks/use-announcer.d.ts +20 -0
- package/dist/hooks/use-asset-look.d.ts +6 -0
- package/dist/hooks/use-asset-states.d.ts +12 -0
- package/dist/hooks/use-chosen-column.d.ts +16 -0
- package/dist/hooks/use-clipboard-follow.d.ts +12 -0
- package/dist/hooks/use-controlled.d.ts +18 -0
- package/dist/hooks/use-cut-ids.d.ts +3 -0
- package/dist/hooks/use-dev-checks.d.ts +16 -0
- package/dist/hooks/use-download-queue.d.ts +19 -0
- package/dist/hooks/use-dragged-ids.d.ts +3 -0
- package/dist/hooks/use-drop-target.d.ts +48 -0
- package/dist/hooks/use-entry-drag.d.ts +46 -0
- package/dist/hooks/use-files-drop.d.ts +20 -0
- package/dist/hooks/use-folder.d.ts +14 -0
- package/dist/hooks/use-fork-ref.d.ts +6 -0
- package/dist/hooks/use-form-send.d.ts +12 -0
- package/dist/hooks/use-found.d.ts +10 -0
- package/dist/hooks/use-icon-config.d.ts +2 -0
- package/dist/hooks/use-level-filters.d.ts +112 -0
- package/dist/hooks/use-level-search.d.ts +21 -0
- package/dist/hooks/use-locale.d.ts +10 -0
- package/dist/hooks/use-location-history.d.ts +42 -0
- package/dist/hooks/use-long-press.d.ts +25 -0
- package/dist/hooks/use-marquee.d.ts +35 -0
- package/dist/hooks/use-match-count.d.ts +8 -0
- package/dist/hooks/use-media-search.d.ts +44 -0
- package/dist/hooks/use-moving-ids.d.ts +3 -0
- package/dist/hooks/use-picks.d.ts +39 -0
- package/dist/hooks/use-preview-contents.d.ts +33 -0
- package/dist/hooks/use-properties.d.ts +25 -0
- package/dist/hooks/use-scroll-measure.d.ts +34 -0
- package/dist/hooks/use-search.d.ts +12 -0
- package/dist/hooks/use-selection.d.ts +29 -0
- package/dist/hooks/use-setting.d.ts +21 -0
- package/dist/hooks/use-stable-set.d.ts +6 -0
- package/dist/hooks/use-swipe.d.ts +41 -0
- package/dist/hooks/use-text-direction.d.ts +8 -0
- package/dist/hooks/use-thumbnail.d.ts +8 -0
- package/dist/hooks/use-transfer-queue.d.ts +22 -0
- package/dist/hooks/use-tree-rows.d.ts +9 -0
- package/dist/hooks/use-tree-selection.d.ts +19 -0
- package/dist/hooks/use-type-ahead.d.ts +9 -0
- package/dist/hooks/use-type-icons.d.ts +10 -0
- package/dist/hooks/use-upload-queue.d.ts +24 -0
- package/dist/hooks/use-virtual-lines.d.ts +27 -0
- package/dist/hooks/use-virtual-rows.d.ts +31 -0
- package/dist/hooks/use-wheel-zoom.d.ts +10 -0
- package/dist/icon-sets/filled.d.ts +6 -0
- package/dist/icon-sets/filled.js +76 -0
- package/dist/icon-sets/filled.js.map +1 -0
- package/dist/icon-sets/outlined.d.ts +6 -0
- package/dist/icon-sets/outlined.js +73 -0
- package/dist/icon-sets/outlined.js.map +1 -0
- package/dist/icon-sets/rounded.d.ts +6 -0
- package/dist/icon-sets/rounded.js +73 -0
- package/dist/icon-sets/rounded.js.map +1 -0
- package/dist/icon-sets/sharp.d.ts +6 -0
- package/dist/icon-sets/sharp.js +73 -0
- package/dist/icon-sets/sharp.js.map +1 -0
- package/dist/icon-sets/two-tone.d.ts +6 -0
- package/dist/icon-sets/two-tone.js +188 -0
- package/dist/icon-sets/two-tone.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +32651 -0
- package/dist/index.js.map +1 -0
- package/dist/locales/en-us.d.ts +7 -0
- package/dist/store/download-queue.d.ts +37 -0
- package/dist/store/folder-store.d.ts +79 -0
- package/dist/store/keyboard-layout.d.ts +11 -0
- package/dist/store/properties-cache.d.ts +73 -0
- package/dist/store/thumbnail-cache.d.ts +30 -0
- package/dist/store/transfer-across.d.ts +24 -0
- package/dist/store/transfer-queue.d.ts +59 -0
- package/dist/store/upload-queue.d.ts +83 -0
- package/dist/styles/arrived.d.ts +6 -0
- package/dist/styles/classes.d.ts +212 -0
- package/dist/styles/layout.d.ts +55 -0
- package/dist/styles/media-layout.d.ts +36 -0
- package/dist/styles/order.d.ts +1 -0
- package/dist/styles.css +7632 -0
- package/dist/styles.layer.css +7634 -0
- package/dist/types/action.d.ts +296 -0
- package/dist/types/adapter.d.ts +922 -0
- package/dist/types/api.d.ts +192 -0
- package/dist/types/clipboard.d.ts +45 -0
- package/dist/types/download.d.ts +41 -0
- package/dist/types/drag.d.ts +57 -0
- package/dist/types/folder.d.ts +47 -0
- package/dist/types/icon.d.ts +20 -0
- package/dist/types/index.d.ts +27 -0
- package/dist/types/limits.d.ts +49 -0
- package/dist/types/locale.d.ts +1132 -0
- package/dist/types/main-menu.d.ts +20 -0
- package/dist/types/media.d.ts +631 -0
- package/dist/types/menu.d.ts +82 -0
- package/dist/types/navigation.d.ts +88 -0
- package/dist/types/preview.d.ts +54 -0
- package/dist/types/previewer.d.ts +67 -0
- package/dist/types/properties.d.ts +111 -0
- package/dist/types/property-definition.d.ts +286 -0
- package/dist/types/search.d.ts +46 -0
- package/dist/types/section.d.ts +98 -0
- package/dist/types/selection.d.ts +52 -0
- package/dist/types/slots.d.ts +218 -0
- package/dist/types/transfer.d.ts +68 -0
- package/dist/types/tree.d.ts +97 -0
- package/dist/types/undo.d.ts +133 -0
- package/dist/types/upload.d.ts +189 -0
- package/dist/types/view.d.ts +192 -0
- package/dist/utils/action-groups.d.ts +17 -0
- package/dist/utils/bidi.d.ts +15 -0
- package/dist/utils/clipboard.d.ts +30 -0
- package/dist/utils/cx.d.ts +2 -0
- package/dist/utils/dom.d.ts +36 -0
- package/dist/utils/download.d.ts +30 -0
- package/dist/utils/field-errors.d.ts +26 -0
- package/dist/utils/files.d.ts +48 -0
- package/dist/utils/format.d.ts +10 -0
- package/dist/utils/groups.d.ts +29 -0
- package/dist/utils/hidden.d.ts +3 -0
- package/dist/utils/keyboard.d.ts +21 -0
- package/dist/utils/limits.d.ts +7 -0
- package/dist/utils/media.d.ts +146 -0
- package/dist/utils/menu-position.d.ts +13 -0
- package/dist/utils/names.d.ts +21 -0
- package/dist/utils/navigation.d.ts +28 -0
- package/dist/utils/path.d.ts +33 -0
- package/dist/utils/permissions.d.ts +56 -0
- package/dist/utils/preview.d.ts +27 -0
- package/dist/utils/property-value.d.ts +41 -0
- package/dist/utils/resize.d.ts +2 -0
- package/dist/utils/search.d.ts +24 -0
- package/dist/utils/sections.d.ts +11 -0
- package/dist/utils/selection.d.ts +30 -0
- package/dist/utils/sets.d.ts +2 -0
- package/dist/utils/shortcut.d.ts +74 -0
- package/dist/utils/slots.d.ts +15 -0
- package/dist/utils/sort.d.ts +47 -0
- package/dist/utils/transfer.d.ts +48 -0
- package/dist/utils/trash.d.ts +25 -0
- package/dist/utils/undo.d.ts +63 -0
- package/dist/utils/zoom.d.ts +14 -0
- package/docs/README.md +55 -0
- package/docs/actions.md +301 -0
- package/docs/adapter.md +229 -0
- package/docs/copy-move-trash-undo.md +97 -0
- package/docs/customizing.md +247 -0
- package/docs/getting-started.md +168 -0
- package/docs/locale-and-rtl.md +58 -0
- package/docs/media-manager.md +498 -0
- package/docs/previewing.md +124 -0
- package/docs/properties.md +125 -0
- package/docs/recipes/in-memory-adapter.md +149 -0
- package/docs/recipes/rest-adapter.md +225 -0
- package/docs/recipes/s3-adapter.md +137 -0
- package/docs/search.md +73 -0
- package/docs/sections.md +119 -0
- package/docs/state-and-api.md +190 -0
- package/docs/uploads-and-downloads.md +144 -0
- package/package.json +90 -4
package/docs/adapter.md
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# The adapter
|
|
2
|
+
|
|
3
|
+
The adapter is the contract between filecove and your backend: an object of async functions, written once per backend (a REST API, S3, WebDAV, a database) and passed as `adapter`. The type is `FileAdapter`.
|
|
4
|
+
|
|
5
|
+
Only `list` is required. Every other member is optional, and each one switches a feature on: without `rename` there's no way to rename, without `upload` no way to upload, and nothing is shown that would only fail. So an adapter can start with `list` and grow.
|
|
6
|
+
|
|
7
|
+
The same adapter type serves `FileManager`, `MediaManager` and `MediaPicker`.
|
|
8
|
+
|
|
9
|
+
## Entries
|
|
10
|
+
|
|
11
|
+
Everything the adapter lists is a `FileEntry`:
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
interface FileEntry {
|
|
15
|
+
id: string; // opaque, unique within this adapter
|
|
16
|
+
name: string;
|
|
17
|
+
kind: "file" | "folder";
|
|
18
|
+
size?: number; // files: bytes
|
|
19
|
+
modifiedAt?: Date;
|
|
20
|
+
createdAt?: Date;
|
|
21
|
+
mimeType?: string;
|
|
22
|
+
childCount?: number; // folders: how many entries they hold, shown in the size column
|
|
23
|
+
hasSubfolders?: boolean; // folders: lets the tree drop the expand arrow without listing them
|
|
24
|
+
hidden?: boolean; // overrides "hidden if the name starts with a dot"
|
|
25
|
+
permissions?: EntryPermissions;
|
|
26
|
+
media?: MediaInfo; // width, height, duration
|
|
27
|
+
trashed?: TrashInfo; // entries in a trash: where they came from and when
|
|
28
|
+
processing?: AssetProcessing; // media manager: work the backend is doing on it
|
|
29
|
+
meta?: Record<string, unknown>; // anything of yours, carried along and never read
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
**Ids are opaque.** The file manager never parses an id, joins two into a path, or makes one up. It only hands back ids it was given, so a full path like `"/projects/site/src"` works, and so does a database id like `"f_8a2c"`. An id must be unique within its adapter; two adapters may use the same ids.
|
|
34
|
+
|
|
35
|
+
**Dates are `Date` objects.** Convert the strings your API sends.
|
|
36
|
+
|
|
37
|
+
**Fill in what's cheap.** Everything but `id`, `name` and `kind` is optional. Leave out what your backend can't tell without extra work: the properties panel can ask for it later through `properties` (see [Properties](properties.md)).
|
|
38
|
+
|
|
39
|
+
**`meta`** is yours. The file manager carries it along and compares it to tell whether an entry changed, but never reads it. The media manager hands it back with what's chosen, so it's where an asset's delivery data goes (a CDN URL, an HLS manifest, a `srcset`).
|
|
40
|
+
|
|
41
|
+
## `list`
|
|
42
|
+
|
|
43
|
+
```ts
|
|
44
|
+
list(folderId: string, options: { signal: AbortSignal; cursor?: string }): Promise<ListResult>;
|
|
45
|
+
|
|
46
|
+
interface ListResult {
|
|
47
|
+
entries: FileEntry[];
|
|
48
|
+
nextCursor?: string; // more pages to come
|
|
49
|
+
permissions?: EntryPermissions; // the listed folder's own
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
`list` returns the direct children of one folder. It's called lazily: when a folder is opened in the content, expanded in the sidebar, or browsed in the "Move to…" picker.
|
|
54
|
+
|
|
55
|
+
- **Listings are saved.** A folder opened again shows at once from its saved listing, and is listed again in the background, so changes made elsewhere show without a refresh. `relistAfter` (milliseconds, default 0) sets how old a listing may be before that; `Infinity` never lists again on its own, for a backend where listing costs, leaving it to `apiRef.refresh()`. Changes made through the file manager always show.
|
|
56
|
+
- **Unchanged entries cost nothing.** An entry that comes back with the same fields keeps its object, so nothing showing it renders again.
|
|
57
|
+
- **Paging.** Return a `nextCursor` and `list` is called again with it as `cursor`, until a page comes without one. Every page is fetched, so sorting, Select all and name clash checks see the whole folder; paging lets the backend cap its responses and the first entries show sooner. The cursor is opaque: a continuation token, an offset, anything.
|
|
58
|
+
- **The signal** aborts when the listing is no longer wanted. Pass it to `fetch`.
|
|
59
|
+
- **Rejecting** shows the folder as failed, with your error's message and a Try again button.
|
|
60
|
+
|
|
61
|
+
## Errors
|
|
62
|
+
|
|
63
|
+
Every call that can fail should reject with an `Error` whose `message` the user can read, in their language. The file manager shows it where it belongs: under the name field for a rename, in the upload panel's row for an upload, over the folder for a listing. An error without a message gets a generic one.
|
|
64
|
+
|
|
65
|
+
## Cancelling
|
|
66
|
+
|
|
67
|
+
Every call takes a `signal`. Calls that change the backend (`rename`, `copy`, `delete`...) get theirs aborted when the user cancels. The change may have been made by then, so the affected folders are listed again either way.
|
|
68
|
+
|
|
69
|
+
## What each optional member switches on
|
|
70
|
+
|
|
71
|
+
| Member | Switches on |
|
|
72
|
+
|---|---|
|
|
73
|
+
| `createFolder(parentId, name, { signal })` | New folder; uploading folders; copying folders in from another adapter |
|
|
74
|
+
| `rename(entry, name, { signal })` | Rename |
|
|
75
|
+
| `checkName(name, { kind, parentId, entry })` | your backend's naming rules, checked as the user types |
|
|
76
|
+
| `copy(entries, targetId, options)` | Copy to…, copy and paste, dragging with Ctrl, within this adapter |
|
|
77
|
+
| `move(entries, targetId, options)` | Move to…, cut and paste, dragging, within this adapter; the media manager's Move and dragging onto a group |
|
|
78
|
+
| `delete(entries, { signal, onEntryDone })` | Delete, emptying the trash, moving entries out to another adapter; the media manager's Delete, of one or several |
|
|
79
|
+
| `trash(entries, { signal })` | Move to trash, undoable |
|
|
80
|
+
| `restore(entries, { signal, conflict })` | Restore from the trash |
|
|
81
|
+
| `upload(file, folderId, options)` | uploading files and folders; taking entries in from another adapter; resolving with an `UploadResult` says a file was already there, or went into another folder |
|
|
82
|
+
| `content(entry, { signal, purpose, onProgress })` | the preview; downloading single files; copying files out to another adapter |
|
|
83
|
+
| `download(entries, options)` | downloading folders and several entries as one file (a zip) |
|
|
84
|
+
| `downloadAcross(groups, options)` | downloading a search's results from several folders as one file |
|
|
85
|
+
| `thumbnail(entry, { signal, view, size })` | thumbnails in the list, the grid, the properties and the preview |
|
|
86
|
+
| `search(rootId, query, options)` | search everywhere (the open folder's own search needs nothing), and a media library's search and filters |
|
|
87
|
+
| `properties(entry, { signal })` | the backend's own fields in the properties panel |
|
|
88
|
+
| `updateProperties(entry, values, { signal })` | editing those fields; without the next, the media manager's Edit fields… for several, one at a time |
|
|
89
|
+
| `updateManyProperties(entries, changes, options)` | media manager: Edit fields…, the same changes to several at once |
|
|
90
|
+
| `measure(folders, options)` | folder totals (files, folders, size, counted all the way down) |
|
|
91
|
+
| `replace(entry, file, options)` | media manager: Replace file in the asset view, a new file in an asset's place |
|
|
92
|
+
| `uploadPart(entry, part, file, options)` | media manager: uploading into an asset's parts (a subtitle, an audio track, a poster) from a property in its view |
|
|
93
|
+
| `processing`, `watchProcessing`, `process` | media manager: following and asking for processing |
|
|
94
|
+
| `createGroup`, `updateGroup` | media manager: groups made and edited from a form |
|
|
95
|
+
|
|
96
|
+
Each is covered in its feature's page. The ones every adapter wants are below.
|
|
97
|
+
|
|
98
|
+
### `createFolder` and `rename`
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
createFolder?(parentId: string, name: string, options: { signal: AbortSignal }): Promise<FileEntry>;
|
|
102
|
+
rename?(entry: FileEntry, name: string, options: { signal: AbortSignal }): Promise<FileEntry>;
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Both resolve with the entry as it now is. A rename's id may change, as it does when ids are paths; the file manager follows it. Reject with an `Error` to show its message under the name field, with what the user typed kept, e.g. "That name is taken."
|
|
106
|
+
|
|
107
|
+
The file manager trims names and refuses empty names, `.`, `..` and names with `/` itself, and checks the folder's listing for clashes. For your backend's own rules, add `checkName`:
|
|
108
|
+
|
|
109
|
+
```ts
|
|
110
|
+
checkName(name, { kind, parentId, entry }) {
|
|
111
|
+
if (/[\\:*?"<>|]/.test(name)) return 'A name can\'t contain \\ : * ? " < > |';
|
|
112
|
+
if (name.length > 255) return "That name is too long.";
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
It runs on every keystroke, so it must be synchronous and quick. Return the message, or nothing when the name is fine. It's asked for New folder, Rename and uploads (files with names it refuses are left out, saying why).
|
|
118
|
+
|
|
119
|
+
### `delete`
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
delete?(entries: FileEntry[], options: { signal: AbortSignal; onEntryDone: (entry: FileEntry) => void }): Promise<void>;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Deletes for good, folders with everything in them. The entries always share a parent, and the user has already confirmed. For a trash the user can restore from, see [Copy, move, trash and undo](copy-move-trash-undo.md#the-trash).
|
|
126
|
+
|
|
127
|
+
**Report each entry as it's deleted** with `onEntryDone(entry)`, when your backend can refuse some and delete the rest, such as an asset still in use. Then reject with an `Error` saying what was refused and why: what went is gone from the view at once, the media manager names what's left, and Delete tries only that again. Without it, a delete that failed is tried again for every entry.
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
async delete(entries, { signal, onEntryDone }) {
|
|
131
|
+
const response = await fetch("/api/files/delete", {
|
|
132
|
+
method: "POST",
|
|
133
|
+
body: JSON.stringify({ ids: entries.map((entry) => entry.id) }),
|
|
134
|
+
signal,
|
|
135
|
+
});
|
|
136
|
+
const { deleted, refused } = await response.json(); // ids deleted, and { id, reason } refused
|
|
137
|
+
|
|
138
|
+
entries.filter((entry) => deleted.includes(entry.id)).forEach(onEntryDone);
|
|
139
|
+
|
|
140
|
+
if (refused.length > 0) {
|
|
141
|
+
throw new Error(refused.map((each: { reason: string }) => each.reason).join(" "));
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### `updateManyProperties`
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
updateManyProperties?(entries: FileEntry[], changes: PropertyChanges, options: {
|
|
150
|
+
signal: AbortSignal;
|
|
151
|
+
onEntryDone: (entry: FileEntry) => void;
|
|
152
|
+
}): Promise<void>;
|
|
153
|
+
|
|
154
|
+
interface PropertyChanges {
|
|
155
|
+
values: Record<string, unknown>; // put in place of each one's, by field; null clears
|
|
156
|
+
added: Record<string, readonly unknown[]>; // items added to each one's list
|
|
157
|
+
removed: Record<string, readonly unknown[]>; // items taken out of each one's list
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
The media manager's Edit fields… saves the same changes to several assets or groups at once through it: values put in place, and items added to and taken out of lists (`multiple` properties, such as tags), each one keeping what it holds of the rest. The entries may be in several groups, as a search's results are. A backend that saves them in one query does it here, as Laravel's `attach` and `detach` do for tags kept as a relation:
|
|
162
|
+
|
|
163
|
+
```ts
|
|
164
|
+
async updateManyProperties(entries, { values, added, removed }, { signal, onEntryDone }) {
|
|
165
|
+
const response = await fetch("/api/media/bulk", {
|
|
166
|
+
method: "PATCH",
|
|
167
|
+
body: JSON.stringify({ ids: entries.map((entry) => entry.id), values, added, removed }),
|
|
168
|
+
signal,
|
|
169
|
+
});
|
|
170
|
+
const { saved, refused } = await response.json(); // ids saved, and { id, reason } refused
|
|
171
|
+
|
|
172
|
+
entries.filter((entry) => saved.includes(entry.id)).forEach(onEntryDone);
|
|
173
|
+
|
|
174
|
+
if (refused.length > 0) {
|
|
175
|
+
throw new Error(refused.map((each: { reason: string }) => each.reason).join(" "));
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
**Report each entry as it's saved** with `onEntryDone(entry)`, and reject with an `Error` saying why for those refused: the media manager names the rest under your message, and Save tries only them again.
|
|
181
|
+
|
|
182
|
+
Without it, each entry goes through `updateProperties`, four at a time, with `values` as they are, and each list it changes as that entry's is now, read from `properties` first, with the items added and taken out. Fine for a few dozen; for hundreds, or a list kept as a relation, `updateManyProperties` saves the backend that many requests.
|
|
183
|
+
|
|
184
|
+
## Permissions
|
|
185
|
+
|
|
186
|
+
A backend says what it refuses, so the file manager doesn't offer what would only fail:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
interface EntryPermissions {
|
|
190
|
+
write?: boolean; // folders: whether anything can go in or change in them
|
|
191
|
+
rename?: boolean;
|
|
192
|
+
move?: boolean;
|
|
193
|
+
delete?: boolean;
|
|
194
|
+
}
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Each is allowed unless it's `false`, so set only what's refused. A read-only entry sets them all to `false`. Put them on an entry (`FileEntry.permissions`), or on a folder's listing (`ListResult.permissions`), which is how a section's root, which no listing holds, says what it allows.
|
|
198
|
+
|
|
199
|
+
- A folder with `write: false` takes nothing: no new folder, upload, paste, drop, move or copy, and none of its entries can be renamed, moved out or deleted, whatever their own permissions say. It shows a lock on its icon.
|
|
200
|
+
- A file with `write: false` is never replaced by something copied or uploaded over it; the new one is kept beside it.
|
|
201
|
+
- Copying out, downloading and previewing are only reading, and are never refused.
|
|
202
|
+
|
|
203
|
+
Your adapter still has the final say: a call it rejects anyway shows its error as usual. To make a whole section read-only regardless of the backend, use `Section.readOnly` (see [Sections](sections.md)).
|
|
204
|
+
|
|
205
|
+
## Name clashes
|
|
206
|
+
|
|
207
|
+
Copies, moves, uploads and restores take a `conflict` option, saying what to do with an entry whose name the destination already has:
|
|
208
|
+
|
|
209
|
+
- `"keepBoth"`: keep the new one under a free name ("report (2).pdf"). The default, so a clash the file manager didn't see coming never overwrites anything.
|
|
210
|
+
- `"replace"`: a file takes the place of the file there, and a folder is **merged** into the folder there, all the way down, so only files with the same names are replaced. A file never replaces a folder, nor the other way round, and nothing replaces what its permissions protect; those are kept both.
|
|
211
|
+
- `"skip"`: leave it out.
|
|
212
|
+
|
|
213
|
+
The file manager checks the destination's listing first and asks the user when it sees a clash. What it can't see (deeper in a merged folder, or made meanwhile) is your adapter's to settle by the same rule.
|
|
214
|
+
|
|
215
|
+
## Several adapters
|
|
216
|
+
|
|
217
|
+
Each section may bring its own adapter (see [Sections](sections.md#several-backends)). Sections served by **the same adapter object** share what's listed, so a change made in one shows in the others; sections served by different adapters are independent, and the file manager copies between them itself.
|
|
218
|
+
|
|
219
|
+
## Changing the adapter after mounting
|
|
220
|
+
|
|
221
|
+
`adapter` may change, but a new object means a new backend to the file manager: every section it serves goes back to its root, and its saved listings are dropped. Keep it the same object across renders, at module scope or in `useMemo`, and change it only when the backend really changes, such as after signing in as someone else.
|
|
222
|
+
|
|
223
|
+
```tsx
|
|
224
|
+
const adapter = useMemo(() => createAdapter(token), [token]);
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
## Growing the contract
|
|
228
|
+
|
|
229
|
+
New features add new optional members, and existing ones never change shape, so an adapter written today keeps working. Results are objects (`{ entries }`, not an array) for the same reason.
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Copy, move, trash and undo
|
|
2
|
+
|
|
3
|
+
## Copy and move
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
copy?(entries: FileEntry[], targetId: string, options: TransferOptions): Promise<TransferResult | void>;
|
|
7
|
+
move?(entries: FileEntry[], targetId: string, options: TransferOptions): Promise<TransferResult | void>;
|
|
8
|
+
|
|
9
|
+
interface TransferOptions {
|
|
10
|
+
signal: AbortSignal;
|
|
11
|
+
conflict: "replace" | "keepBoth" | "skip";
|
|
12
|
+
onProgress: (loaded: number, total: number) => void; // bytes
|
|
13
|
+
onEntryDone: (entry: FileEntry, made?: FileEntry) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
interface TransferResult {
|
|
17
|
+
entries: FileEntry[]; // what each entry given became in the target, in order
|
|
18
|
+
}
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
With `copy`, the user copies by Copy to…, Copy and Paste, or dragging with Ctrl held; with `move`, by Move to…, Cut and Paste, or dragging. Each copy or move runs in the background, a few at once (3 by default, `limits.transfers`), shown in a panel once it takes a moment, with Cancel and Try again. The dialogs only ask what needs an answer (a destination, clashing names), then close.
|
|
22
|
+
|
|
23
|
+
- **The entries share a parent**, and `targetId` is a folder this adapter serves. A move is never into the entries themselves, nor into the folder they're already in.
|
|
24
|
+
- **Resolve with what you made** (`TransferResult`): the entries as they now are in the target, one for each entry given that went, in their order, under the names they went in by. That's what lets the user **undo** it. Without it, the copy or move can't be undone, as finding the copies by name could take a file that was there already.
|
|
25
|
+
- **Report each entry as it's done** with `onEntryDone(entry, made)`, when your backend goes one by one. Then a copy that fails partway says what went: the panel counts it, Try again leaves it out, and what went can still be undone.
|
|
26
|
+
- **`onProgress`** in bytes is optional. Without it, the row's bar sweeps, as for a move that only renames on the backend.
|
|
27
|
+
- **`conflict`** is the user's choice for names the target already has (see [The adapter](adapter.md#name-clashes)). Replace merges folders into folders, all the way down.
|
|
28
|
+
- **Reject with an `Error`** to show its message in the panel's row.
|
|
29
|
+
|
|
30
|
+
While a move is waiting or running, its entries are held: marked as being moved, and not renamed, moved, deleted or dragged until it ends, since their ids may soon name nothing.
|
|
31
|
+
|
|
32
|
+
### Between backends
|
|
33
|
+
|
|
34
|
+
When the target section is served by another adapter, the file manager copies the entries across itself, as a desktop copies between disks. It reads through the source adapter's `list` and `content` (with `purpose: "copy"`), and writes through the target adapter's `upload` and `createFolder`; a move then deletes each entry from the source with `delete`, once all of it is there. So copying between backends needs no member of its own: it works between any two adapters that have those.
|
|
35
|
+
|
|
36
|
+
Content handed over as a URL is fetched by the page, so it needs CORS. The target's `upload` has the final say, and can refuse what it won't take.
|
|
37
|
+
|
|
38
|
+
## The trash
|
|
39
|
+
|
|
40
|
+
A trash the user can restore from is your backend's. The adapter moves entries there and back, and a section shows it.
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
trash?(entries: FileEntry[], options: { signal: AbortSignal }): Promise<TrashResult | void>;
|
|
44
|
+
restore?(entries: FileEntry[], options: { signal: AbortSignal; conflict: ConflictPolicy }): Promise<TrashResult | void>;
|
|
45
|
+
|
|
46
|
+
interface TrashResult {
|
|
47
|
+
entries: FileEntry[]; // what each entry given became, in order
|
|
48
|
+
}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
The entries in the trash's root carry where they came from:
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
interface TrashInfo {
|
|
55
|
+
trail: FolderRef[]; // the folders it was in, outermost first, down to its folder
|
|
56
|
+
trashedAt?: Date;
|
|
57
|
+
}
|
|
58
|
+
// FileEntry.trashed
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
And a section with `trash: true` shows it, rooted where `trash` puts entries:
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
const sections: SectionGroup[] = [
|
|
65
|
+
{ id: "places", sections: [{ id: "home", label: "Home", icon: "home", rootId: "/home" }] },
|
|
66
|
+
{ id: "bin", sections: [{ id: "trash", label: "Trash", icon: "delete", rootId: "/.trash", trash: true, showFolders: false }] },
|
|
67
|
+
];
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
- **Moving to the trash** (`context.trash()`, or dropping on the trash section) happens at once, without asking, as on a desktop, since it can be undone. Resolve with what's now in the trash so it can; without it, or without `restore`, it can't.
|
|
71
|
+
- **The trash section** lists each entry's original location and when it was trashed, and shows a bar with Empty trash. Nothing in it can be renamed, moved, copied out or changed; its entries can be restored, deleted for good, opened and previewed. A search everywhere leaves it out.
|
|
72
|
+
- **Restoring** (`context.restore()`) puts entries back in the folders they came from, which may be several. The file manager first checks those folders for names they have now and asks, as a paste does, then passes the choice as `conflict`. A folder they came from that's gone is your backend's to make again, or to refuse with a message.
|
|
73
|
+
- **Emptying the trash** (`context.emptyTrash()`, or the trash bar's button) asks first, then calls `delete` with everything in the trash's root, read afresh.
|
|
74
|
+
- Each entry goes to its own adapter's trash; one trash doesn't take another backend's entries.
|
|
75
|
+
|
|
76
|
+
`trail` is the folders from a section's root or above it (even the top of the backend) down to the entry's folder, as `FolderRef`s. The file manager never parses ids, so the trail is how it knows where an entry came from and which section shows that folder.
|
|
77
|
+
|
|
78
|
+
Without `trash`, entries are only deleted, for good, after the user confirms.
|
|
79
|
+
|
|
80
|
+
## Undo and redo
|
|
81
|
+
|
|
82
|
+
Changes made through the file manager can be undone, several steps back (20 by default, `limits.undoSteps`), and redone, with Ctrl+Z and Shift+Ctrl+Z (or Ctrl+Y), the sidebar's main menu, or the notice each change shows over the content.
|
|
83
|
+
|
|
84
|
+
| Change | Can be undone when |
|
|
85
|
+
|---|---|
|
|
86
|
+
| Rename | always |
|
|
87
|
+
| New folder | while it's still empty, and the adapter has `delete` |
|
|
88
|
+
| Copy | `copy` resolved with a `TransferResult` (or reported each entry with `made`); undoing deletes the copies, after asking |
|
|
89
|
+
| Move | `move` resolved with a `TransferResult` (or reported each entry with `made`) |
|
|
90
|
+
| Move to the trash | `trash` resolved with a `TrashResult`, and the adapter has `restore` |
|
|
91
|
+
| Restore | `restore` resolved with a `TrashResult`, and the adapter has `trash` |
|
|
92
|
+
|
|
93
|
+
Before undoing, the file manager lists the folders again and checks that every entry is as the change left it; anything changed elsewhere since refuses the undo, saying so.
|
|
94
|
+
|
|
95
|
+
What can't be undone ends the history, so an undo never reaches past it: deleting for good, emptying the trash, an upload, Replace in a copy or move (what it replaced is gone), and a copy or move whose adapter didn't say what it made.
|
|
96
|
+
|
|
97
|
+
Changes made by your own actions (a "Compress…") aren't in the history. For a toolbar of your own, `context.undo`, `context.redo`, `apiRef.current.undo()` and `apiRef.current.redo()` do the same as the keys.
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
# Customizing
|
|
2
|
+
|
|
3
|
+
filecove brings its own look, scoped to its roots and what they open (menus, dialogs, tooltips), and asks for no theme provider or global reset. There are five ways to change it, from lightest to heaviest:
|
|
4
|
+
|
|
5
|
+
1. **Custom properties** (`--fm-*`): colours, the corner radius, the panels' gap, the font, the layers. Covers most needs.
|
|
6
|
+
2. **Stable class names** (`fm-…`, `fmClasses`): aim CSS at a part.
|
|
7
|
+
3. **`slotProps`**: put your own attributes, such as utility classes or test ids, on a part.
|
|
8
|
+
4. **`slots`**: draw a part yourself, such as the empty folder state.
|
|
9
|
+
5. **Icons**: another Material style, or your own.
|
|
10
|
+
|
|
11
|
+
## Custom properties
|
|
12
|
+
|
|
13
|
+
Set any `--fm-*` property on the component or anything above it, `:root` included. Every one you leave out keeps its default.
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
:root {
|
|
17
|
+
--fm-primary: #6d28d9;
|
|
18
|
+
--fm-primary-hover: #5b21b6;
|
|
19
|
+
--fm-radius: 10px;
|
|
20
|
+
--fm-font-family: "Inter", sans-serif;
|
|
21
|
+
}
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Property | What it colours or sets |
|
|
25
|
+
|---|---|
|
|
26
|
+
| `--fm-primary`, `--fm-primary-hover`, `--fm-primary-contrast` | selection, focus rings, the main button; text drawn on it |
|
|
27
|
+
| `--fm-error`, `--fm-error-hover`, `--fm-error-contrast` | errors, destructive actions |
|
|
28
|
+
| `--fm-success`, `--fm-success-contrast` | finished tasks |
|
|
29
|
+
| `--fm-text`, `--fm-text-secondary`, `--fm-text-disabled` | text |
|
|
30
|
+
| `--fm-background` | the window, the sidebar, dialogs |
|
|
31
|
+
| `--fm-surface` | the content panel, a view inside a dialog |
|
|
32
|
+
| `--fm-menu` | menus |
|
|
33
|
+
| `--fm-divider` | rules and outlines |
|
|
34
|
+
| `--fm-icon` | icons and icon buttons at rest |
|
|
35
|
+
| `--fm-hover`, `--fm-pressed` | buttons, menu items and fields hovered and pressed |
|
|
36
|
+
| `--fm-disabled`, `--fm-disabled-background` | disabled controls |
|
|
37
|
+
| `--fm-field-border`, `--fm-chip` | text fields' borders, chips |
|
|
38
|
+
| `--fm-row-stripe`, `--fm-row-hover`, `--fm-row-selected`, `--fm-row-selected-hover`, `--fm-row-arrived` | rows, tiles and tree rows; `arrived` is the tint on something just uploaded |
|
|
39
|
+
| `--fm-backdrop` | behind overlays and dialogs |
|
|
40
|
+
| `--fm-tooltip`, `--fm-tooltip-text` | tooltips |
|
|
41
|
+
| `--fm-notice`, `--fm-notice-text` | the notice over the content ("Renamed … · Undo") |
|
|
42
|
+
| `--fm-radius` | the corner radius, one step that parts take a few of |
|
|
43
|
+
| `--fm-panel-gap` | the space between the window's panels and around them (6px): the content, the docked properties, the upload, download and transfer panels, a media library and its selected column; a length with its unit, `0px` for none |
|
|
44
|
+
| `--fm-panel-radius` | those panels' corners; three steps of `--fm-radius` when left out |
|
|
45
|
+
| `--fm-font-family` | the font; the page's own when left out |
|
|
46
|
+
| `--fm-shadow-1`, `-2`, `-3`, `-6`, `-8`, `-24` | shadows, by elevation |
|
|
47
|
+
| `--fm-z-popup`, `--fm-z-tooltip` | the z-index of menus and dialogs (1300) and tooltips (1500), to fit your own layers |
|
|
48
|
+
|
|
49
|
+
What portals out of the component (menus, dialogs, tooltips) hangs from `<body>`, so it only gets values set on `:root` or `<body>`, not ones set on the component's own element. To theme everything, set them on `:root`.
|
|
50
|
+
|
|
51
|
+
### Light and dark
|
|
52
|
+
|
|
53
|
+
The defaults follow the element's `color-scheme`, through CSS `light-dark()`:
|
|
54
|
+
|
|
55
|
+
```css
|
|
56
|
+
:root { color-scheme: light dark; } /* follows the system */
|
|
57
|
+
.dark-panel { color-scheme: dark; } /* always dark inside */
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Without a `color-scheme`, it's light. Your own values can use `light-dark()` too:
|
|
61
|
+
|
|
62
|
+
```css
|
|
63
|
+
:root {
|
|
64
|
+
--fm-surface: light-dark(#ffffff, #1e1e2e);
|
|
65
|
+
--fm-background: light-dark(#f4f4f5, #181825);
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Lines instead of tone
|
|
70
|
+
|
|
71
|
+
By default the panels are inset cards on the window's background, told apart by the two tones of `--fm-background` and `--fm-surface`. For a flat look, with lines between the parts, put the panels edge to edge and square, give both tones one value, and draw the lines on the parts' stable class names:
|
|
72
|
+
|
|
73
|
+
```css
|
|
74
|
+
.admin {
|
|
75
|
+
--fm-panel-gap: 0px;
|
|
76
|
+
--fm-panel-radius: 0;
|
|
77
|
+
--fm-background: #fff;
|
|
78
|
+
--fm-surface: #fff;
|
|
79
|
+
--fm-divider: #e5e7eb;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/* MediaManager and MediaPicker */
|
|
83
|
+
.admin .fm-media-libraries { border-inline-end: 1px solid var(--fm-divider); }
|
|
84
|
+
.admin .fm-media-header { border-bottom: 1px solid var(--fm-divider); }
|
|
85
|
+
.admin .fm-media-chosen { border-inline-start: 1px solid var(--fm-divider); }
|
|
86
|
+
.admin .fm-task-panel { border-top: 1px solid var(--fm-divider); }
|
|
87
|
+
|
|
88
|
+
/* FileManager; its properties only, as the media manager's asset view holds a properties panel too */
|
|
89
|
+
.admin .fm-sidebar { border-inline-end: 1px solid var(--fm-divider); }
|
|
90
|
+
.admin .fm-header { border-bottom: 1px solid var(--fm-divider); }
|
|
91
|
+
.admin .fm-file-manager .fm-properties { border-inline-start: 1px solid var(--fm-divider); }
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
The upload panel then runs across the bottom as a strip. Aim at the parts, not at the boxes around them, which have no stable names and may change.
|
|
95
|
+
|
|
96
|
+
### Sizing the root
|
|
97
|
+
|
|
98
|
+
The root fills its container, 100% wide and high. Give the container a height. Its layout follows its own width, not the viewport's (container queries): the sidebar docks from 900px wide, the properties panel from 1100px. Those widths leave the content room for the default gap; a much larger `--fm-panel-gap` narrows the panels docked beside it sooner.
|
|
99
|
+
|
|
100
|
+
## The two stylesheets
|
|
101
|
+
|
|
102
|
+
- **`filecove/styles.css`**, the default, has no cascade layer, so your app's resets and element rules (`* { margin: 0 }`, `button { ... }`) can't break the component. A rule of yours aimed at a part wins when your stylesheet loads after it, or with one more class.
|
|
103
|
+
- **`filecove/styles.layer.css`** is the same inside `@layer fm`, for an app that orders its styles by layers. Declare the order, and any rule of yours in a later layer wins whatever its selector:
|
|
104
|
+
|
|
105
|
+
```css
|
|
106
|
+
@layer reset, fm, app;
|
|
107
|
+
@import "filecove/styles.layer.css";
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
Import one, once.
|
|
111
|
+
|
|
112
|
+
## Stable class names
|
|
113
|
+
|
|
114
|
+
The component's own class names are hashed and change between versions. Each part you'd aim at also carries a stable name, `fm-…`, exported as `fmClasses` if you'd rather not write strings:
|
|
115
|
+
|
|
116
|
+
```css
|
|
117
|
+
.fm-file-manager .fm-list-row { font-size: 0.9375rem; }
|
|
118
|
+
.fm-sidebar { border-inline-end: 1px solid var(--fm-divider); }
|
|
119
|
+
.fm-button[data-variant="contained"] { text-transform: uppercase; }
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```ts
|
|
123
|
+
import { fmClasses } from "filecove";
|
|
124
|
+
fmClasses.listRow; // "fm-list-row"
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Named parts include the roots (`fm-file-manager`, `fm-media-manager`, `fm-media-picker`), the regions (`fm-sidebar`, `fm-tree`, `fm-header`, `fm-path-bar`, `fm-content`, `fm-list`, `fm-grid`, `fm-properties`, `fm-preview`), the rows and tiles (`fm-list-row`, `fm-grid-tile`, `fm-tree-row`, `fm-media-option`), entries' names and icons (`fm-entry-name`, `fm-entry-icon`), the empty and error states (`fm-state`), the panels (`fm-upload-panel`, `fm-download-panel`, `fm-transfer-panel`, `fm-task-row`), each dialog (`fm-dialog` plus `fm-name-dialog`, `fm-delete-dialog`...), and the building blocks wherever they're used (`fm-button`, `fm-icon-button`, `fm-menu`, `fm-menu-item`, `fm-text-field`, `fm-chip`, `fm-icon`, `fm-tooltip`). `fmClasses` has them all, each with a doc comment.
|
|
128
|
+
|
|
129
|
+
**States are attributes, not classes**: `[aria-selected="true"]`, `[data-selected="true"]`, `[data-highlighted]` on a menu item, `[data-disabled]`, `[data-column="size"]` on the list's cells, `[data-kind="folder"]` on a tree row.
|
|
130
|
+
|
|
131
|
+
The layout boxes between parts have no stable names, on purpose, so the layout can still change. Use custom properties first, and stable names for what they don't cover.
|
|
132
|
+
|
|
133
|
+
## `slotProps`: attributes on parts
|
|
134
|
+
|
|
135
|
+
`slotProps` puts attributes of your own on the component's parts: utility classes, `data-testid`, handlers.
|
|
136
|
+
|
|
137
|
+
```tsx
|
|
138
|
+
<FileManager
|
|
139
|
+
slotProps={{
|
|
140
|
+
content: { "data-testid": "file-content" },
|
|
141
|
+
sidebar: { className: "border-e" },
|
|
142
|
+
entry: ({ entry, selected }) => ({
|
|
143
|
+
className: entry.name.startsWith(".") ? "italic" : undefined,
|
|
144
|
+
}),
|
|
145
|
+
}}
|
|
146
|
+
/* ... */
|
|
147
|
+
/>
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
| Key | `FileManager` | `MediaManager` | `MediaPicker` |
|
|
151
|
+
|---|---|---|---|
|
|
152
|
+
| `sidebar`, `content`, `properties` | yes | | |
|
|
153
|
+
| `header` | yes | yes | yes |
|
|
154
|
+
| `libraries` | | yes | |
|
|
155
|
+
| `chosen` | | yes | yes |
|
|
156
|
+
| `entry` (each row and tile), `asset` (each asset) | `entry` | `asset` | `asset` |
|
|
157
|
+
|
|
158
|
+
The part's own attributes win (its `role`, `tabIndex`, `aria-*`), so keyboard and screen reader support keep working. Your `className` is added after the part's own, your `style` goes under its own, and a handler the part has too runs yours first, then its own unless yours called `preventDefault`.
|
|
159
|
+
|
|
160
|
+
`entry` and `asset` take an object for every row, or a function of each. Keep that function outside your component, or memoized: a new one each render redraws every row.
|
|
161
|
+
|
|
162
|
+
The root itself takes its attributes directly, as props.
|
|
163
|
+
|
|
164
|
+
## `slots`: parts of your own
|
|
165
|
+
|
|
166
|
+
`slots` draws your own component where the file manager's would be:
|
|
167
|
+
|
|
168
|
+
| Slot | Shown | Props |
|
|
169
|
+
|---|---|---|
|
|
170
|
+
| `empty` | the open folder shows nothing, or the trash is empty | `section`, `location`, `folder`, `trash`, `context` (the folder's `ActionContext`) |
|
|
171
|
+
| `noResults` | a search found nothing | `query`, `scope` |
|
|
172
|
+
| `error` | the open folder couldn't be listed | `section`, `location`, `folder`, `error`, `retry` |
|
|
173
|
+
| `loading` | nothing to show yet | `label`, to name a spinner by |
|
|
174
|
+
| `noSections` | there's no section | none |
|
|
175
|
+
| `sidebarFooter` | under the sidebar's tree | `section`, `location` (or `null`) |
|
|
176
|
+
|
|
177
|
+
```tsx
|
|
178
|
+
import type { FileManagerEmptyProps, FileManagerSlots } from "filecove";
|
|
179
|
+
|
|
180
|
+
// Defined outside your component, so React keeps it mounted.
|
|
181
|
+
function EmptyFolder({ context, trash }: FileManagerEmptyProps) {
|
|
182
|
+
if (trash) return <p>Nothing in the trash.</p>;
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<div className="empty">
|
|
186
|
+
<p>This folder is empty.</p>
|
|
187
|
+
{context?.upload && (
|
|
188
|
+
<button
|
|
189
|
+
onClick={(event) => {
|
|
190
|
+
event.stopPropagation(); // or the click reaches the folder and clears the selection
|
|
191
|
+
context.upload?.();
|
|
192
|
+
}}
|
|
193
|
+
>
|
|
194
|
+
Upload files
|
|
195
|
+
</button>
|
|
196
|
+
)}
|
|
197
|
+
</div>
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const slots: FileManagerSlots = { empty: EmptyFolder };
|
|
202
|
+
|
|
203
|
+
<FileManager slots={slots} /* ... */ />;
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
- The states are drawn **inside** the component's own box, which keeps its role (`alert` for an error) and what it's described by, so they need nothing extra for screen readers.
|
|
207
|
+
- **Define slot components outside your own component.** One made while rendering is a new component every time, which React mounts afresh, losing its state.
|
|
208
|
+
- A button in a state should call `event.stopPropagation()` on click, as the folder's empty space takes clicks as clearing the selection.
|
|
209
|
+
|
|
210
|
+
`MediaManager` and `MediaPicker` take `empty` (with the header's `upload`), `noResults`, `error` and `loading`, and `MediaManager` `noSections` too.
|
|
211
|
+
|
|
212
|
+
## Icons
|
|
213
|
+
|
|
214
|
+
The UI's icons are Material Icons, drawn by filecove's own code, in five styles. Outlined is the default; the others are imported separately so your app ships only the one it uses:
|
|
215
|
+
|
|
216
|
+
```tsx
|
|
217
|
+
import { IconProvider } from "filecove";
|
|
218
|
+
import { roundedIcons } from "filecove/icons/rounded"; // or filled, outlined, sharp, two-tone
|
|
219
|
+
|
|
220
|
+
<IconProvider icons={roundedIcons}>
|
|
221
|
+
<FileManager /* ... */ />
|
|
222
|
+
</IconProvider>;
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
Replace single icons with `overrides`, any component taking an `svg`'s props, from any icon library:
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import { Trash2 } from "lucide-react";
|
|
229
|
+
|
|
230
|
+
<IconProvider overrides={{ delete: Trash2 }}>...</IconProvider>
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
Or give a whole set of your own as `icons` (an `IconSet`, a component for every `IconName`).
|
|
234
|
+
|
|
235
|
+
Sections, actions and main menu items take an icon name (`"home"`, `"upload"`, `"share"`...) or any element of your own, fitted to the same box:
|
|
236
|
+
|
|
237
|
+
```tsx
|
|
238
|
+
{ id: "drive", label: "Drive", icon: <MyDriveLogo />, rootId: "/" }
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
The coloured file and folder type icons, chosen by name, load as a separate chunk after the component mounts. `typeIcons={false}` keeps the plain icons and never loads them:
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
<IconProvider typeIcons={false}>...</IconProvider>
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
Providers nest, each inheriting what it leaves out from the one above.
|