From 6ebfe76f2c51ca8173f6a4a9a89c4c2adb3ec675 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 3 Sep 2025 21:39:23 +0000 Subject: [PATCH 1/4] Change onFilesPicked callback to return files in an object Co-authored-by: guillaume --- README.md | 6 +++--- src/filePicker.ts | 2 +- src/types.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index a7bee8a..864d680 100644 --- a/README.md +++ b/README.md @@ -60,8 +60,8 @@ const options = { showBranding = false, folderSelectionEnabled = true, driveSelectionEnabled = true, - onFilesPicked = (files) => { - console.log('Selected files:', files); + onFilesPicked = (data) => { + console.log('Selected files:', data.files); }, onOpen = () => { console.log('File picker opened'); @@ -93,7 +93,7 @@ const filePicker = new FilePicker(options); | **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: +When you get the callback from the `onFilesPicked` function, you will receive an object with a `files` property containing an array of files you selected. Each file has the following parameters: | Name | Type | Required | Description | | ----------------- | -------- | -------- | ------------------------------------------------------------------------------------------------------------------------- | | **id** | string | **Yes** | The Unified Id for the file. | diff --git a/src/filePicker.ts b/src/filePicker.ts index 3004bf0..7d26b4a 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -13,7 +13,7 @@ export class FilePicker { #fields?: string[]; #folderSelectionEnabled = false; #driveSelectionEnabled = false; - #onFilesPicked: (data: File[]) => void; + #onFilesPicked: (data: { files: File[] }) => void; #onClose: () => void; #onOpen: () => void; #onCancel: () => void; diff --git a/src/types.ts b/src/types.ts index 64285a9..78639f8 100644 --- a/src/types.ts +++ b/src/types.ts @@ -14,7 +14,7 @@ export interface FilePickerOptions { showBranding?: boolean; folderSelectionEnabled?: boolean; driveSelectionEnabled?: boolean; - onFilesPicked?: (data: File[]) => void; + onFilesPicked?: (data: { files: File[] }) => void; onError?: (error: Error) => void; onClose?: () => void; onOpen?: () => void; From 01a82af47a47e94d415c9cca4eee02f6073e7fa5 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 3 Sep 2025 21:43:54 +0000 Subject: [PATCH 2/4] feat: Enhance file picker with folder, drive selection and type support Co-authored-by: guillaume --- README.md | 16 ++++++++++++---- src/filePicker.ts | 7 ++++++- src/types.ts | 9 ++++++++- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 864d680..d81010c 100644 --- a/README.md +++ b/README.md @@ -92,14 +92,22 @@ 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. | +### Callback Data Structure +When you get the callback from the `onFilesPicked` function, you will receive an object with the following structure: +- `files` (required): An array of selected items (files, folders, or drives depending on enabled options) +- `folders` (optional): May contain an array of selected folders when `folderSelectionEnabled` is true +- `drives` (optional): May contain an array of selected drives when `driveSelectionEnabled` is true +- Additional properties may be included depending on the integration + ### File Type -When you get the callback from the `onFilesPicked` function, you will receive an object with a `files` property containing an array of files you selected. Each file has the following parameters: +Each item in the arrays has the following parameters: | 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 item. | +| **path** | string | No | The URL of the item. | +| **driveId** | string | No | The Drive Id of the item. | +| **type** | string | No | The type of the item: 'file', 'folder', or '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. diff --git a/src/filePicker.ts b/src/filePicker.ts index 7d26b4a..4cac2f6 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -13,7 +13,12 @@ export class FilePicker { #fields?: string[]; #folderSelectionEnabled = false; #driveSelectionEnabled = false; - #onFilesPicked: (data: { files: File[] }) => void; + #onFilesPicked: (data: { + files: File[]; + folders?: File[]; + drives?: File[]; + [key: string]: any; + }) => void; #onClose: () => void; #onOpen: () => void; #onCancel: () => void; diff --git a/src/types.ts b/src/types.ts index 78639f8..fc5ed9c 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,6 +3,8 @@ export type File = { name?: string; path?: string; driveId?: string; + type?: 'file' | 'folder' | 'drive'; + [key: string]: any; // Allow for additional properties }; export interface FilePickerOptions { @@ -14,7 +16,12 @@ export interface FilePickerOptions { showBranding?: boolean; folderSelectionEnabled?: boolean; driveSelectionEnabled?: boolean; - onFilesPicked?: (data: { files: File[] }) => void; + onFilesPicked?: (data: { + files: File[]; + folders?: File[]; + drives?: File[]; + [key: string]: any; // Allow for additional properties + }) => void; onError?: (error: Error) => void; onClose?: () => void; onOpen?: () => void; From 07f83d115017273044b3ce7bda4dd98e82bb97dd Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 3 Sep 2025 21:58:51 +0000 Subject: [PATCH 3/4] Refactor file picker types and documentation for better clarity Co-authored-by: guillaume --- README.md | 44 +++++++++++++++++++++++++++++++------------- src/filePicker.ts | 9 ++++----- src/index.ts | 2 +- src/types.ts | 23 +++++++++++++++++------ 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index d81010c..dac315a 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,16 @@ const options = { folderSelectionEnabled = true, driveSelectionEnabled = true, onFilesPicked = (data) => { - console.log('Selected files:', data.files); + // 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'); @@ -93,21 +102,30 @@ const filePicker = new FilePicker(options); | **onError()** | function | No | Called when the file picker has an error. | ### Callback Data Structure -When you get the callback from the `onFilesPicked` function, you will receive an object with the following structure: -- `files` (required): An array of selected items (files, folders, or drives depending on enabled options) -- `folders` (optional): May contain an array of selected folders when `folderSelectionEnabled` is true -- `drives` (optional): May contain an array of selected drives when `driveSelectionEnabled` is true -- Additional properties may be included depending on the integration - -### File Type -Each item in the arrays has the following parameters: +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 item. | -| **path** | string | No | The URL of the item. | -| **driveId** | string | No | The Drive Id of the item. | -| **type** | string | No | The type of the item: 'file', 'folder', or 'drive'. | +| **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. diff --git a/src/filePicker.ts b/src/filePicker.ts index 4cac2f6..c881236 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -1,4 +1,4 @@ -import { File, FilePickerOptions } from './types'; +import { File, Folder, Drive, FilePickerOptions } from './types'; import { createIFrameInDocument } from './utils/dom'; import { createUrl } from './utils/url'; @@ -14,10 +14,9 @@ export class FilePicker { #folderSelectionEnabled = false; #driveSelectionEnabled = false; #onFilesPicked: (data: { - files: File[]; - folders?: File[]; - drives?: File[]; - [key: string]: any; + files?: File[]; + folders?: Folder[]; + drives?: Drive[]; }) => void; #onClose: () => void; #onOpen: () => void; diff --git a/src/index.ts b/src/index.ts index 4388457..9a04028 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ export { FilePicker } from './filePicker'; -export type { File } from './types'; +export type { File, Folder, Drive, FilePickerOptions } from './types'; diff --git a/src/types.ts b/src/types.ts index fc5ed9c..014ee85 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,8 +3,20 @@ export type File = { name?: string; path?: string; driveId?: string; - type?: 'file' | 'folder' | 'drive'; - [key: string]: any; // Allow for additional properties +}; + +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 { @@ -17,10 +29,9 @@ export interface FilePickerOptions { folderSelectionEnabled?: boolean; driveSelectionEnabled?: boolean; onFilesPicked?: (data: { - files: File[]; - folders?: File[]; - drives?: File[]; - [key: string]: any; // Allow for additional properties + files?: File[]; + folders?: Folder[]; + drives?: Drive[]; }) => void; onError?: (error: Error) => void; onClose?: () => void; From 232bd9fedb239a074051b8daa50d20e6c1f8df2e Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 3 Sep 2025 22:02:30 +0000 Subject: [PATCH 4/4] Refactor: Reformat import and callback type order in types and filePicker Co-authored-by: guillaume --- src/filePicker.ts | 8 ++++---- src/types.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/filePicker.ts b/src/filePicker.ts index c881236..9059dab 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -1,4 +1,4 @@ -import { File, Folder, Drive, FilePickerOptions } from './types'; +import { Drive, File, FilePickerOptions, Folder } from './types'; import { createIFrameInDocument } from './utils/dom'; import { createUrl } from './utils/url'; @@ -13,9 +13,9 @@ export class FilePicker { #fields?: string[]; #folderSelectionEnabled = false; #driveSelectionEnabled = false; - #onFilesPicked: (data: { - files?: File[]; - folders?: Folder[]; + #onFilesPicked: (data: { + files?: File[]; + folders?: Folder[]; drives?: Drive[]; }) => void; #onClose: () => void; diff --git a/src/types.ts b/src/types.ts index 014ee85..86d440a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,9 +28,9 @@ export interface FilePickerOptions { showBranding?: boolean; folderSelectionEnabled?: boolean; driveSelectionEnabled?: boolean; - onFilesPicked?: (data: { - files?: File[]; - folders?: Folder[]; + onFilesPicked?: (data: { + files?: File[]; + folders?: Folder[]; drives?: Drive[]; }) => void; onError?: (error: Error) => void;