@plugable-io/react 0.0.1 → 0.0.3
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/README.md +33 -0
- package/dist/index.d.mts +125 -0
- package/dist/index.d.ts +125 -0
- package/dist/index.js +708 -0
- package/dist/index.mjs +664 -0
- package/package.json +9 -2
package/README.md
CHANGED
|
@@ -238,6 +238,37 @@ function ImageGallery() {
|
|
|
238
238
|
}
|
|
239
239
|
```
|
|
240
240
|
|
|
241
|
+
### Ordering Files
|
|
242
|
+
|
|
243
|
+
```tsx
|
|
244
|
+
function SortedFileList() {
|
|
245
|
+
const [orderBy, setOrderBy] = useState<'created_at' | 'name' | 'byte_size'>('created_at');
|
|
246
|
+
const [orderDirection, setOrderDirection] = useState<'asc' | 'desc'>('desc');
|
|
247
|
+
|
|
248
|
+
const { files, isLoading } = useFiles({
|
|
249
|
+
orderBy,
|
|
250
|
+
orderDirection,
|
|
251
|
+
perPage: 20,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
<div>
|
|
256
|
+
<select value={orderBy} onChange={(e) => setOrderBy(e.target.value as any)}>
|
|
257
|
+
<option value="created_at">Date</option>
|
|
258
|
+
<option value="name">Name</option>
|
|
259
|
+
<option value="byte_size">Size</option>
|
|
260
|
+
</select>
|
|
261
|
+
<button onClick={() => setOrderDirection(orderDirection === 'asc' ? 'desc' : 'asc')}>
|
|
262
|
+
{orderDirection === 'asc' ? '↑' : '↓'}
|
|
263
|
+
</button>
|
|
264
|
+
{files.map((file) => (
|
|
265
|
+
<div key={file.id}>{file.name}</div>
|
|
266
|
+
))}
|
|
267
|
+
</div>
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
```
|
|
271
|
+
|
|
241
272
|
### Manual Loading
|
|
242
273
|
|
|
243
274
|
```tsx
|
|
@@ -268,6 +299,8 @@ function LazyFileList() {
|
|
|
268
299
|
| `perPage` | `number` | `20` | Files per page |
|
|
269
300
|
| `startPage` | `number` | `1` | Initial page number |
|
|
270
301
|
| `autoLoad` | `boolean` | `true` | Fetch on mount |
|
|
302
|
+
| `orderBy` | `'created_at' \| 'name' \| 'byte_size'` | `'created_at'` | Field to order by |
|
|
303
|
+
| `orderDirection` | `'asc' \| 'desc'` | `'desc'` | Sort direction |
|
|
271
304
|
|
|
272
305
|
### Return Value
|
|
273
306
|
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { BucketClient, FileObject } from '@plugable-io/js';
|
|
4
|
+
export { FileObject, SearchOptions, UpdateOptions } from '@plugable-io/js';
|
|
5
|
+
|
|
6
|
+
type AuthProvider = 'clerk' | 'supabase' | 'firebase';
|
|
7
|
+
interface PlugableProviderProps {
|
|
8
|
+
bucketId: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
getToken?: () => Promise<string> | string;
|
|
11
|
+
authProvider?: AuthProvider;
|
|
12
|
+
clerkJWTTemplate?: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
type PlugableEventType = 'file.uploaded' | 'file.deleted';
|
|
16
|
+
type EventHandler = (data?: any) => void;
|
|
17
|
+
interface PlugableContextValue {
|
|
18
|
+
client: BucketClient;
|
|
19
|
+
bucketId: string;
|
|
20
|
+
on: (event: PlugableEventType, handler: EventHandler) => () => void;
|
|
21
|
+
emit: (event: PlugableEventType, data?: any) => void;
|
|
22
|
+
getToken: () => Promise<string> | string;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function PlugableProvider({ bucketId, children, getToken, authProvider, clerkJWTTemplate, baseUrl, }: PlugableProviderProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
declare function usePlugable(): PlugableContextValue;
|
|
27
|
+
|
|
28
|
+
interface DropzoneProps {
|
|
29
|
+
bucketId?: string;
|
|
30
|
+
metadata?: Record<string, any>;
|
|
31
|
+
onUploadComplete?: (files: FileObject[]) => void;
|
|
32
|
+
onUploadError?: (error: Error) => void;
|
|
33
|
+
onProgressUpdate?: (fileName: string, progress: number) => void;
|
|
34
|
+
accept?: string;
|
|
35
|
+
maxFiles?: number;
|
|
36
|
+
children?: (props: DropzoneRenderProps) => ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
style?: React.CSSProperties;
|
|
39
|
+
}
|
|
40
|
+
interface DropzoneRenderProps {
|
|
41
|
+
isDragActive: boolean;
|
|
42
|
+
isUploading: boolean;
|
|
43
|
+
uploadProgress: Record<string, number>;
|
|
44
|
+
openFileDialog: () => void;
|
|
45
|
+
uploadedFiles: FileObject[];
|
|
46
|
+
}
|
|
47
|
+
declare function Dropzone({ bucketId: _bucketId, metadata, onUploadComplete, onUploadError, onProgressUpdate, accept, maxFiles, children, className, style, }: DropzoneProps): react_jsx_runtime.JSX.Element;
|
|
48
|
+
|
|
49
|
+
interface FileListProps {
|
|
50
|
+
metadata?: Record<string, any>;
|
|
51
|
+
mediaType?: string;
|
|
52
|
+
perPage?: number;
|
|
53
|
+
autoLoad?: boolean;
|
|
54
|
+
startPage?: number;
|
|
55
|
+
children: (props: FileListRenderProps) => ReactNode;
|
|
56
|
+
}
|
|
57
|
+
interface FileListRenderProps {
|
|
58
|
+
files: FileObject[];
|
|
59
|
+
isLoading: boolean;
|
|
60
|
+
hasMore: boolean;
|
|
61
|
+
loadMore: () => void;
|
|
62
|
+
refresh: () => Promise<void>;
|
|
63
|
+
error: Error | null;
|
|
64
|
+
pagination: {
|
|
65
|
+
current: number;
|
|
66
|
+
hasNext: boolean;
|
|
67
|
+
hasPrevious: boolean;
|
|
68
|
+
loadNextPage: () => void;
|
|
69
|
+
loadPreviousPage: () => void;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
declare function FileList({ metadata, mediaType, perPage, autoLoad, startPage, children, }: FileListProps): react_jsx_runtime.JSX.Element;
|
|
73
|
+
|
|
74
|
+
interface FileImageProps {
|
|
75
|
+
file: FileObject;
|
|
76
|
+
width?: number | string;
|
|
77
|
+
height?: number | string;
|
|
78
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
79
|
+
borderRadius?: number | string;
|
|
80
|
+
alt?: string;
|
|
81
|
+
className?: string;
|
|
82
|
+
style?: CSSProperties;
|
|
83
|
+
onLoad?: () => void;
|
|
84
|
+
onError?: (error: Error) => void;
|
|
85
|
+
}
|
|
86
|
+
declare function FileImage({ file, width, height, objectFit, borderRadius, alt, className, style, onLoad, onError, }: FileImageProps): react_jsx_runtime.JSX.Element;
|
|
87
|
+
declare function clearImageCache(): void;
|
|
88
|
+
|
|
89
|
+
interface FilePreviewProps {
|
|
90
|
+
file: FileObject;
|
|
91
|
+
width?: number | string;
|
|
92
|
+
height?: number | string;
|
|
93
|
+
className?: string;
|
|
94
|
+
style?: CSSProperties;
|
|
95
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
96
|
+
showExtension?: boolean;
|
|
97
|
+
renderNonImage?: (file: FileObject) => React.ReactNode;
|
|
98
|
+
}
|
|
99
|
+
declare function FilePreview({ file, width, height, className, style, objectFit, showExtension, renderNonImage, }: FilePreviewProps): react_jsx_runtime.JSX.Element;
|
|
100
|
+
|
|
101
|
+
interface UseFilesOptions {
|
|
102
|
+
metadata?: Record<string, any>;
|
|
103
|
+
startPage?: number;
|
|
104
|
+
perPage?: number;
|
|
105
|
+
mediaType?: string;
|
|
106
|
+
autoLoad?: boolean;
|
|
107
|
+
orderBy?: 'created_at' | 'name' | 'byte_size';
|
|
108
|
+
orderDirection?: 'asc' | 'desc';
|
|
109
|
+
}
|
|
110
|
+
interface UseFilesResult {
|
|
111
|
+
files: FileObject[];
|
|
112
|
+
isLoading: boolean;
|
|
113
|
+
pagination: {
|
|
114
|
+
current: number;
|
|
115
|
+
hasNext: boolean;
|
|
116
|
+
hasPrevious: boolean;
|
|
117
|
+
loadNextPage: () => void;
|
|
118
|
+
loadPreviousPage: () => void;
|
|
119
|
+
};
|
|
120
|
+
setPage: (page: number) => void;
|
|
121
|
+
refresh: () => Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
declare function useFiles({ metadata, startPage, perPage, mediaType, autoLoad, orderBy, orderDirection, }?: UseFilesOptions): UseFilesResult;
|
|
124
|
+
|
|
125
|
+
export { type AuthProvider, Dropzone, type DropzoneProps, type DropzoneRenderProps, FileImage, type FileImageProps, FileList, type FileListProps, type FileListRenderProps, FilePreview, type FilePreviewProps, PlugableProvider, type PlugableProviderProps, type UseFilesOptions, type UseFilesResult, clearImageCache, useFiles, usePlugable };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import React, { ReactNode, CSSProperties } from 'react';
|
|
3
|
+
import { BucketClient, FileObject } from '@plugable-io/js';
|
|
4
|
+
export { FileObject, SearchOptions, UpdateOptions } from '@plugable-io/js';
|
|
5
|
+
|
|
6
|
+
type AuthProvider = 'clerk' | 'supabase' | 'firebase';
|
|
7
|
+
interface PlugableProviderProps {
|
|
8
|
+
bucketId: string;
|
|
9
|
+
children: ReactNode;
|
|
10
|
+
getToken?: () => Promise<string> | string;
|
|
11
|
+
authProvider?: AuthProvider;
|
|
12
|
+
clerkJWTTemplate?: string;
|
|
13
|
+
baseUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
type PlugableEventType = 'file.uploaded' | 'file.deleted';
|
|
16
|
+
type EventHandler = (data?: any) => void;
|
|
17
|
+
interface PlugableContextValue {
|
|
18
|
+
client: BucketClient;
|
|
19
|
+
bucketId: string;
|
|
20
|
+
on: (event: PlugableEventType, handler: EventHandler) => () => void;
|
|
21
|
+
emit: (event: PlugableEventType, data?: any) => void;
|
|
22
|
+
getToken: () => Promise<string> | string;
|
|
23
|
+
baseUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
declare function PlugableProvider({ bucketId, children, getToken, authProvider, clerkJWTTemplate, baseUrl, }: PlugableProviderProps): react_jsx_runtime.JSX.Element;
|
|
26
|
+
declare function usePlugable(): PlugableContextValue;
|
|
27
|
+
|
|
28
|
+
interface DropzoneProps {
|
|
29
|
+
bucketId?: string;
|
|
30
|
+
metadata?: Record<string, any>;
|
|
31
|
+
onUploadComplete?: (files: FileObject[]) => void;
|
|
32
|
+
onUploadError?: (error: Error) => void;
|
|
33
|
+
onProgressUpdate?: (fileName: string, progress: number) => void;
|
|
34
|
+
accept?: string;
|
|
35
|
+
maxFiles?: number;
|
|
36
|
+
children?: (props: DropzoneRenderProps) => ReactNode;
|
|
37
|
+
className?: string;
|
|
38
|
+
style?: React.CSSProperties;
|
|
39
|
+
}
|
|
40
|
+
interface DropzoneRenderProps {
|
|
41
|
+
isDragActive: boolean;
|
|
42
|
+
isUploading: boolean;
|
|
43
|
+
uploadProgress: Record<string, number>;
|
|
44
|
+
openFileDialog: () => void;
|
|
45
|
+
uploadedFiles: FileObject[];
|
|
46
|
+
}
|
|
47
|
+
declare function Dropzone({ bucketId: _bucketId, metadata, onUploadComplete, onUploadError, onProgressUpdate, accept, maxFiles, children, className, style, }: DropzoneProps): react_jsx_runtime.JSX.Element;
|
|
48
|
+
|
|
49
|
+
interface FileListProps {
|
|
50
|
+
metadata?: Record<string, any>;
|
|
51
|
+
mediaType?: string;
|
|
52
|
+
perPage?: number;
|
|
53
|
+
autoLoad?: boolean;
|
|
54
|
+
startPage?: number;
|
|
55
|
+
children: (props: FileListRenderProps) => ReactNode;
|
|
56
|
+
}
|
|
57
|
+
interface FileListRenderProps {
|
|
58
|
+
files: FileObject[];
|
|
59
|
+
isLoading: boolean;
|
|
60
|
+
hasMore: boolean;
|
|
61
|
+
loadMore: () => void;
|
|
62
|
+
refresh: () => Promise<void>;
|
|
63
|
+
error: Error | null;
|
|
64
|
+
pagination: {
|
|
65
|
+
current: number;
|
|
66
|
+
hasNext: boolean;
|
|
67
|
+
hasPrevious: boolean;
|
|
68
|
+
loadNextPage: () => void;
|
|
69
|
+
loadPreviousPage: () => void;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
declare function FileList({ metadata, mediaType, perPage, autoLoad, startPage, children, }: FileListProps): react_jsx_runtime.JSX.Element;
|
|
73
|
+
|
|
74
|
+
interface FileImageProps {
|
|
75
|
+
file: FileObject;
|
|
76
|
+
width?: number | string;
|
|
77
|
+
height?: number | string;
|
|
78
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
79
|
+
borderRadius?: number | string;
|
|
80
|
+
alt?: string;
|
|
81
|
+
className?: string;
|
|
82
|
+
style?: CSSProperties;
|
|
83
|
+
onLoad?: () => void;
|
|
84
|
+
onError?: (error: Error) => void;
|
|
85
|
+
}
|
|
86
|
+
declare function FileImage({ file, width, height, objectFit, borderRadius, alt, className, style, onLoad, onError, }: FileImageProps): react_jsx_runtime.JSX.Element;
|
|
87
|
+
declare function clearImageCache(): void;
|
|
88
|
+
|
|
89
|
+
interface FilePreviewProps {
|
|
90
|
+
file: FileObject;
|
|
91
|
+
width?: number | string;
|
|
92
|
+
height?: number | string;
|
|
93
|
+
className?: string;
|
|
94
|
+
style?: CSSProperties;
|
|
95
|
+
objectFit?: 'contain' | 'cover' | 'fill' | 'none' | 'scale-down';
|
|
96
|
+
showExtension?: boolean;
|
|
97
|
+
renderNonImage?: (file: FileObject) => React.ReactNode;
|
|
98
|
+
}
|
|
99
|
+
declare function FilePreview({ file, width, height, className, style, objectFit, showExtension, renderNonImage, }: FilePreviewProps): react_jsx_runtime.JSX.Element;
|
|
100
|
+
|
|
101
|
+
interface UseFilesOptions {
|
|
102
|
+
metadata?: Record<string, any>;
|
|
103
|
+
startPage?: number;
|
|
104
|
+
perPage?: number;
|
|
105
|
+
mediaType?: string;
|
|
106
|
+
autoLoad?: boolean;
|
|
107
|
+
orderBy?: 'created_at' | 'name' | 'byte_size';
|
|
108
|
+
orderDirection?: 'asc' | 'desc';
|
|
109
|
+
}
|
|
110
|
+
interface UseFilesResult {
|
|
111
|
+
files: FileObject[];
|
|
112
|
+
isLoading: boolean;
|
|
113
|
+
pagination: {
|
|
114
|
+
current: number;
|
|
115
|
+
hasNext: boolean;
|
|
116
|
+
hasPrevious: boolean;
|
|
117
|
+
loadNextPage: () => void;
|
|
118
|
+
loadPreviousPage: () => void;
|
|
119
|
+
};
|
|
120
|
+
setPage: (page: number) => void;
|
|
121
|
+
refresh: () => Promise<void>;
|
|
122
|
+
}
|
|
123
|
+
declare function useFiles({ metadata, startPage, perPage, mediaType, autoLoad, orderBy, orderDirection, }?: UseFilesOptions): UseFilesResult;
|
|
124
|
+
|
|
125
|
+
export { type AuthProvider, Dropzone, type DropzoneProps, type DropzoneRenderProps, FileImage, type FileImageProps, FileList, type FileListProps, type FileListRenderProps, FilePreview, type FilePreviewProps, PlugableProvider, type PlugableProviderProps, type UseFilesOptions, type UseFilesResult, clearImageCache, useFiles, usePlugable };
|