fix(frontend): fix fileinput drag and drop check (#2781)

* fix(frontend): fix fileinput drag and drop check

* fix(frontend): fix fileinput drag and drop check

* fix(frontend): fix fileinput drag and drop check
This commit is contained in:
Faton Ramadani
2023-12-05 14:11:49 +01:00
committed by GitHub
parent fde056a62f
commit 727a6798b6
4 changed files with 20 additions and 6 deletions
@@ -11,7 +11,7 @@
export let id: string
export let configuration: RichConfigurations
export let customCss: ComponentCustomCSS<'containercomponent'> | undefined = undefined
export let customCss: ComponentCustomCSS<'fileinputcomponent'> | undefined = undefined
export let render: boolean
const { app, worldStore } = getContext<AppViewerContext>('AppViewerContext')
@@ -33,7 +33,6 @@
return { name: file.name, data }
})
}
outputs?.result.set(files)
}
@@ -11,7 +11,7 @@
export let id: string
export let componentContainerHeight: number
export let customCss: ComponentCustomCSS<'containercomponent'> | undefined = undefined
export let customCss: ComponentCustomCSS<'conditionalwrapper'> | undefined = undefined
export let render: boolean
export let conditions: RichConfiguration[]
@@ -30,7 +30,7 @@
}
}
let css = initCss($app.css?.containercomponent, customCss)
let css = initCss($app.css?.conditionalwrapper, customCss)
let resolvedConditions: boolean[] = []
let selectedConditionIndex = 0
@@ -45,7 +45,7 @@
}
}
let css = initCss($app.css?.containercomponent, customCss)
let css = initCss($app.css?.listcomponent, customCss)
let result: any[] | undefined = undefined
$: isCard = resolvedConfig.width?.selected == 'card'
@@ -32,8 +32,15 @@
}
for (let i = 0; i < fileList.length; i++) {
const file = fileList.item(i)
if (file) files.push(file)
if (file && isAcceptedFileType(file)) {
files.push(file)
}
}
if (!files.length) {
files = undefined
}
// Needs to be reset so the same file can be selected
// multiple times in a row
input.value = ''
@@ -41,6 +48,14 @@
dispatchChange()
}
function isAcceptedFileType(file: File): boolean {
const acceptedTypes = accept?.split(',').map((type) => type.trim()) ?? []
return (
acceptedTypes.includes(file.type) ||
acceptedTypes.includes(`.${file?.name?.split('.').pop()}`)
)
}
async function convertFile(file: File): Promise<string | ArrayBuffer | null> {
return new Promise((resolve) => {
if (!convertTo) {