@mgamadeus/ddd-clouddrive 0.0.0-stage → 0.1.0-rc.21

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/dist/index.js ADDED
@@ -0,0 +1,16 @@
1
+ 'use client';
2
+ import {
3
+ CLOUD_DRIVE_TAG,
4
+ buildCloudDriveRequests,
5
+ cloudDriveEndpointDefinitions,
6
+ createCloudDriveApi,
7
+ createStaticCloudDriveApi
8
+ } from "./chunk-EODL77UM.js";
9
+ export {
10
+ CLOUD_DRIVE_TAG,
11
+ buildCloudDriveRequests,
12
+ cloudDriveEndpointDefinitions,
13
+ createCloudDriveApi,
14
+ createStaticCloudDriveApi
15
+ };
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -0,0 +1,230 @@
1
+ import * as react from 'react';
2
+ import { ReactNode } from 'react';
3
+ import { PdfJsLoader, FileAreaMaintenanceSlotProps, FileAreaSettingsSlotProps, FileAreaRefView, FileAreaKey, FileManagerCapabilities, FileManagerAdapter, FileManagerActions, FileDownloadOptions, FileAreaView, FileListQuery, FileEventView, FileFamily, FileView, FolderView, FileLocationMiss, FileLocationResolution, FileScanStatus, FileAreaUsagePart, FileVersionSystemNote, FileVersionView } from '@mgamadeus/ddd-admin-ui/files';
4
+ import { UrlStateAdapter, EntityDrawerUrlAdapter } from '@mgamadeus/ddd-admin-ui/logic/pure';
5
+ import { CloudDriveApi, DriveSpaceListItem, DriveContentPurpose, DriveChildrenArg, DriveChangeEventListItem, DriveNodeListItem, DriveLocationResolveResponse, DriveScanStatus, DriveFileVersionListItem, DriveNodeBulkResult, DriveUploadReservation } from '../index.js';
6
+
7
+ /**
8
+ * The URL parameters of the drive screen: `space`, `path` (`/a/b`; a folder node id still works), `file` (the details),
9
+ * `fileTab` (`accesses`), `tab` (`trash`), `view`, `q`, the filters and `sort`.
10
+ */
11
+ declare const CLOUD_DRIVE_URL_KEYS: {
12
+ readonly area: "space";
13
+ readonly folder: "path";
14
+ readonly order: "sort";
15
+ readonly file: "file";
16
+ readonly fileTab: "fileTab";
17
+ readonly tab: "tab";
18
+ };
19
+ /** A deep link by node id (`?node=<id>`): replaced by `space` + `path` + `file` once the node is known. */
20
+ declare const CLOUD_DRIVE_NODE_KEY = "node";
21
+ /** One folder of a path (`null` id: the root). Kept for hosts that typed deep links with it. */
22
+ interface CloudDriveFolderStep {
23
+ id: number | null;
24
+ name: string;
25
+ }
26
+ interface CloudDriveScreenProps {
27
+ api: CloudDriveApi;
28
+ /** The page title; default "Drive". */
29
+ title?: ReactNode;
30
+ description?: ReactNode;
31
+ /** The space shown first; default the first space in the picker's order. */
32
+ initialSpaceId?: number;
33
+ /** A folder to open first (a deep link); its space is read from the server. */
34
+ initialFolderNodeId?: number;
35
+ /** A file to open first (a deep link): its folder opens and its details drawer. */
36
+ initialNodeId?: number;
37
+ /** Actions next to the title. */
38
+ headerActions?: ReactNode;
39
+ /** The host's URL adapters (`useNextUrlStateAdapter`, `useNextDrawerUrlAdapter`); component state otherwise. */
40
+ urlStateAdapter?: UrlStateAdapter;
41
+ drawerUrlAdapter?: EntityDrawerUrlAdapter;
42
+ /** pdf.js of the host for the PDF preview (without it a PDF offers its download only). */
43
+ loadPdfJs?: PdfJsLoader;
44
+ /** Host controls next to the page actions (a usage link, a maintenance action). */
45
+ renderAreaMaintenance?: (props: FileAreaMaintenanceSlotProps) => ReactNode;
46
+ /** The space's settings (a drawer of the host): the manager adds a "Space settings" button that opens it. */
47
+ renderAreaSettings?: (props: FileAreaSettingsSlotProps) => ReactNode;
48
+ /** The label of an event type the drive does not know (host events); `null` = the built-in label. */
49
+ formatEventType?: (type: string) => string | null | undefined;
50
+ /** Grid or table first; default grid. */
51
+ defaultView?: 'grid' | 'table';
52
+ /** `page` (default): a full-height page with its header; `embedded`: inside a tab or a preview, header-less. */
53
+ variant?: 'page' | 'embedded';
54
+ }
55
+ /**
56
+ * The drive screen: the file manager of `./files` on the drive (`useCloudDriveFileAdapter`) with a grouped, searchable
57
+ * space picker. Folders, grid and table, upload straight to the store, details with preview, versions (restore) and
58
+ * history, the malware status, the agents' unsaved changes, filters and orders, the trash (purge and empty for
59
+ * managers). Needs mgamadeus/ddd-clouddrive ≥ 0.1.0-rc.10.
60
+ */
61
+ declare const CloudDriveScreen: ({ api, title, description, initialSpaceId, initialFolderNodeId, initialNodeId, headerActions, urlStateAdapter, drawerUrlAdapter, loadPdfJs, renderAreaMaintenance, renderAreaSettings, formatEventType, defaultView, variant, }: CloudDriveScreenProps) => react.JSX.Element;
62
+
63
+ interface CloudDriveSpacePickerProps {
64
+ /** The spaces (`driveAreaRefOf` of the space list): name and group. */
65
+ areas: readonly FileAreaRefView[];
66
+ areaKey: FileAreaKey;
67
+ onSelectArea: (areaKey: FileAreaKey) => void;
68
+ /** The space list items: each entry then shows its file count and used size on a second line. */
69
+ spaces?: readonly DriveSpaceListItem[];
70
+ className?: string;
71
+ }
72
+ /** The space picker of the drive screen: one button, a searchable list grouped by the space's group. */
73
+ declare const CloudDriveSpacePicker: ({ areas, areaKey, onSelectArea, spaces, className }: CloudDriveSpacePickerProps) => react.JSX.Element;
74
+
75
+ /** How many changes the drawer shows. */
76
+ declare const DRIVE_ACTIVITY_LIMIT = 20;
77
+ interface UseCloudDriveFileAdapterOptions {
78
+ /** `createCloudDriveApi(…)` of the host. */
79
+ api: CloudDriveApi;
80
+ /** The open space; writes without an area (move, trash, restore, purge) go to it. */
81
+ spaceId: number;
82
+ }
83
+ /**
84
+ * The capabilities of the drive besides the trash (which `createCloudDriveFileAdapter` adds with its own hook): the
85
+ * same set for every space; the actions say what a viewer may do.
86
+ */
87
+ declare const CLOUD_DRIVE_FILE_CAPABILITIES: Omit<FileManagerCapabilities, 'trash'>;
88
+ /**
89
+ * A `FileManagerAdapter` on the drive: area = space, folder and file ids = node ids. Every space offers trash,
90
+ * versions, activity, filters (family, created, mine, three orders), the working-copy mark and the malware status;
91
+ * purge and empty trash appear only for a viewer with the space's manage right. Create it with
92
+ * `useCloudDriveFileAdapter`; its identity changes only with `api` and `spaceId`.
93
+ */
94
+ declare const createCloudDriveFileAdapter: (api: CloudDriveApi, spaceId: number) => FileManagerAdapter;
95
+ /** The drive's file manager adapter for one space; stable while `api` and `spaceId` stay the same. */
96
+ declare const useCloudDriveFileAdapter: ({ api, spaceId }: UseCloudDriveFileAdapterOptions) => FileManagerAdapter;
97
+
98
+ type TriggerOf<THook> = THook extends () => readonly [infer TTrigger, unknown] ? TTrigger : never;
99
+ /** The mutation triggers the writes call (the first element of each mutation hook). */
100
+ interface CloudDriveFileActionTriggers {
101
+ reserveUpload: TriggerOf<CloudDriveApi['useReserveDriveUploadMutation']>;
102
+ completeUpload: TriggerOf<CloudDriveApi['useCompleteDriveUploadMutation']>;
103
+ requestContent: TriggerOf<CloudDriveApi['useDriveContentMutation']>;
104
+ moveNode: TriggerOf<CloudDriveApi['useMoveDriveNodeMutation']>;
105
+ updateMetadata: TriggerOf<CloudDriveApi['useUpdateDriveNodeMetadataMutation']>;
106
+ createFolder: TriggerOf<CloudDriveApi['useCreateDriveFolderMutation']>;
107
+ moveNodes: TriggerOf<CloudDriveApi['useMoveDriveNodesMutation']>;
108
+ trashNodes: TriggerOf<CloudDriveApi['useTrashDriveNodesMutation']>;
109
+ restoreNodes: TriggerOf<CloudDriveApi['useRestoreDriveNodesMutation']>;
110
+ purgeNodes: TriggerOf<CloudDriveApi['usePurgeDriveNodesMutation']>;
111
+ emptyTrash: TriggerOf<CloudDriveApi['useEmptyDriveTrashMutation']>;
112
+ restoreVersion: TriggerOf<CloudDriveApi['useRestoreDriveVersionMutation']>;
113
+ }
114
+ /** The folder and name of a node the writes need and the views do not carry (a new version of a file). */
115
+ interface DriveNodeFact {
116
+ parentNodeId: number | null;
117
+ name: string;
118
+ }
119
+ interface CloudDriveFileActionContext {
120
+ /** The open space: writes without an area (move, trash, restore, purge) go to it. */
121
+ spaceId: number;
122
+ /** The space's root folder (`null` folder of the file manager). */
123
+ rootNodeId: number | null;
124
+ /** The viewer may purge and empty the trash (the space's manage right). */
125
+ canManage: boolean;
126
+ /** Facts of the nodes the lists showed, by id. */
127
+ nodeFacts: Map<number, DriveNodeFact>;
128
+ }
129
+ /**
130
+ * The writes of the drive's file manager. Purge and empty trash exist only with `canManage` (so the manager offers
131
+ * them only to managers); every other write is offered and the server checks the space's write right.
132
+ */
133
+ /**
134
+ * The content purpose of a download request: a list picture is a `THUMBNAIL` (never recorded), a preview `INLINE`
135
+ * (recorded as viewed; the server serves non-raster types as attachment anyway), an original `DOWNLOAD` (recorded as
136
+ * downloaded).
137
+ */
138
+ declare const drivePurposeOf: (options: FileDownloadOptions) => DriveContentPurpose;
139
+ declare const buildCloudDriveFileActions: (triggers: CloudDriveFileActionTriggers, context: CloudDriveFileActionContext) => FileManagerActions;
140
+
141
+ /** The page size of a growing list; each "more" asks for one page more, up to `DRIVE_LIST_MAX_LIMIT`. */
142
+ declare const DRIVE_LIST_PAGE_SIZE = 100;
143
+ /** The largest `limit` the drive answers in one call. */
144
+ declare const DRIVE_LIST_MAX_LIMIT = 1000;
145
+ /** The most calls one "empty trash" makes (each removes one batch of the server). */
146
+ declare const DRIVE_EMPTY_TRASH_MAX_CALLS = 200;
147
+ /** The labels of the drive's own event types the file manager does not know. */
148
+ declare const DRIVE_EVENT_LABELS: Readonly<Record<string, string>>;
149
+ /** The scan state the file manager shows: `PURGING` (the content is being removed) reads as not available. */
150
+ declare const driveScanStatusOf: (scanStatus: DriveScanStatus | null | undefined) => FileScanStatus;
151
+ /** The family of a drive item: the server's family, else from the extension, else from the content type. */
152
+ declare const driveFamilyOf: (item: Pick<DriveNodeListItem, "family" | "extension" | "contentType" | "name">) => FileFamily;
153
+ /** The folder a node sits in as the file manager names it: the space's root is `null`. */
154
+ declare const driveFolderIdOf: (parentNodeId: number | null | undefined, rootNodeId: number | null | undefined) => number | null;
155
+ /** A file of the drive as a `FileView` (trash facts included when present; a trashed folder is marked `isFolder`). */
156
+ declare const driveFileViewOf: (item: DriveNodeListItem, rootNodeId: number | null | undefined) => FileView;
157
+ /** The folders of a space as the tree reads them: the root itself is left out, its children hang at `null`. */
158
+ declare const driveFolderViewsOf: (items: readonly DriveNodeListItem[], rootNodeId: number | null | undefined) => FolderView[];
159
+ /** A version's system note; null for free text or a code this package does not know (then `comment` is drawn). */
160
+ declare const driveVersionNoteOf: (item: DriveFileVersionListItem) => FileVersionSystemNote | null;
161
+ /** A version of a file as the drawer lists it. */
162
+ declare const driveVersionViewOf: (item: DriveFileVersionListItem) => FileVersionView;
163
+ /** A change of a node as the drawer's activity lists it; a move or rename shows `old path → new path`. */
164
+ declare const driveEventViewOf: (item: DriveChangeEventListItem) => FileEventView;
165
+ /**
166
+ * Where a resolve answer leads, for the file manager: the space, the folder to open (a file's folder; `null` = the
167
+ * root), the file whose details open, and the path with a leading slash.
168
+ */
169
+ declare const driveLocationResolutionOf: (response: DriveLocationResolveResponse) => FileLocationResolution;
170
+ /** The miss of a resolve request (its 404 body), for the path bar's message. */
171
+ declare const driveLocationMissOf: (error: unknown) => FileLocationMiss | null;
172
+ /** The labels of the usage split of a space (the quota pill's tooltip). */
173
+ declare const DRIVE_USAGE_PART_LABELS: {
174
+ readonly currentVersionBytes: "Current versions";
175
+ readonly olderVersionBytes: "Older versions";
176
+ readonly trashedBytes: "Trash";
177
+ readonly pendingBytes: "Uploads being checked";
178
+ };
179
+ /** The usage split of a space when the server sends it (ddd-clouddrive ≥ rc.12), translated; `null` otherwise. */
180
+ declare const driveUsagePartsOf: (quota: DriveSpaceListItem["quota"]) => FileAreaUsagePart[] | null;
181
+ /** The quota that applies (`effectiveQuotaBytes`, else `quotaBytes`); `null` = no limit. */
182
+ declare const effectiveQuotaOf: (quota: DriveSpaceListItem["quota"]) => number | null;
183
+ /** A space as the file manager's area facts. */
184
+ declare const driveAreaViewOf: (item: DriveSpaceListItem) => FileAreaView;
185
+ /** A space as an entry of the area picker and the manager's `areas`. */
186
+ declare const driveAreaRefOf: (item: DriveSpaceListItem) => FileAreaRefView;
187
+ /**
188
+ * The `children` request of a file manager query. A folder (or `'root'`) lists that folder; no folder, a name search
189
+ * or a filter lists the whole space (`recursive`).
190
+ */
191
+ declare const driveChildrenArgOf: (query: FileListQuery, rootNodeId: number | null | undefined, limit: number) => DriveChildrenArg;
192
+ /** The files of a list answer (folders, links and system nodes are left out). */
193
+ declare const driveFileItemsOf: (items: readonly DriveNodeListItem[] | undefined) => DriveNodeListItem[];
194
+ /** The next `limit` of a growing list, or `null` when the drive answers no more in one call. */
195
+ declare const nextDriveListLimit: (limit: number) => number | null;
196
+ /** What an "empty trash" removed over all its calls. */
197
+ interface DriveEmptyTrashOutcome {
198
+ calls: number;
199
+ processedCount: number;
200
+ fileCount: number;
201
+ folderCount: number;
202
+ /** The call limit was reached with more left (rare; the user empties again). */
203
+ hasMore: boolean;
204
+ }
205
+ /** Empties a trash batch by batch: calls `emptyOnce` while the server answers `hasMore`, at most `maxCalls` times. */
206
+ declare const emptyDriveTrashFully: (emptyOnce: () => Promise<DriveNodeBulkResult>, maxCalls?: number) => Promise<DriveEmptyTrashOutcome>;
207
+ /** One group of the space picker. */
208
+ interface DriveSpaceGroup {
209
+ /** `''` = spaces without a group. */
210
+ label: string;
211
+ areas: FileAreaRefView[];
212
+ }
213
+ /** Groups the spaces by `groupLabel` in the server's order (it sorts by group, then name): nothing is re-sorted. */
214
+ declare const groupDriveSpaces: (areas: readonly FileAreaRefView[]) => DriveSpaceGroup[];
215
+
216
+ /** The progress of one upload in bytes. */
217
+ type DriveUploadProgress = (sentBytes: number, totalBytes: number) => void;
218
+ /**
219
+ * Sends a file along a reservation: one PUT, or every part of a multipart upload one after the other. Every header of
220
+ * a request goes out unchanged (they are signed into the URL). Content the space knows needs nothing. `signal` aborts
221
+ * the running request (the fetch rejects with an `AbortError`).
222
+ */
223
+ declare const sendDriveUpload: (reservation: DriveUploadReservation, file: Blob, onProgress?: DriveUploadProgress, signal?: AbortSignal) => Promise<void>;
224
+ /** Human-readable size: `512 B`, `1.2 KB`, `3.4 MB`, `1.25 GB`. */
225
+ declare const formatDriveSize: (sizeBytes: number | null | undefined) => string;
226
+ /** A backend time `Y-m-d H:i:s` without an offset is UTC; one with an offset is read as it is. */
227
+ declare const parseDriveTime: (value: string | null | undefined) => Date | null;
228
+
229
+ export { CLOUD_DRIVE_FILE_CAPABILITIES, CLOUD_DRIVE_NODE_KEY, CLOUD_DRIVE_URL_KEYS, CloudDriveScreen, CloudDriveSpacePicker, DRIVE_ACTIVITY_LIMIT, DRIVE_EMPTY_TRASH_MAX_CALLS, DRIVE_EVENT_LABELS, DRIVE_LIST_MAX_LIMIT, DRIVE_LIST_PAGE_SIZE, DRIVE_USAGE_PART_LABELS, buildCloudDriveFileActions, createCloudDriveFileAdapter, driveAreaRefOf, driveAreaViewOf, driveChildrenArgOf, driveEventViewOf, driveFamilyOf, driveFileItemsOf, driveFileViewOf, driveFolderIdOf, driveFolderViewsOf, driveLocationMissOf, driveLocationResolutionOf, drivePurposeOf, driveScanStatusOf, driveUsagePartsOf, driveVersionNoteOf, driveVersionViewOf, effectiveQuotaOf, emptyDriveTrashFully, formatDriveSize, groupDriveSpaces, nextDriveListLimit, parseDriveTime, sendDriveUpload, useCloudDriveFileAdapter };
230
+ export type { CloudDriveFolderStep, CloudDriveScreenProps, CloudDriveSpacePickerProps, DriveEmptyTrashOutcome, DriveSpaceGroup, DriveUploadProgress, UseCloudDriveFileAdapterOptions };