@sqlrooms/s3-browser 0.6.0 → 0.8.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/README.md +176 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/README.md
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
This package is part of the SQLRooms framework.
|
|
2
|
+
|
|
3
|
+
# S3 Browser
|
|
4
|
+
|
|
5
|
+
A React component library for browsing and interacting with S3-compatible storage services.
|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Directory navigation with breadcrumbs
|
|
12
|
+
- File and directory listing
|
|
13
|
+
- Multiple file selection
|
|
14
|
+
- File metadata display (size, type, last modified)
|
|
15
|
+
- S3 utility functions for listing and deleting files
|
|
16
|
+
|
|
17
|
+
## Installation
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install @sqlrooms/s3-browser
|
|
21
|
+
# or
|
|
22
|
+
yarn add @sqlrooms/s3-browser
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
### S3FileBrowser Component
|
|
28
|
+
|
|
29
|
+
The `S3FileBrowser` component provides a familiar file explorer interface for navigating and selecting files from an S3-like storage.
|
|
30
|
+
|
|
31
|
+
```tsx
|
|
32
|
+
import {S3FileBrowser} from '@sqlrooms/s3-browser';
|
|
33
|
+
import {useState} from 'react';
|
|
34
|
+
|
|
35
|
+
function MyS3Browser() {
|
|
36
|
+
const [selectedFiles, setSelectedFiles] = useState<string[]>([]);
|
|
37
|
+
const [selectedDirectory, setSelectedDirectory] = useState('');
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<S3FileBrowser
|
|
41
|
+
files={[
|
|
42
|
+
{key: 'documents', isDirectory: true},
|
|
43
|
+
{
|
|
44
|
+
key: 'example.txt',
|
|
45
|
+
isDirectory: false,
|
|
46
|
+
size: 1024,
|
|
47
|
+
contentType: 'text/plain',
|
|
48
|
+
lastModified: new Date(),
|
|
49
|
+
},
|
|
50
|
+
]}
|
|
51
|
+
selectedFiles={selectedFiles}
|
|
52
|
+
selectedDirectory={selectedDirectory}
|
|
53
|
+
onCanConfirmChange={(canConfirm) =>
|
|
54
|
+
console.log('Can confirm:', canConfirm)
|
|
55
|
+
}
|
|
56
|
+
onChangeSelectedDirectory={setSelectedDirectory}
|
|
57
|
+
onChangeSelectedFiles={setSelectedFiles}
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### S3 Utility Functions
|
|
64
|
+
|
|
65
|
+
The package also provides utility functions for working with S3:
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import {S3Client} from '@aws-sdk/client-s3';
|
|
69
|
+
import {
|
|
70
|
+
listFilesAndDirectoriesWithPrefix,
|
|
71
|
+
deleteS3Files,
|
|
72
|
+
} from '@sqlrooms/s3-browser';
|
|
73
|
+
|
|
74
|
+
// Initialize S3 client
|
|
75
|
+
const s3Client = new S3Client({region: 'us-east-1'});
|
|
76
|
+
|
|
77
|
+
// List files and directories
|
|
78
|
+
async function listFiles() {
|
|
79
|
+
const files = await listFilesAndDirectoriesWithPrefix(
|
|
80
|
+
s3Client,
|
|
81
|
+
'my-bucket',
|
|
82
|
+
'path/to/directory',
|
|
83
|
+
);
|
|
84
|
+
console.log(files);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Delete files with a prefix
|
|
88
|
+
async function deleteFiles() {
|
|
89
|
+
await deleteS3Files(s3Client, 'my-bucket', 'path/to/delete');
|
|
90
|
+
}
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## API Reference
|
|
94
|
+
|
|
95
|
+
### S3FileBrowser
|
|
96
|
+
|
|
97
|
+
```tsx
|
|
98
|
+
interface S3FileBrowserProps {
|
|
99
|
+
/**
|
|
100
|
+
* Array of files and directories to display
|
|
101
|
+
*/
|
|
102
|
+
files?: S3FileOrDirectory[];
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Array of currently selected file keys
|
|
106
|
+
*/
|
|
107
|
+
selectedFiles: string[];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Current directory path (empty string for root)
|
|
111
|
+
*/
|
|
112
|
+
selectedDirectory: string;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Callback fired when selection state changes
|
|
116
|
+
*/
|
|
117
|
+
onCanConfirmChange: (canConfirm: boolean) => void;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Callback fired when directory navigation occurs
|
|
121
|
+
*/
|
|
122
|
+
onChangeSelectedDirectory: (directory: string) => void;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Callback fired when file selection changes
|
|
126
|
+
*/
|
|
127
|
+
onChangeSelectedFiles: (files: string[]) => void;
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### S3FileOrDirectory
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
type S3FileOrDirectory =
|
|
135
|
+
| {
|
|
136
|
+
key: string;
|
|
137
|
+
isDirectory: true;
|
|
138
|
+
}
|
|
139
|
+
| {
|
|
140
|
+
key: string;
|
|
141
|
+
isDirectory: false;
|
|
142
|
+
lastModified?: Date;
|
|
143
|
+
size?: number;
|
|
144
|
+
contentType?: string;
|
|
145
|
+
};
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
### Utility Functions
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
/**
|
|
152
|
+
* Lists files and directories with a given prefix
|
|
153
|
+
*/
|
|
154
|
+
function listFilesAndDirectoriesWithPrefix(
|
|
155
|
+
S3: S3Client,
|
|
156
|
+
bucket: string,
|
|
157
|
+
prefix?: string,
|
|
158
|
+
): Promise<S3FileOrDirectory[]>;
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Delete all files with the given prefix
|
|
162
|
+
*/
|
|
163
|
+
function deleteS3Files(
|
|
164
|
+
S3: S3Client,
|
|
165
|
+
bucket: string,
|
|
166
|
+
prefix: string,
|
|
167
|
+
): Promise<void>;
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Dependencies
|
|
171
|
+
|
|
172
|
+
- @aws-sdk/client-s3
|
|
173
|
+
- React
|
|
174
|
+
- @sqlrooms/ui (for UI components)
|
|
175
|
+
- @sqlrooms/utils (for formatting utilities)
|
|
176
|
+
- zod (for type validation)
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,iBAAiB,CAAC;AACzD,cAAc,MAAM,CAAC;AACrB,cAAc,qBAAqB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,iBAAiB,CAAC;AACzD,cAAc,MAAM,CAAC;AACrB,cAAc,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,iBAAiB,CAAC;AACzD,cAAc,MAAM,CAAC;AACrB,cAAc,qBAAqB,CAAC","sourcesContent":["
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAC,OAAO,IAAI,aAAa,EAAC,MAAM,iBAAiB,CAAC;AACzD,cAAc,MAAM,CAAC;AACrB,cAAc,qBAAqB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\nexport {default as S3FileBrowser} from './S3FileBrowser';\nexport * from './s3';\nexport * from './S3FileOrDirectory';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/s3-browser",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@aws-sdk/client-s3": "^3.726.1",
|
|
23
|
-
"@sqlrooms/ui": "0.
|
|
24
|
-
"@sqlrooms/utils": "0.
|
|
23
|
+
"@sqlrooms/ui": "0.8.0",
|
|
24
|
+
"@sqlrooms/utils": "0.8.0",
|
|
25
25
|
"lucide-react": "^0.474.0",
|
|
26
26
|
"zod": "^3.24.1"
|
|
27
27
|
},
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"lint": "eslint .",
|
|
35
35
|
"typedoc": "typedoc"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "99b46a96ab900e6b005bcd30cfbfe7b3c9d51f8d"
|
|
38
38
|
}
|