Skip to content
Merged
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
23 changes: 16 additions & 7 deletions lib/filepicker-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export class FilePicker<IsMultiSelect extends boolean> {
}

/**
* Pick files using the FilePicker
* Pick files using the FilePicker.
*
* @return Promise with array of picked files or rejected promise on close without picking
*/
public async pick(): Promise<IsMultiSelect extends true ? string[] : string> {
public async pickNodes(): Promise<Node[]> {
const { FilePickerVue } = await import('./components/FilePicker/index')

return new Promise((resolve, reject) => {
Expand All @@ -86,16 +86,25 @@ export class FilePicker<IsMultiSelect extends boolean> {
if (!Array.isArray(nodes) || nodes.length === 0) {
reject(new FilePickerClosed('FilePicker: No nodes selected'))
} else {
if (this.multiSelect) {
resolve((nodes as Node[]).map((node) => node.path) as (IsMultiSelect extends true ? string[] : string))
} else {
resolve(((nodes as Node[])[0]?.path || '/') as (IsMultiSelect extends true ? string[] : string))
}
resolve(nodes)
}
})
})
}

/**
* Pick files using the FilePicker
*
* @return Promise with array of paths of picked files or rejected promise on close without picking
*/
public async pick(): Promise<IsMultiSelect extends true ? string[] : string> {
const nodes = await this.pickNodes()
if (this.multiSelect) {
return (nodes[0]?.path ?? '/') as (IsMultiSelect extends true ? string[] : string)
}
return nodes.map((node) => node.path) as (IsMultiSelect extends true ? string[] : string)
}

}

export class FilePickerBuilder<IsMultiSelect extends boolean> {
Expand Down