From d31a45ffe90f668e17f42e80b47532c41fc340e7 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 27 Aug 2023 03:27:48 +0200 Subject: [PATCH] fix(FilePickerBuilder): Fix paths returned in Promise by `pick` method and reject if nothing is picked Signed-off-by: Ferdinand Thiessen --- lib/filepicker.ts | 7 ++++--- lib/utils/dialogs.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/filepicker.ts b/lib/filepicker.ts index ae3ef1328..25f0c02e9 100644 --- a/lib/filepicker.ts +++ b/lib/filepicker.ts @@ -87,9 +87,10 @@ export class FilePicker { mimetypeFilter: this.mimeTypeFilter, multiselect: this.multiSelect, filterFn: this.filter, - }, (...nodes: unknown[]) => { - if (!nodes) { - reject(new Error('Nothing selected')) + }, (...rest: unknown[]) => { + const [nodes] = rest as [nodes: Node[]] + if (!Array.isArray(nodes) || nodes.length === 0) { + reject(new Error('FilePicker: No nodes selected')) } else { if (this.multiSelect) { resolve((nodes as Node[]).map((node) => node.path) as (IsMultiSelect extends true ? string[] : string)) diff --git a/lib/utils/dialogs.ts b/lib/utils/dialogs.ts index e63437817..a5b8d5bd1 100644 --- a/lib/utils/dialogs.ts +++ b/lib/utils/dialogs.ts @@ -21,7 +21,7 @@ */ import type { AsyncComponent, Component } from 'vue' -import Vue from 'vue' +import Vue, { toRaw } from 'vue' /** * Helper to spawn a Vue dialog without having to mount it from a component @@ -44,7 +44,7 @@ export const spawnDialog = (dialog: Component | AsyncComponent, props: any, onCl props, on: { close: (...rest: unknown[]) => { - onClose(rest) + onClose(...rest.map(v => toRaw(v))) vue.$destroy() }, },