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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const options = {
baseUrl = 'https://app.stackone.com',
fields = ['name', 'path', 'driveId'],
showBranding = false,
folderSelectionEnabled = true,
onFilesPicked = (files) => {
console.log('Selected files:', files);
},
Expand All @@ -82,6 +83,7 @@ const filePicker = new FilePicker(options);
| **baseUrl** | string | No | Which API instance should it connect to. |
| **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. |
| **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. |
Expand Down
4 changes: 4 additions & 0 deletions src/filePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export class FilePicker {
#isListenerAttached = false;
#showBranding = true;
#fields?: string[];
#folderSelectionEnabled = false;
#onFilesPicked: (data: File[]) => void;
#onClose: () => void;
#onOpen: () => void;
Expand All @@ -25,6 +26,7 @@ export class FilePicker {
apiUrl,
fields,
showBranding,
folderSelectionEnabled,
onFilesPicked,
onClose,
onOpen,
Expand All @@ -37,6 +39,7 @@ export class FilePicker {
this.#baseUrl = baseUrl ?? 'https://app.stackone.com';
this.#apiUrl = apiUrl ?? 'https://api.stackone.com';
this.#showBranding = showBranding ?? true;
this.#folderSelectionEnabled = folderSelectionEnabled ?? false;
this.#onFilesPicked = onFilesPicked ?? (() => {});
this.#onClose = onClose ?? (() => {});
this.#onOpen = onOpen ?? (() => {});
Expand Down Expand Up @@ -75,6 +78,7 @@ export class FilePicker {
this.#fields,
this.#apiUrl,
this.#showBranding,
this.#folderSelectionEnabled,
);
this.#iframe.src = url;
}
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface FilePickerOptions {
apiUrl?: string;
fields?: string[];
showBranding?: boolean;
folderSelectionEnabled?: boolean;
onFilesPicked?: (data: File[]) => void;
onError?: (error: Error) => void;
onClose?: () => void;
Expand Down
2 changes: 2 additions & 0 deletions src/utils/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ export const createUrl = (
fields?: string[],
apiUrl?: string,
showBranding?: boolean,
folderSelectionEnabled?: 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');

if (fields) {
url.searchParams.set('fields', btoa(JSON.stringify(fields)));
Expand Down