diff --git a/README.md b/README.md index ad63b44..a7bee8a 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ const options = { fields = ['name', 'path', 'driveId'], showBranding = false, folderSelectionEnabled = true, + driveSelectionEnabled = true, onFilesPicked = (files) => { console.log('Selected files:', files); }, @@ -84,6 +85,7 @@ const filePicker = new FilePicker(options); | **fields** | string[] | No | Which fields from the raw picked file will be mapped on the files picked callback. | | **showBranding** | boolean | No | Show StackOne footer on the file picker, it is defaulted to true. | | **folderSelectionEnabled** | boolean | No | Enable the selection of folders on the unified and native pickers. | +| **driveSelectionEnabled** | boolean | No | Enable the selection of drives on the unified and native pickers. | | **onFilesPicked** | function | No | Called when files are selected. | | **onOpen()** | function | No | Called when the file picker is opened. | | **onClose()** | function | No | Called every time the file picker is closed regardless of whether a file has been picked or not. | diff --git a/src/filePicker.ts b/src/filePicker.ts index 27dcdfe..3004bf0 100644 --- a/src/filePicker.ts +++ b/src/filePicker.ts @@ -12,6 +12,7 @@ export class FilePicker { #showBranding = true; #fields?: string[]; #folderSelectionEnabled = false; + #driveSelectionEnabled = false; #onFilesPicked: (data: File[]) => void; #onClose: () => void; #onOpen: () => void; @@ -27,6 +28,7 @@ export class FilePicker { fields, showBranding, folderSelectionEnabled, + driveSelectionEnabled, onFilesPicked, onClose, onOpen, @@ -40,6 +42,7 @@ export class FilePicker { this.#apiUrl = apiUrl ?? 'https://api.stackone.com'; this.#showBranding = showBranding ?? true; this.#folderSelectionEnabled = folderSelectionEnabled ?? false; + this.#driveSelectionEnabled = driveSelectionEnabled ?? false; this.#onFilesPicked = onFilesPicked ?? (() => {}); this.#onClose = onClose ?? (() => {}); this.#onOpen = onOpen ?? (() => {}); @@ -79,6 +82,7 @@ export class FilePicker { this.#apiUrl, this.#showBranding, this.#folderSelectionEnabled, + this.#driveSelectionEnabled, ); this.#iframe.src = url; } diff --git a/src/types.ts b/src/types.ts index 9811902..64285a9 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,6 +13,7 @@ export interface FilePickerOptions { fields?: string[]; showBranding?: boolean; folderSelectionEnabled?: boolean; + driveSelectionEnabled?: boolean; onFilesPicked?: (data: File[]) => void; onError?: (error: Error) => void; onClose?: () => void; diff --git a/src/utils/url.ts b/src/utils/url.ts index e9328c2..9b3d8bb 100644 --- a/src/utils/url.ts +++ b/src/utils/url.ts @@ -6,12 +6,14 @@ export const createUrl = ( apiUrl?: string, showBranding?: boolean, folderSelectionEnabled?: boolean, + driveSelectionEnabled?: boolean, ) => { const url = new URL(baseUrl); url.searchParams.set('token', sessionToken); url.searchParams.set('origin', btoa(origin)); url.searchParams.set('showBranding', showBranding ? 'true' : 'false'); url.searchParams.set('folderSelectionEnabled', folderSelectionEnabled ? 'true' : 'false'); + url.searchParams.set('driveSelectionEnabled', driveSelectionEnabled ? 'true' : 'false'); if (fields) { url.searchParams.set('fields', btoa(JSON.stringify(fields)));