@vryzel/file-next-ui 0.4.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.
@@ -0,0 +1,423 @@
1
+ import { RequestUploadResult, ViewMode } from '@vryzel/file-next-headless';
2
+ import { ReactNode } from 'react';
3
+ import { FileNode, Result } from '@vryzel/file-next';
4
+ export { FileNode, Result } from '@vryzel/file-next';
5
+ import { LucideIcon } from 'lucide-react';
6
+ import { ClassValue } from 'clsx';
7
+
8
+ type FileSystemError = {
9
+ code: string;
10
+ message: string;
11
+ };
12
+
13
+ type ExplorerColumn = "name" | "size" | "modified" | "kind";
14
+ type SortDirection = "asc" | "desc";
15
+ interface ExplorerListViewProps {
16
+ readonly files: ReadonlyArray<FileNode>;
17
+ readonly protectedIds?: ReadonlySet<string>;
18
+ readonly selectedIds: ReadonlySet<string>;
19
+ readonly onSelect: (file: FileNode, event: {
20
+ shiftKey: boolean;
21
+ }) => void;
22
+ readonly onActivate: (file: FileNode) => void;
23
+ readonly onContextMenu?: (file: FileNode, event: React.MouseEvent) => void;
24
+ readonly onDragStart: (id: string) => void;
25
+ readonly onDragEnd: () => void;
26
+ readonly onDrop: (destinationFolderId: string) => void;
27
+ readonly draggingId: string | null;
28
+ readonly draggingIds?: ReadonlySet<string>;
29
+ readonly dropTargetId: string | null;
30
+ readonly onDragOverRow: (id: string | null) => void;
31
+ readonly sortKey?: ExplorerColumn;
32
+ readonly sortDirection?: SortDirection;
33
+ readonly onSortChange?: (key: ExplorerColumn) => void;
34
+ readonly className?: string;
35
+ }
36
+ declare function ExplorerListView(props: ExplorerListViewProps): React.ReactElement;
37
+
38
+ type ExplorerLabels = {
39
+ loading: string;
40
+ emptyFolder: string;
41
+ emptyTrash: string;
42
+ noMatches: string;
43
+ dropHint: string;
44
+ trashRetention: string;
45
+ items: string;
46
+ inTrash: string;
47
+ loadMore: string;
48
+ search: string;
49
+ upload: string;
50
+ newFolder: string;
51
+ folderName: string;
52
+ folderNameHint: string;
53
+ folderExists: string;
54
+ folderCreateFailed: string;
55
+ createFolder: string;
56
+ cancel: string;
57
+ rename: string;
58
+ renameHint: string;
59
+ viewOptions: string;
60
+ listView: string;
61
+ gridView: string;
62
+ sortName: string;
63
+ sortSize: string;
64
+ sortModified: string;
65
+ sortKind: string;
66
+ trash: string;
67
+ folder: string;
68
+ inUse: string;
69
+ itemActions: string;
70
+ preview: string;
71
+ download: string;
72
+ copy: string;
73
+ paste: string;
74
+ copied: string;
75
+ copyShare: string;
76
+ share: string;
77
+ restore: string;
78
+ moveToTrash: string;
79
+ deleteForever: string;
80
+ confirmDelete: string;
81
+ confirmDeleteMany: string;
82
+ confirmPurge: string;
83
+ confirmPurgeMany: string;
84
+ deleting: string;
85
+ selectedCount: string;
86
+ clearSelection: string;
87
+ clearClipboard: string;
88
+ uploadStatus: string;
89
+ dismissUploads: string;
90
+ uploadQueued: string;
91
+ uploadDone: string;
92
+ uploadFailed: string;
93
+ unknownType: string;
94
+ previewUnavailable: string;
95
+ };
96
+ declare const defaultLabels: ExplorerLabels;
97
+ declare function ExplorerLabelsProvider({ labels, children, }: {
98
+ labels?: Partial<ExplorerLabels>;
99
+ children: ReactNode;
100
+ }): React.ReactElement;
101
+ declare function useExplorerLabels(): ExplorerLabels;
102
+
103
+ interface FileExplorerActions {
104
+ readonly deleteFile: (input: {
105
+ id: string;
106
+ }) => Promise<unknown>;
107
+ readonly moveFile: (input: {
108
+ id: string;
109
+ newParentId: string | null;
110
+ newName?: string;
111
+ }) => Promise<unknown>;
112
+ readonly copyFile: (input: {
113
+ id: string;
114
+ newParentId: string | null;
115
+ newName?: string;
116
+ }) => Promise<unknown>;
117
+ readonly renameFile: (id: string, newName: string) => Promise<void>;
118
+ readonly restoreNode?: (input: {
119
+ id: string;
120
+ }) => Promise<unknown>;
121
+ readonly purgeNode?: (input: {
122
+ id: string;
123
+ }) => Promise<unknown>;
124
+ readonly createShare?: (input: {
125
+ id: string;
126
+ }) => Promise<string>;
127
+ readonly createFolder?: (input: {
128
+ name: string;
129
+ parentId: string | null;
130
+ }) => Promise<unknown>;
131
+ }
132
+ type ListPageResult = Result<{
133
+ items: ReadonlyArray<FileNode>;
134
+ nextCursor?: string;
135
+ }, FileSystemError>;
136
+ type OverlayQuery = (input: {
137
+ query?: string;
138
+ cursor?: string;
139
+ limit?: number;
140
+ trash?: boolean;
141
+ }) => Promise<ListPageResult>;
142
+ interface FileExplorerProps {
143
+ readonly tenantId: string;
144
+ readonly parentId: string | null;
145
+ readonly listFiles: (input: {
146
+ parentId: string | null;
147
+ cursor?: string;
148
+ limit?: number;
149
+ }) => Promise<ListPageResult>;
150
+ readonly actions: FileExplorerActions;
151
+ readonly breadcrumbs?: ReadonlyArray<{
152
+ id: string;
153
+ name: string;
154
+ }>;
155
+ readonly onBreadcrumbNavigate?: (seg: {
156
+ id: string;
157
+ name: string;
158
+ }) => void;
159
+ readonly initialView?: "list" | "grid";
160
+ readonly autoFetch?: boolean;
161
+ readonly onActivate?: (file: FileNode) => void;
162
+ readonly onOpenFolder?: (folder: FileNode) => void;
163
+ readonly searchFiles?: OverlayQuery;
164
+ readonly listTrash?: OverlayQuery;
165
+ readonly requestUpload?: (file: {
166
+ name: string;
167
+ size: number;
168
+ type: string;
169
+ content: Blob;
170
+ parentId: string | null;
171
+ }) => Promise<RequestUploadResult>;
172
+ readonly confirmUpload?: () => Promise<void> | void;
173
+ readonly usedBytes?: number;
174
+ readonly quotaBytes?: number;
175
+ readonly onMove?: (input: {
176
+ itemIds: ReadonlyArray<string>;
177
+ destinationFolderId: string;
178
+ }) => Promise<void> | void;
179
+ readonly refreshKey?: number;
180
+ readonly className?: string;
181
+ readonly persistViewKey?: string;
182
+ readonly onPreview?: (file: FileNode) => void;
183
+ readonly onDownload?: (file: FileNode) => void;
184
+ readonly extraFileAction?: {
185
+ label: string;
186
+ onSelect: (file: FileNode) => void;
187
+ };
188
+ readonly protectedIds?: ReadonlyArray<string>;
189
+ readonly labels?: Partial<ExplorerLabels>;
190
+ }
191
+ declare function FileExplorer(props: FileExplorerProps): React.ReactElement;
192
+
193
+ interface ExplorerToolbarProps {
194
+ readonly view: ViewMode;
195
+ readonly onViewChange: (v: ViewMode) => void;
196
+ readonly query?: string;
197
+ readonly onQueryChange?: (query: string) => void;
198
+ readonly trashOpen?: boolean;
199
+ readonly onTrashToggle?: () => void;
200
+ readonly trashHasItems?: boolean;
201
+ readonly onNewFolder?: () => void;
202
+ readonly onUpload?: () => void;
203
+ readonly uploading?: boolean;
204
+ readonly uploadLabel?: string;
205
+ readonly sortKey: ExplorerColumn;
206
+ readonly sortDirection: SortDirection;
207
+ readonly onSortChange: (key: ExplorerColumn) => void;
208
+ readonly className?: string;
209
+ }
210
+ declare function ExplorerToolbar(props: ExplorerToolbarProps): React.ReactElement;
211
+
212
+ interface ExplorerGridViewProps {
213
+ readonly files: ReadonlyArray<FileNode>;
214
+ readonly protectedIds?: ReadonlySet<string>;
215
+ readonly selectedIds: ReadonlySet<string>;
216
+ readonly onSelect: (file: FileNode, event: {
217
+ shiftKey: boolean;
218
+ }) => void;
219
+ readonly onActivate: (file: FileNode) => void;
220
+ readonly onContextMenu?: (file: FileNode, event: React.MouseEvent) => void;
221
+ readonly onDragStart: (id: string) => void;
222
+ readonly onDragEnd: () => void;
223
+ readonly onDrop: (destinationFolderId: string) => void;
224
+ readonly draggingId: string | null;
225
+ readonly draggingIds?: ReadonlySet<string>;
226
+ readonly dropTargetId: string | null;
227
+ readonly onDragOverRow: (id: string | null) => void;
228
+ readonly className?: string;
229
+ }
230
+ declare function ExplorerGridView(props: ExplorerGridViewProps): React.ReactElement;
231
+
232
+ interface ExplorerContextMenuActions {
233
+ readonly deleteFile: (input: {
234
+ id: string;
235
+ }) => Promise<unknown>;
236
+ readonly renameFile: (id: string, newName: string) => Promise<void>;
237
+ readonly restoreNode?: (input: {
238
+ id: string;
239
+ }) => Promise<unknown>;
240
+ readonly purgeNode?: (input: {
241
+ id: string;
242
+ }) => Promise<unknown>;
243
+ readonly createShare?: (input: {
244
+ id: string;
245
+ }) => Promise<string>;
246
+ }
247
+ type ExplorerContextTarget = {
248
+ kind: "item";
249
+ file: FileNode;
250
+ x: number;
251
+ y: number;
252
+ } | {
253
+ kind: "blank";
254
+ x: number;
255
+ y: number;
256
+ };
257
+ interface ExplorerContextMenuProps {
258
+ readonly target: ExplorerContextTarget | null;
259
+ readonly mode?: "browse" | "trash";
260
+ readonly actions: ExplorerContextMenuActions;
261
+ readonly protectedItem?: boolean;
262
+ readonly onClose: () => void;
263
+ readonly onPreview?: (file: FileNode) => void;
264
+ readonly onDownload?: (file: FileNode) => void;
265
+ readonly onRename?: (file: FileNode) => void;
266
+ readonly onRequestDelete?: (file: FileNode) => void;
267
+ readonly onRequestPurge?: (file: FileNode) => void;
268
+ readonly onCopy?: (file: FileNode) => void;
269
+ readonly onPaste?: (folder?: FileNode) => void;
270
+ readonly onNewFolder?: () => void;
271
+ readonly onUpload?: () => void;
272
+ readonly extraFileAction?: {
273
+ label: string;
274
+ onSelect: (file: FileNode) => void;
275
+ };
276
+ }
277
+ declare function ExplorerContextMenu(props: ExplorerContextMenuProps): React.ReactElement | null;
278
+
279
+ interface BreadcrumbsProps {
280
+ readonly segments: ReadonlyArray<{
281
+ id: string;
282
+ name: string;
283
+ }>;
284
+ readonly onNavigate?: (segment: {
285
+ id: string;
286
+ name: string;
287
+ }) => void;
288
+ readonly className?: string;
289
+ }
290
+ declare function Breadcrumbs(props: BreadcrumbsProps): React.ReactElement;
291
+
292
+ interface EmptyStateProps {
293
+ readonly title: string;
294
+ readonly description?: string;
295
+ readonly icon?: ReactNode;
296
+ readonly action?: ReactNode;
297
+ readonly className?: string;
298
+ }
299
+ declare function EmptyState(props: EmptyStateProps): React.ReactElement;
300
+
301
+ interface ErrorStateProps {
302
+ readonly error: FileSystemError | {
303
+ code: string;
304
+ message: string;
305
+ };
306
+ readonly onRetry?: () => void;
307
+ readonly className?: string;
308
+ }
309
+ declare function ErrorState(props: ErrorStateProps): React.ReactElement;
310
+
311
+ interface FileIconProps {
312
+ readonly kind: "file" | "folder";
313
+ readonly mimeType?: string;
314
+ readonly className?: string;
315
+ }
316
+ declare const FILE_ICON_MAP: Record<string, LucideIcon>;
317
+ declare function resolveFileIcon(mimeType: string | undefined): LucideIcon;
318
+ declare function FileIcon(props: FileIconProps): React.ReactElement;
319
+
320
+ declare function canPreviewFile(file: Pick<FileNode, "mimeType" | "name">): boolean;
321
+ declare function FilePreviewDialog({ file, src, onClose, onDownload, }: {
322
+ file: FileNode | null;
323
+ src: string;
324
+ onClose: () => void;
325
+ onDownload: (file: FileNode) => void;
326
+ }): React.ReactElement | null;
327
+
328
+ declare function CreateFolderDialog({ open, onOpenChange, onCreate, title, description, confirmLabel, initialName, }: {
329
+ open: boolean;
330
+ onOpenChange: (open: boolean) => void;
331
+ onCreate: (name: string) => Promise<void> | void;
332
+ title?: string;
333
+ description?: string;
334
+ confirmLabel?: string;
335
+ initialName?: string;
336
+ }): React.ReactElement;
337
+
338
+ declare function ConfirmDeleteDialog({ open, names, permanent, onOpenChange, onConfirm, }: {
339
+ open: boolean;
340
+ names: ReadonlyArray<string>;
341
+ permanent?: boolean;
342
+ onOpenChange: (open: boolean) => void;
343
+ onConfirm: () => Promise<void> | void;
344
+ }): React.ReactElement;
345
+
346
+ declare function ExplorerSelectionToast({ files, protectedIds, trashOpen, onDownload, onCopy, onShare, onDelete, onRestore, onPurge, onClear, }: {
347
+ readonly files: ReadonlyArray<FileNode>;
348
+ readonly protectedIds: ReadonlySet<string>;
349
+ readonly trashOpen: boolean;
350
+ readonly onDownload?: (file: FileNode) => void;
351
+ readonly onCopy?: () => void;
352
+ readonly onShare?: () => void;
353
+ readonly onDelete?: () => void;
354
+ readonly onRestore?: () => void;
355
+ readonly onPurge?: () => void;
356
+ readonly onClear: () => void;
357
+ }): React.ReactElement | null;
358
+ declare function ExplorerClipboardToast({ count, onPaste, onClear, }: {
359
+ readonly count: number;
360
+ readonly onPaste: () => void;
361
+ readonly onClear: () => void;
362
+ }): React.ReactElement | null;
363
+
364
+ type UploadQueueStatus = "queued" | "uploading" | "success" | "error";
365
+ type UploadQueueItem = {
366
+ readonly id: string;
367
+ readonly name: string;
368
+ readonly size: number;
369
+ readonly type: string;
370
+ readonly parentId: string | null;
371
+ readonly status: UploadQueueStatus;
372
+ readonly progress: number;
373
+ readonly error?: string;
374
+ };
375
+ declare function useUploadQueue(options: {
376
+ readonly requestUpload: (file: {
377
+ name: string;
378
+ size: number;
379
+ type: string;
380
+ content: Blob;
381
+ parentId: string | null;
382
+ }) => Promise<RequestUploadResult>;
383
+ readonly confirmUpload?: (file: {
384
+ name: string;
385
+ size: number;
386
+ type: string;
387
+ content: Blob;
388
+ }) => Promise<void> | void;
389
+ }): {
390
+ readonly items: ReadonlyArray<UploadQueueItem>;
391
+ readonly enqueue: (files: ReadonlyArray<File>, parentId: string | null) => void;
392
+ readonly dismiss: () => void;
393
+ readonly active: boolean;
394
+ };
395
+
396
+ declare function ExplorerUploadStatus({ items, onDismiss, className, }: {
397
+ readonly items: ReadonlyArray<UploadQueueItem>;
398
+ readonly onDismiss: () => void;
399
+ readonly className?: string;
400
+ }): React.ReactElement | null;
401
+
402
+ type Enqueue = (files: ReadonlyArray<File>, parentId: string | null) => void;
403
+ declare function useUploadEnqueue(): Enqueue | null;
404
+ declare function UploadQueueProvider({ requestUpload, confirmUpload, children, }: {
405
+ requestUpload: (file: {
406
+ name: string;
407
+ size: number;
408
+ type: string;
409
+ content: Blob;
410
+ parentId: string | null;
411
+ }) => Promise<RequestUploadResult>;
412
+ confirmUpload?: (file: {
413
+ name: string;
414
+ size: number;
415
+ type: string;
416
+ content: Blob;
417
+ }) => Promise<void> | void;
418
+ children: ReactNode;
419
+ }): React.ReactElement;
420
+
421
+ declare function cn(...inputs: ClassValue[]): string;
422
+
423
+ export { Breadcrumbs, type BreadcrumbsProps, ConfirmDeleteDialog, CreateFolderDialog, EmptyState, type EmptyStateProps, ErrorState, type ErrorStateProps, ExplorerClipboardToast, type ExplorerColumn, ExplorerContextMenu, type ExplorerContextMenuProps, type ExplorerContextTarget, ExplorerGridView, type ExplorerGridViewProps, type ExplorerLabels, ExplorerLabelsProvider, ExplorerListView, type ExplorerListViewProps, ExplorerSelectionToast, ExplorerToolbar, type ExplorerToolbarProps, ExplorerUploadStatus, FILE_ICON_MAP, FileExplorer, type FileExplorerActions, type FileExplorerProps, FileIcon, type FileIconProps, FilePreviewDialog, type FileSystemError, type SortDirection, type UploadQueueItem, UploadQueueProvider, canPreviewFile, cn, defaultLabels, resolveFileIcon, useExplorerLabels, useUploadEnqueue, useUploadQueue };