From 91a3f311b19ad9df841ee5850da86f9d4a21ff2c Mon Sep 17 00:00:00 2001 From: Benjamin Canac Date: Thu, 17 Jul 2025 16:06:42 +0200 Subject: [PATCH] up --- playground-vue/src/app.vue | 1 + playground/app/app.vue | 1 + .../app/pages/components/file-upload.vue | 134 +++++++++++++++++- playground/app/pages/index.vue | 86 ++--------- src/runtime/components/FileUpload.vue | 14 +- src/theme/file-upload.ts | 8 +- 6 files changed, 157 insertions(+), 87 deletions(-) diff --git a/playground-vue/src/app.vue b/playground-vue/src/app.vue index cc2e69d5..64285334 100644 --- a/playground-vue/src/app.vue +++ b/playground-vue/src/app.vue @@ -35,6 +35,7 @@ const components = [ 'command-palette', 'drawer', 'dropdown-menu', + 'file-upload', 'form', 'form-field', 'input', diff --git a/playground/app/app.vue b/playground/app/app.vue index 7348fbd7..61662537 100644 --- a/playground/app/app.vue +++ b/playground/app/app.vue @@ -35,6 +35,7 @@ const components = [ 'command-palette', 'drawer', 'dropdown-menu', + 'file-upload', 'form', 'form-field', 'input', diff --git a/playground/app/pages/components/file-upload.vue b/playground/app/pages/components/file-upload.vue index f931baf9..c9caeada 100644 --- a/playground/app/pages/components/file-upload.vue +++ b/playground/app/pages/components/file-upload.vue @@ -1,5 +1,135 @@ + + diff --git a/playground/app/pages/index.vue b/playground/app/pages/index.vue index 057f52a8..991b8d12 100644 --- a/playground/app/pages/index.vue +++ b/playground/app/pages/index.vue @@ -1,81 +1,11 @@ - - diff --git a/src/runtime/components/FileUpload.vue b/src/runtime/components/FileUpload.vue index 354bf713..5b708ff1 100644 --- a/src/runtime/components/FileUpload.vue +++ b/src/runtime/components/FileUpload.vue @@ -33,6 +33,7 @@ export interface FileUploadProps { * @defaultValue false */ dropzone?: boolean + defaultValue?: File[] class?: any ui?: FileUpload['slots'] } @@ -46,6 +47,7 @@ export interface FileUploadSlots { open: UseFileDialogReturn['open'] reset: UseFileDialogReturn['reset'] previewUrls: string[] + files: FileList[] }): any } @@ -73,9 +75,8 @@ const appConfig = useAppConfig() as FileUpload['AppConfig'] const { emitFormInput, emitFormChange, id, name, disabled, ariaAttrs } = useFormField(props, { deferInputValidation: true }) -// eslint-disable-next-line vue/no-dupe-keys const ui = computed(() => tv({ extend: tv(theme), ...(appConfig.ui?.fileUpload || {}) })({ - + dropzone: props.dropzone })) const inputRef = ref() @@ -84,14 +85,14 @@ const { files, open, reset, onCancel, onChange } = useFileDialog({ multiple: props.multiple, accept: props.accept, reset: props.reset, - input: inputRef.value + input: inputRef.value, + initialFiles: props.defaultValue }) const previewUrls = computed(() => Array.from(files.value || []).map(file => URL.createObjectURL(file))) onChange((files) => { - console.log('files:', typeof files?.[0]) - modelValue.value = props.multiple ? files : files?.[0] + modelValue.value = (props.multiple ? files : files?.[0]) as (M extends true ? File[] : File) | null }) onCancel(() => { @@ -101,7 +102,7 @@ onCancel(() => {