diff --git a/lib/filepicker-builder.ts b/lib/filepicker-builder.ts index f542962cb..df04574b0 100644 --- a/lib/filepicker-builder.ts +++ b/lib/filepicker-builder.ts @@ -63,11 +63,11 @@ export class FilePicker { } /** - * 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 { + public async pickNodes(): Promise { const { FilePickerVue } = await import('./components/FilePicker/index') return new Promise((resolve, reject) => { @@ -86,16 +86,25 @@ export class FilePicker { 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 { + 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 {