Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ const options = {
showBranding = false,
folderSelectionEnabled = true,
driveSelectionEnabled = true,
onFilesPicked = (files) => {
console.log('Selected files:', files);
onFilesPicked = (data) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use ':' for the object property; '=' makes the example invalid JavaScript.

Prompt for AI agents
Address the following comment on README.md at line 63:

<comment>Use &#39;:&#39; for the object property; &#39;=&#39; makes the example invalid JavaScript.</comment>

<file context>
@@ -60,8 +60,17 @@ const options = {
     driveSelectionEnabled = true,
-    onFilesPicked = (files) =&gt; {
-        console.log(&#39;Selected files:&#39;, files);
+    onFilesPicked = (data) =&gt; {
+        // data may contain files, folders, and/or drives based on what was selected
+        if (data.files) {
</file context>

// data may contain files, folders, and/or drives based on what was selected
if (data.files) {
console.log('Selected files:', data.files);
}
if (data.folders) {
console.log('Selected folders:', data.folders);
}
if (data.drives) {
console.log('Selected drives:', data.drives);
}
},
onOpen = () => {
console.log('File picker opened');
Expand Down Expand Up @@ -92,14 +101,31 @@ const filePicker = new FilePicker(options);
| **onCancel()** | function | No | Called when the file picker is closed without a file being selected. |
| **onError()** | function | No | Called when the file picker has an error. |

### File Type
When you get the callback from the `onFilesPicked` function, you will receive an array of files you selected with the following parameters:
### Callback Data Structure
When you get the callback from the `onFilesPicked` function, you will receive an object that may contain one or more of the following properties based on what was selected:
- `files` (optional): An array of selected files
- `folders` (optional): An array of selected folders when `folderSelectionEnabled` is true
- `drives` (optional): An array of selected drives/sites when `driveSelectionEnabled` is true

Note: The callback will only include the arrays that have items. For example, if only files are selected, only the `files` property will be present.

### File and Folder Types
Files and folders share the same structure:
| Name | Type | Required | Description |
| ----------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| **id** | string | **Yes** | The Unified Id for the file. |
| **name** | string | No | The Name of the file. |
| **path** | string | No | The URL of the file. |
| **driveId** | string | No | The Drive Id of the file. |
| **name** | string | No | The name of the file or folder. |
| **path** | string | No | The URL or path of the file or folder. |
| **driveId** | string | No | The Drive ID where the file or folder is located. |

### Drive Type
Drives have a different structure:
| Name | Type | Required | Description |
| ----------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------- |
| **id** | string | **Yes** | The Unified Id for the drive. |
| **name** | string | No | The name of the drive or site. |
| **type** | string | No | Will be 'site' for drives. |
| **createdAt** | string | No | The creation date of the drive. |
## Contribute & Release

This repose uses [conventional commit](https://www.conventionalcommits.org/en/v1.0.0/). The repo use semantic-release and the package version is automatically determined based on the commit messages.
Expand Down
8 changes: 6 additions & 2 deletions src/filePicker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { File, FilePickerOptions } from './types';
import { Drive, File, FilePickerOptions, Folder } from './types';
import { createIFrameInDocument } from './utils/dom';
import { createUrl } from './utils/url';

Expand All @@ -13,7 +13,11 @@ export class FilePicker {
#fields?: string[];
#folderSelectionEnabled = false;
#driveSelectionEnabled = false;
#onFilesPicked: (data: File[]) => void;
#onFilesPicked: (data: {
files?: File[];
folders?: Folder[];
drives?: Drive[];
}) => void;
#onClose: () => void;
#onOpen: () => void;
#onCancel: () => void;
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { FilePicker } from './filePicker';
export type { File } from './types';
export type { File, Folder, Drive, FilePickerOptions } from './types';
20 changes: 19 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ export type File = {
driveId?: string;
};

export type Folder = {
id: string;
name?: string;
path?: string;
driveId?: string;
};

export type Drive = {
id: string;
name?: string;
type?: 'site';
createdAt?: string;
};

export interface FilePickerOptions {
sessionToken: string;
containerId?: string;
Expand All @@ -14,7 +28,11 @@ export interface FilePickerOptions {
showBranding?: boolean;
folderSelectionEnabled?: boolean;
driveSelectionEnabled?: boolean;
onFilesPicked?: (data: File[]) => void;
onFilesPicked?: (data: {
files?: File[];
folders?: Folder[];
drives?: Drive[];
}) => void;
onError?: (error: Error) => void;
onClose?: () => void;
onOpen?: () => void;
Expand Down