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
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
# Getting started
|
|
2
|
+
|
|
3
|
+
## Install
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install filecove
|
|
7
|
+
# or: bun add filecove / pnpm add filecove / yarn add filecove
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
filecove needs **React 19** and React DOM 19, as peer dependencies. It brings `@base-ui/react` and `@react-symbols/icons` with it.
|
|
11
|
+
|
|
12
|
+
It's published as ES modules only. Its type declarations resolve with TypeScript's `moduleResolution` set to `"bundler"`, which Vite and Next.js use, `"node16"` or `"nodenext"`.
|
|
13
|
+
|
|
14
|
+
## Import the stylesheet
|
|
15
|
+
|
|
16
|
+
The components don't put their CSS in the page themselves. Import one of the two stylesheets once, at your app's entry:
|
|
17
|
+
|
|
18
|
+
```ts
|
|
19
|
+
import "filecove/styles.css";
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or, if your app orders its styles with cascade layers, import the layered copy and place the `fm` layer where you want it:
|
|
23
|
+
|
|
24
|
+
```css
|
|
25
|
+
@layer reset, fm, app;
|
|
26
|
+
@import "filecove/styles.layer.css";
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Without either, the component renders unstyled. See [Customizing](customizing.md#the-two-stylesheets) for the difference.
|
|
30
|
+
|
|
31
|
+
## A first file manager
|
|
32
|
+
|
|
33
|
+
A file manager needs three things: an **adapter** (how to reach the backend), **sections** (the roots shown in the sidebar) and **actions** (what the context menu offers). Here's the smallest one that works, over a few folders kept in memory:
|
|
34
|
+
|
|
35
|
+
```tsx
|
|
36
|
+
import { FileManager } from "filecove";
|
|
37
|
+
import type { FileAdapter, FileEntry, SectionGroup } from "filecove";
|
|
38
|
+
import "filecove/styles.css";
|
|
39
|
+
|
|
40
|
+
// The files, by the id of the folder holding them. Ids are yours: paths here, but they could be
|
|
41
|
+
// database ids. The file manager never reads them, only hands them back.
|
|
42
|
+
const tree: Record<string, FileEntry[]> = {
|
|
43
|
+
"/": [
|
|
44
|
+
{ id: "/docs", name: "docs", kind: "folder" },
|
|
45
|
+
{ id: "/readme.md", name: "readme.md", kind: "file", size: 1200, modifiedAt: new Date("2026-01-04") },
|
|
46
|
+
],
|
|
47
|
+
"/docs": [
|
|
48
|
+
{ id: "/docs/guide.pdf", name: "guide.pdf", kind: "file", size: 480_000, mimeType: "application/pdf" },
|
|
49
|
+
],
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Defined outside the component, so it's the same object on every render.
|
|
53
|
+
const adapter: FileAdapter = {
|
|
54
|
+
async list(folderId) {
|
|
55
|
+
return { entries: tree[folderId] ?? [] };
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const sections: SectionGroup[] = [
|
|
60
|
+
{
|
|
61
|
+
id: "places",
|
|
62
|
+
sections: [{ id: "files", label: "My files", icon: "home", rootId: "/" }],
|
|
63
|
+
},
|
|
64
|
+
];
|
|
65
|
+
|
|
66
|
+
export function Files() {
|
|
67
|
+
return (
|
|
68
|
+
<div style={{ height: "100vh" }}>
|
|
69
|
+
<FileManager adapter={adapter} sections={sections} />
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
That's a working, read-only file manager: browsing, the tree, list and grid views, sorting, hidden files, the folder search and the keyboard all work with `list` alone. Every other feature switches on as the adapter grows a matching method (see [The adapter](adapter.md#what-each-optional-member-switches-on)).
|
|
76
|
+
|
|
77
|
+
**Give it a height.** The root fills the box it's placed in, 100% wide and 100% high, and lays itself out by its own width rather than the viewport's. In a container with no height it collapses to nothing.
|
|
78
|
+
|
|
79
|
+
## Add the context menu
|
|
80
|
+
|
|
81
|
+
The file manager puts nothing in the context menu by itself: it hands each action an `ActionContext` saying what the user can do here, and you decide what to show and what to call it. So with no `actions`, right-clicking does nothing.
|
|
82
|
+
|
|
83
|
+
The usual set is in [Actions](actions.md#a-complete-set-to-start-from), ready to copy. A small one looks like this:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
import type { ActionGroup } from "filecove";
|
|
87
|
+
|
|
88
|
+
const actions: ActionGroup[] = [
|
|
89
|
+
{
|
|
90
|
+
id: "edit",
|
|
91
|
+
actions: [
|
|
92
|
+
{
|
|
93
|
+
id: "rename",
|
|
94
|
+
label: "Rename…",
|
|
95
|
+
icon: "rename",
|
|
96
|
+
shortcut: "F2",
|
|
97
|
+
target: "selection",
|
|
98
|
+
single: true,
|
|
99
|
+
visible: (context) => !!context.rename,
|
|
100
|
+
onSelect: (context) => context.rename?.(),
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: "delete",
|
|
104
|
+
label: "Delete…",
|
|
105
|
+
icon: "delete",
|
|
106
|
+
shortcut: "Delete",
|
|
107
|
+
target: "selection",
|
|
108
|
+
destructive: true,
|
|
109
|
+
visible: (context) => !!context.delete,
|
|
110
|
+
onSelect: (context) => context.delete?.(),
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
<FileManager adapter={adapter} sections={sections} actions={actions} />;
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
`context.rename` and `context.delete` are only there when the adapter has `rename` and `delete`, and the entries' permissions allow them, so `visible` hides the item otherwise.
|
|
120
|
+
|
|
121
|
+
## Grow the adapter
|
|
122
|
+
|
|
123
|
+
Each optional method on the adapter switches a feature on. Add them as your backend supports them:
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
const adapter: FileAdapter = {
|
|
127
|
+
list: (folderId, { signal, cursor }) => api.list(folderId, cursor, signal),
|
|
128
|
+
createFolder: (parentId, name, { signal }) => api.createFolder(parentId, name, signal),
|
|
129
|
+
rename: (entry, name, { signal }) => api.rename(entry.id, name, signal),
|
|
130
|
+
delete: (entries, { signal }) => api.delete(entries.map((e) => e.id), signal),
|
|
131
|
+
upload: (file, folderId, { signal, onProgress, conflict }) => api.upload(file, folderId, conflict, onProgress, signal),
|
|
132
|
+
content: async (entry) => ({ url: `/api/files/${encodeURIComponent(entry.id)}/content` }),
|
|
133
|
+
};
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
A complete adapter over a REST API is in [recipes/rest-adapter.md](recipes/rest-adapter.md).
|
|
137
|
+
|
|
138
|
+
## Things that cost the most time
|
|
139
|
+
|
|
140
|
+
In development, the console warns about the first and last of these, and about a missing stylesheet or a root with no height. Your production build carries none of those checks.
|
|
141
|
+
|
|
142
|
+
- **Keep `adapter` stable.** Define it at module scope, or in `useMemo`. When the `adapter` prop changes to another object, every section it serves goes back to its root and its saved listings are dropped, as another adapter's ids may mean something else. A new adapter each render resets the file manager on every render.
|
|
143
|
+
- **Dates are `Date` objects.** `modifiedAt`, `createdAt` and `trashedAt` are `Date`s, not strings. Convert what your API sends.
|
|
144
|
+
- **Ids are opaque and unique within an adapter.** The file manager never parses an id, joins paths or builds one; it only hands back ids it was given. Paths work as ids, and so do database ids.
|
|
145
|
+
- **Reject with an `Error`.** When a call fails, reject with an `Error` whose `message` the user can read. The file manager shows it where the action happened (under a field, in a panel row, in the folder).
|
|
146
|
+
- **Pass the `signal` on.** Every call gets an `AbortSignal`. Hand it to `fetch` so a folder the user has left stops loading.
|
|
147
|
+
- **Functions and components in props.** `slots` take components, so define them outside your component, or React mounts them afresh each render. `localeText` functions, `slotProps.entry` functions and `renderAsset` written inline are new each render and redraw every row; define them outside or memoize them.
|
|
148
|
+
|
|
149
|
+
## Server rendering and Next.js
|
|
150
|
+
|
|
151
|
+
The package is marked `"use client"`, so in Next.js's App Router you can import `FileManager` in a server component's tree directly; it renders on the server and hydrates in the browser. Nothing reads `window` or `document` while rendering. The coloured file type icons load after the component mounts, so the server's render shows plain icons, which swap in the browser.
|
|
152
|
+
|
|
153
|
+
Import the stylesheet in your root layout:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
// app/layout.tsx
|
|
157
|
+
import "filecove/styles.css";
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## Browser support
|
|
161
|
+
|
|
162
|
+
The stylesheets use CSS nesting, container queries, `:has()`, `:dir()`, `color-mix()` and `light-dark()`. The floor is **Chrome 123, Safari 17.5 and Firefox 120**.
|
|
163
|
+
|
|
164
|
+
## Next
|
|
165
|
+
|
|
166
|
+
- [The adapter](adapter.md), the contract in full.
|
|
167
|
+
- [Sections](sections.md), for several roots or several backends.
|
|
168
|
+
- [Customizing](customizing.md), for colours, fonts and dark mode.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
# Text, languages and right to left
|
|
2
|
+
|
|
3
|
+
## The component's text
|
|
4
|
+
|
|
5
|
+
Everything the component shows or reads to screen readers is a key of `FileManagerLocaleText` (or `MediaManagerLocaleText` for the media manager). It ships in English only, as `enUS`. Pass `localeText` for another language or other wording; keys you leave out stay in English.
|
|
6
|
+
|
|
7
|
+
```tsx
|
|
8
|
+
import { FileManager } from "filecove";
|
|
9
|
+
import type { FileManagerLocaleText } from "filecove";
|
|
10
|
+
|
|
11
|
+
const localeText: Partial<FileManagerLocaleText> = {
|
|
12
|
+
sidebarTitle: "Dateien",
|
|
13
|
+
deleteDone: (count, name) => (count === 1 ? `„${name}“ gelöscht` : `${count} Elemente gelöscht`),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
<FileManager localeText={localeText} /* ... */ />;
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- **Start a translation from `enUS`**, which has every key: `import { enUS } from "filecove"`, copy it, and translate each value. TypeScript tells you the shape of each.
|
|
20
|
+
- **Texts about entries are functions**, so each language words and pluralizes its own way: counts come as numbers, a name as the entry's name for one entry.
|
|
21
|
+
- **Names, messages, sizes and dates come already isolated** (between Unicode FSI and PDI), so they keep their own direction in a sentence of any language. Don't isolate them again.
|
|
22
|
+
- **Keep the object stable.** A new object with the same strings is fine, but functions written inline are new each render and make every row render again. Define `localeText` outside your component, or memoize it.
|
|
23
|
+
|
|
24
|
+
Your own labels (sections, actions, the main menu, property labels from your adapter) are yours already, in whatever language your app uses, and aren't in `localeText`. So are error messages from your adapter, shown as they are.
|
|
25
|
+
|
|
26
|
+
## Formats
|
|
27
|
+
|
|
28
|
+
`locale` is the BCP 47 language tag numbers, sizes and dates are written in, and names are sorted and matched by:
|
|
29
|
+
|
|
30
|
+
```tsx
|
|
31
|
+
<FileManager locale="de-DE" /* ... */ />
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
The browser's language when left out. It changes no text; that's `localeText`. With `locale="ar-EG"`, digits and dates are Arabic; with `"de"`, sizes read "1,5 MB".
|
|
35
|
+
|
|
36
|
+
Names sort in natural order ("file 2" before "file 10"), case and accents aside, by the language's collation, so a language that counts "å" as a letter of its own keeps it apart from "a".
|
|
37
|
+
|
|
38
|
+
## Right to left
|
|
39
|
+
|
|
40
|
+
Set `dir="rtl"` on the page, or on any element around the component:
|
|
41
|
+
|
|
42
|
+
```html
|
|
43
|
+
<html dir="rtl">
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
That's all. There's no provider, theme direction or RTL plugin to set up. The styles use logical properties and follow the element's direction: the sidebar docks on the right, the tree indents from the right, back and forward arrows are mirrored, Left and Right swap, menus open the other way. Menus, dialogs and tooltips, which open outside the component, take its direction too.
|
|
47
|
+
|
|
48
|
+
The component's stylesheets are static files, so an RTL plugin of your app's (such as `stylis-plugin-rtl`) never sees them, and nothing is flipped twice.
|
|
49
|
+
|
|
50
|
+
A page that sets `direction: rtl` in CSS without the `dir` attribute gets the keys and menus right but not the mirrored styles: use `dir`.
|
|
51
|
+
|
|
52
|
+
Names in any script show correctly in both directions: a Latin name on a right-to-left page keeps its extension at its end, and an Arabic name in a left-to-right list reads right to left.
|
|
53
|
+
|
|
54
|
+
## The media manager
|
|
55
|
+
|
|
56
|
+
`MediaManager` and `MediaPicker` take `localeText` (a `Partial<MediaManagerLocaleText>`) and `locale` the same way. `MediaManagerLocaleText` holds the media manager's own keys, named `media…`, and the few it shares with the file manager. `enUS` has the keys of both.
|
|
57
|
+
|
|
58
|
+
Text inside your forms, properties and previewers is yours, in your app's language.
|