|
@@ -1,34 +1,51 @@
|
|
-// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
|
|
-// @ts-nocheck Typing this file requires more work, skipping it to unblock the rest of the transition.
|
|
|
|
-
|
|
|
|
/* eslint-disable react/destructuring-assignment */
|
|
/* eslint-disable react/destructuring-assignment */
|
|
import { h, Component, Fragment, type ComponentChild } from 'preact'
|
|
import { h, Component, Fragment, type ComponentChild } from 'preact'
|
|
|
|
+import type { I18n } from '@uppy/utils/lib/Translator'
|
|
|
|
+import type Translator from '@uppy/utils/lib/Translator'
|
|
|
|
+import type { TargetedEvent } from 'preact/compat'
|
|
|
|
+import type { DashboardState, TargetWithRender } from '../Dashboard'
|
|
|
|
+
|
|
|
|
+interface AddFilesProps {
|
|
|
|
+ i18n: I18n
|
|
|
|
+ i18nArray: Translator['translateArray']
|
|
|
|
+ acquirers: TargetWithRender[]
|
|
|
|
+ handleInputChange: (event: TargetedEvent<HTMLInputElement, Event>) => void
|
|
|
|
+ maxNumberOfFiles: number | null
|
|
|
|
+ allowedFileTypes: string[] | null
|
|
|
|
+ showNativePhotoCameraButton: boolean
|
|
|
|
+ showNativeVideoCameraButton: boolean
|
|
|
|
+ nativeCameraFacingMode: 'user' | 'environment' | ''
|
|
|
|
+ showPanel: (id: string) => void
|
|
|
|
+ activePickerPanel: DashboardState<any, any>['activePickerPanel']
|
|
|
|
+ disableLocalFiles: boolean
|
|
|
|
+ fileManagerSelectionType: string
|
|
|
|
+ note: string | null
|
|
|
|
+ proudlyDisplayPoweredByUppy: boolean
|
|
|
|
+}
|
|
|
|
|
|
-type $TSFixMe = any
|
|
|
|
-
|
|
|
|
-class AddFiles extends Component {
|
|
|
|
- fileInput: $TSFixMe
|
|
|
|
|
|
+class AddFiles extends Component<AddFilesProps> {
|
|
|
|
+ fileInput: HTMLInputElement | null = null
|
|
|
|
|
|
- folderInput: $TSFixMe
|
|
|
|
|
|
+ folderInput: HTMLInputElement | null = null
|
|
|
|
|
|
- mobilePhotoFileInput: $TSFixMe
|
|
|
|
|
|
+ mobilePhotoFileInput: HTMLInputElement | null = null
|
|
|
|
|
|
- mobileVideoFileInput: $TSFixMe
|
|
|
|
|
|
+ mobileVideoFileInput: HTMLInputElement | null = null
|
|
|
|
|
|
private triggerFileInputClick = () => {
|
|
private triggerFileInputClick = () => {
|
|
- this.fileInput.click()
|
|
|
|
|
|
+ this.fileInput?.click()
|
|
}
|
|
}
|
|
|
|
|
|
private triggerFolderInputClick = () => {
|
|
private triggerFolderInputClick = () => {
|
|
- this.folderInput.click()
|
|
|
|
|
|
+ this.folderInput?.click()
|
|
}
|
|
}
|
|
|
|
|
|
private triggerVideoCameraInputClick = () => {
|
|
private triggerVideoCameraInputClick = () => {
|
|
- this.mobileVideoFileInput.click()
|
|
|
|
|
|
+ this.mobileVideoFileInput?.click()
|
|
}
|
|
}
|
|
|
|
|
|
private triggerPhotoCameraInputClick = () => {
|
|
private triggerPhotoCameraInputClick = () => {
|
|
- this.mobilePhotoFileInput.click()
|
|
|
|
|
|
+ this.mobilePhotoFileInput?.click()
|
|
}
|
|
}
|
|
|
|
|
|
private onFileInputChange = (
|
|
private onFileInputChange = (
|
|
@@ -42,13 +59,17 @@ class AddFiles extends Component {
|
|
event.currentTarget.value = ''
|
|
event.currentTarget.value = ''
|
|
}
|
|
}
|
|
|
|
|
|
- private renderHiddenInput = (isFolder: $TSFixMe, refCallback: $TSFixMe) => {
|
|
|
|
|
|
+ private renderHiddenInput = (
|
|
|
|
+ isFolder: boolean,
|
|
|
|
+ refCallback: (ref: HTMLInputElement | null) => void,
|
|
|
|
+ ) => {
|
|
return (
|
|
return (
|
|
<input
|
|
<input
|
|
className="uppy-Dashboard-input"
|
|
className="uppy-Dashboard-input"
|
|
hidden
|
|
hidden
|
|
aria-hidden="true"
|
|
aria-hidden="true"
|
|
tabIndex={-1}
|
|
tabIndex={-1}
|
|
|
|
+ // @ts-expect-error default types don't yet know about the `webkitdirectory` property
|
|
webkitdirectory={isFolder}
|
|
webkitdirectory={isFolder}
|
|
type="file"
|
|
type="file"
|
|
name="files[]"
|
|
name="files[]"
|
|
@@ -61,9 +82,9 @@ class AddFiles extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
private renderHiddenCameraInput = (
|
|
private renderHiddenCameraInput = (
|
|
- type: $TSFixMe,
|
|
|
|
- nativeCameraFacingMode: $TSFixMe,
|
|
|
|
- refCallback: $TSFixMe,
|
|
|
|
|
|
+ type: 'photo' | 'video',
|
|
|
|
+ nativeCameraFacingMode: 'user' | 'environment' | '',
|
|
|
|
+ refCallback: (ref: HTMLInputElement | null) => void,
|
|
) => {
|
|
) => {
|
|
const typeToAccept = { photo: 'image/*', video: 'video/*' }
|
|
const typeToAccept = { photo: 'image/*', video: 'video/*' }
|
|
const accept = typeToAccept[type]
|
|
const accept = typeToAccept[type]
|
|
@@ -193,7 +214,10 @@ class AddFiles extends Component {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
- private renderBrowseButton = (text: $TSFixMe, onClickFn: $TSFixMe) => {
|
|
|
|
|
|
+ private renderBrowseButton = (
|
|
|
|
+ text: string,
|
|
|
|
+ onClickFn: (event: Event) => void,
|
|
|
|
+ ) => {
|
|
const numberOfAcquirers = this.props.acquirers.length
|
|
const numberOfAcquirers = this.props.acquirers.length
|
|
return (
|
|
return (
|
|
<button
|
|
<button
|
|
@@ -207,7 +231,7 @@ class AddFiles extends Component {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
- private renderDropPasteBrowseTagline = (numberOfAcquirers: $TSFixMe) => {
|
|
|
|
|
|
+ private renderDropPasteBrowseTagline = (numberOfAcquirers: number) => {
|
|
const browseFiles = this.renderBrowseButton(
|
|
const browseFiles = this.renderBrowseButton(
|
|
this.props.i18n('browseFiles'),
|
|
this.props.i18n('browseFiles'),
|
|
this.triggerFileInputClick,
|
|
this.triggerFileInputClick,
|
|
@@ -257,7 +281,7 @@ class AddFiles extends Component {
|
|
this.props.i18nArray('dropPasteImportFolders')
|
|
this.props.i18nArray('dropPasteImportFolders')
|
|
}
|
|
}
|
|
|
|
|
|
- private renderAcquirer = (acquirer: $TSFixMe) => {
|
|
|
|
|
|
+ private renderAcquirer = (acquirer: TargetWithRender) => {
|
|
return (
|
|
return (
|
|
<div
|
|
<div
|
|
className="uppy-DashboardTab"
|
|
className="uppy-DashboardTab"
|
|
@@ -282,7 +306,7 @@ class AddFiles extends Component {
|
|
)
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
- private renderAcquirers = (acquirers: $TSFixMe) => {
|
|
|
|
|
|
+ private renderAcquirers = (acquirers: TargetWithRender[]) => {
|
|
// Group last two buttons, so we don’t end up with
|
|
// Group last two buttons, so we don’t end up with
|
|
// just one button on a new line
|
|
// just one button on a new line
|
|
const acquirersWithoutLastTwo = [...acquirers]
|
|
const acquirersWithoutLastTwo = [...acquirers]
|
|
@@ -304,18 +328,22 @@ class AddFiles extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
private renderSourcesList = (
|
|
private renderSourcesList = (
|
|
- acquirers: $TSFixMe,
|
|
|
|
- disableLocalFiles: $TSFixMe,
|
|
|
|
|
|
+ acquirers: TargetWithRender[],
|
|
|
|
+ disableLocalFiles: boolean,
|
|
) => {
|
|
) => {
|
|
const { showNativePhotoCameraButton, showNativeVideoCameraButton } =
|
|
const { showNativePhotoCameraButton, showNativeVideoCameraButton } =
|
|
this.props
|
|
this.props
|
|
|
|
|
|
- let list = []
|
|
|
|
|
|
+ type RenderListItem = { key: string; elements: ComponentChild }
|
|
|
|
+ let list: RenderListItem[] = []
|
|
|
|
|
|
const myDeviceKey = 'myDevice'
|
|
const myDeviceKey = 'myDevice'
|
|
|
|
|
|
if (!disableLocalFiles)
|
|
if (!disableLocalFiles)
|
|
- list.push({ key: myDeviceKey, elements: this.renderMyDeviceAcquirer() })
|
|
|
|
|
|
+ list.push({
|
|
|
|
+ key: myDeviceKey,
|
|
|
|
+ elements: this.renderMyDeviceAcquirer(),
|
|
|
|
+ })
|
|
if (showNativePhotoCameraButton)
|
|
if (showNativePhotoCameraButton)
|
|
list.push({
|
|
list.push({
|
|
key: 'nativePhotoCameraButton',
|
|
key: 'nativePhotoCameraButton',
|
|
@@ -327,7 +355,7 @@ class AddFiles extends Component {
|
|
elements: this.renderVideoCamera(),
|
|
elements: this.renderVideoCamera(),
|
|
})
|
|
})
|
|
list.push(
|
|
list.push(
|
|
- ...acquirers.map((acquirer: $TSFixMe) => ({
|
|
|
|
|
|
+ ...acquirers.map((acquirer: TargetWithRender) => ({
|
|
key: acquirer.id,
|
|
key: acquirer.id,
|
|
elements: this.renderAcquirer(acquirer),
|
|
elements: this.renderAcquirer(acquirer),
|
|
})),
|
|
})),
|
|
@@ -342,20 +370,19 @@ class AddFiles extends Component {
|
|
const listWithoutLastTwo = [...list]
|
|
const listWithoutLastTwo = [...list]
|
|
const lastTwo = listWithoutLastTwo.splice(list.length - 2, list.length)
|
|
const lastTwo = listWithoutLastTwo.splice(list.length - 2, list.length)
|
|
|
|
|
|
- const renderList = (l: $TSFixMe) =>
|
|
|
|
- l.map(({ key, elements }: $TSFixMe) => (
|
|
|
|
- <Fragment key={key}>{elements}</Fragment>
|
|
|
|
- ))
|
|
|
|
-
|
|
|
|
return (
|
|
return (
|
|
<>
|
|
<>
|
|
{this.renderDropPasteBrowseTagline(list.length)}
|
|
{this.renderDropPasteBrowseTagline(list.length)}
|
|
|
|
|
|
<div className="uppy-Dashboard-AddFiles-list" role="tablist">
|
|
<div className="uppy-Dashboard-AddFiles-list" role="tablist">
|
|
- {renderList(listWithoutLastTwo)}
|
|
|
|
|
|
+ {listWithoutLastTwo.map(({ key, elements }) => (
|
|
|
|
+ <Fragment key={key}>{elements}</Fragment>
|
|
|
|
+ ))}
|
|
|
|
|
|
<span role="presentation" style={{ 'white-space': 'nowrap' }}>
|
|
<span role="presentation" style={{ 'white-space': 'nowrap' }}>
|
|
- {renderList(lastTwo)}
|
|
|
|
|
|
+ {lastTwo.map(({ key, elements }) => (
|
|
|
|
+ <Fragment key={key}>{elements}</Fragment>
|
|
|
|
+ ))}
|
|
</span>
|
|
</span>
|
|
</div>
|
|
</div>
|
|
</>
|
|
</>
|
|
@@ -363,7 +390,7 @@ class AddFiles extends Component {
|
|
}
|
|
}
|
|
|
|
|
|
private renderPoweredByUppy() {
|
|
private renderPoweredByUppy() {
|
|
- const { i18nArray } = this.props as $TSFixMe
|
|
|
|
|
|
+ const { i18nArray } = this.props
|
|
|
|
|
|
const uppyBranding = (
|
|
const uppyBranding = (
|
|
<span>
|
|
<span>
|
|
@@ -408,17 +435,17 @@ class AddFiles extends Component {
|
|
|
|
|
|
return (
|
|
return (
|
|
<div className="uppy-Dashboard-AddFiles">
|
|
<div className="uppy-Dashboard-AddFiles">
|
|
- {this.renderHiddenInput(false, (ref: $TSFixMe) => {
|
|
|
|
|
|
+ {this.renderHiddenInput(false, (ref) => {
|
|
this.fileInput = ref
|
|
this.fileInput = ref
|
|
})}
|
|
})}
|
|
- {this.renderHiddenInput(true, (ref: $TSFixMe) => {
|
|
|
|
|
|
+ {this.renderHiddenInput(true, (ref) => {
|
|
this.folderInput = ref
|
|
this.folderInput = ref
|
|
})}
|
|
})}
|
|
{showNativePhotoCameraButton &&
|
|
{showNativePhotoCameraButton &&
|
|
this.renderHiddenCameraInput(
|
|
this.renderHiddenCameraInput(
|
|
'photo',
|
|
'photo',
|
|
nativeCameraFacingMode,
|
|
nativeCameraFacingMode,
|
|
- (ref: $TSFixMe) => {
|
|
|
|
|
|
+ (ref) => {
|
|
this.mobilePhotoFileInput = ref
|
|
this.mobilePhotoFileInput = ref
|
|
},
|
|
},
|
|
)}
|
|
)}
|
|
@@ -426,7 +453,7 @@ class AddFiles extends Component {
|
|
this.renderHiddenCameraInput(
|
|
this.renderHiddenCameraInput(
|
|
'video',
|
|
'video',
|
|
nativeCameraFacingMode,
|
|
nativeCameraFacingMode,
|
|
- (ref: $TSFixMe) => {
|
|
|
|
|
|
+ (ref) => {
|
|
this.mobileVideoFileInput = ref
|
|
this.mobileVideoFileInput = ref
|
|
},
|
|
},
|
|
)}
|
|
)}
|
|
@@ -438,8 +465,7 @@ class AddFiles extends Component {
|
|
{this.props.note && (
|
|
{this.props.note && (
|
|
<div className="uppy-Dashboard-note">{this.props.note}</div>
|
|
<div className="uppy-Dashboard-note">{this.props.note}</div>
|
|
)}
|
|
)}
|
|
- {this.props.proudlyDisplayPoweredByUppy &&
|
|
|
|
- this.renderPoweredByUppy(this.props)}
|
|
|
|
|
|
+ {this.props.proudlyDisplayPoweredByUppy && this.renderPoweredByUppy()}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
)
|