This repository has been archived by the owner on Dec 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.tsx
56 lines (51 loc) · 1.47 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { list, DeprecatedPlugin, upload } from '@edtr-io/plugin'
import { createIcon, faFileAlt } from '@edtr-io/ui'
import * as React from 'react'
import { createFilesEditor } from './editor'
import { FilesRenderer } from './renderer'
import { FileType, UploadedFile, UploadFileConfig } from './types'
export const fileState = list(
upload<UploadedFile>({
location: '',
name: '',
type: FileType.Other
})
)
export function createFilePlugin(
config: UploadFileConfig
): DeprecatedPlugin<typeof fileState> {
const FilesEditor = createFilesEditor(config.upload)
return {
//eslint-disable-next-line react/display-name
Component: props =>
props.editable ? (
<FilesEditor {...props} />
) : (
<FilesRenderer {...props} />
),
state: fileState,
title: 'Dateien',
description: 'Ein Plugin für den Upload von beliebigen Dateien.',
icon: createIcon(faFileAlt),
onPaste: (clipboardData: DataTransfer) => {
const files = getFilesFromDataTransfer(clipboardData)
if (files.length) {
return {
state: files.map(file => ({ pending: file }))
}
}
}
}
}
export function getFilesFromDataTransfer(clipboardData: DataTransfer) {
const items = clipboardData.files
const files: File[] = []
for (let i = 0; i < items.length; i++) {
const item = items[i]
if (!item) continue
files.push(item)
}
return files
}
export * from './types'
export { parseFileType } from './upload'