@instructure/ui-file-drop 8.8.1-snapshot.7 → 8.9.1-snapshot.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/es/FileDrop/index.js +5 -139
- package/es/FileDrop/props.js +151 -0
- package/lib/FileDrop/index.js +4 -140
- package/lib/FileDrop/props.js +164 -0
- package/package.json +16 -16
- package/src/FileDrop/index.tsx +41 -123
- package/src/FileDrop/props.ts +212 -0
- package/src/FileDrop/styles.ts +1 -1
- package/src/index.ts +1 -1
- package/types/FileDrop/index.d.ts +51 -116
- package/types/FileDrop/index.d.ts.map +1 -1
- package/types/FileDrop/{types.d.ts → props.d.ts} +13 -7
- package/types/FileDrop/props.d.ts.map +1 -0
- package/types/FileDrop/styles.d.ts +1 -1
- package/types/index.d.ts +1 -1
- package/es/FileDrop/types.js +0 -1
- package/lib/FileDrop/types.js +0 -1
- package/src/FileDrop/types.ts +0 -68
- package/types/FileDrop/types.d.ts.map +0 -1
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.allowedProps = exports.propTypes = void 0;
|
|
9
|
+
|
|
10
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
11
|
+
|
|
12
|
+
var _FormPropTypes = require("@instructure/ui-form-field/lib/FormPropTypes.js");
|
|
13
|
+
|
|
14
|
+
var _emotion = require("@instructure/emotion");
|
|
15
|
+
|
|
16
|
+
/*
|
|
17
|
+
* The MIT License (MIT)
|
|
18
|
+
*
|
|
19
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
20
|
+
*
|
|
21
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
22
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
23
|
+
* in the Software without restriction, including without limitation the rights
|
|
24
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
25
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
26
|
+
* furnished to do so, subject to the following conditions:
|
|
27
|
+
*
|
|
28
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
29
|
+
* copies or substantial portions of the Software.
|
|
30
|
+
*
|
|
31
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
32
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
33
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
34
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
35
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
36
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
37
|
+
* SOFTWARE.
|
|
38
|
+
*/
|
|
39
|
+
const propTypes = {
|
|
40
|
+
/**
|
|
41
|
+
* The id of the input (to link it to its label for a11y)
|
|
42
|
+
*/
|
|
43
|
+
id: _propTypes.default.string,
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The content of FileDrop; can be a component or React node.
|
|
47
|
+
* Components receive `isDragAccepted` and `isDragRejected` as props.
|
|
48
|
+
*/
|
|
49
|
+
renderLabel: _propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.node]).isRequired,
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The mime media type/s or file extension/s allowed to be dropped inside
|
|
53
|
+
*/
|
|
54
|
+
accept: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.arrayOf(_propTypes.default.string)]),
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* object with shape: `{
|
|
58
|
+
* text: PropTypes.string,
|
|
59
|
+
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
60
|
+
* }`
|
|
61
|
+
*/
|
|
62
|
+
messages: _propTypes.default.arrayOf(_FormPropTypes.FormPropTypes.message),
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Called when clicking on drop area to select files to upload
|
|
66
|
+
*/
|
|
67
|
+
onClick: _propTypes.default.func,
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Called when dropping files or when file dialog window exits successfully
|
|
71
|
+
*/
|
|
72
|
+
onDrop: _propTypes.default.func,
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Called when dropping allowed files
|
|
76
|
+
*/
|
|
77
|
+
onDropAccepted: _propTypes.default.func,
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Called when dropping rejected files
|
|
81
|
+
*/
|
|
82
|
+
onDropRejected: _propTypes.default.func,
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Called when dragging files
|
|
86
|
+
* and passing through FileDrop's content for the first time
|
|
87
|
+
*/
|
|
88
|
+
onDragEnter: _propTypes.default.func,
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Called when dragging files and passing through FileDrop's content
|
|
92
|
+
*/
|
|
93
|
+
onDragOver: _propTypes.default.func,
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Called when dragging files and leaving FileDrop's content
|
|
97
|
+
*/
|
|
98
|
+
onDragLeave: _propTypes.default.func,
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Flag to use window.URL.createObjectURL for each dropped file and pass it through file.preview
|
|
102
|
+
*/
|
|
103
|
+
shouldEnablePreview: _propTypes.default.bool,
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Flag to allow multiple files to drop at once
|
|
107
|
+
*/
|
|
108
|
+
shouldAllowMultiple: _propTypes.default.bool,
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Flag to allow upload of the same file more than once
|
|
112
|
+
*/
|
|
113
|
+
shouldAllowRepeats: _propTypes.default.bool,
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* the maximum file size allowed
|
|
117
|
+
*/
|
|
118
|
+
maxSize: _propTypes.default.number,
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* the minimum file size allowed
|
|
122
|
+
*/
|
|
123
|
+
minSize: _propTypes.default.number,
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Specifies if interaction with the input is enabled, disabled, or readonly.
|
|
127
|
+
*/
|
|
128
|
+
interaction: _propTypes.default.oneOf(['enabled', 'disabled', 'readonly']),
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Set the CSS `display` property on FileInput's outermost element
|
|
132
|
+
*/
|
|
133
|
+
display: _propTypes.default.oneOf(['block', 'inline-block']),
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Set the CSS `height` property on FileInput's outermost element
|
|
137
|
+
*/
|
|
138
|
+
height: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Set the CSS `width` property on FileInput's outermost element
|
|
142
|
+
*/
|
|
143
|
+
width: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Set the CSS `maxWidth` property on FileInput's outermost element
|
|
147
|
+
*/
|
|
148
|
+
maxWidth: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Set the CSS `minWidth` property on FileInput's outermost element
|
|
152
|
+
*/
|
|
153
|
+
minWidth: _propTypes.default.oneOfType([_propTypes.default.string, _propTypes.default.number]),
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Valid values are 0, none, auto, xxx-small, xx-small, x-small, small,
|
|
157
|
+
* medium, large, x-large, xx-large. Apply these values via familiar
|
|
158
|
+
* CSS-like shorthand. For example: margin="small auto large".
|
|
159
|
+
*/
|
|
160
|
+
margin: _emotion.ThemeablePropTypes.spacing
|
|
161
|
+
};
|
|
162
|
+
exports.propTypes = propTypes;
|
|
163
|
+
const allowedProps = ['id', 'renderLabel', 'accept', 'messages', 'onClick', 'onDrop', 'onDropAccepted', 'onDropRejected', 'onDragEnter', 'onDragOver', 'onDragLeave', 'shouldEnablePreview', 'shouldAllowMultiple', 'shouldAllowRepeats', 'maxSize', 'minSize', 'interaction', 'display', 'height', 'width', 'maxWidth', 'minWidth', 'margin'];
|
|
164
|
+
exports.allowedProps = allowedProps;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-file-drop",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.9.1-snapshot.2+7f5faa3df",
|
|
4
4
|
"description": "A flexible facade for an HTML file input",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -25,24 +25,24 @@
|
|
|
25
25
|
"license": "MIT",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@babel/runtime": "^7.13.10",
|
|
28
|
-
"@instructure/console": "8.
|
|
29
|
-
"@instructure/emotion": "8.
|
|
30
|
-
"@instructure/
|
|
31
|
-
"@instructure/ui-
|
|
32
|
-
"@instructure/ui-
|
|
33
|
-
"@instructure/ui-
|
|
34
|
-
"@instructure/ui-
|
|
35
|
-
"@instructure/ui-
|
|
36
|
-
"@instructure/
|
|
28
|
+
"@instructure/console": "8.9.1-snapshot.2+7f5faa3df",
|
|
29
|
+
"@instructure/emotion": "8.9.1-snapshot.2+7f5faa3df",
|
|
30
|
+
"@instructure/shared-types": "8.9.1-snapshot.2+7f5faa3df",
|
|
31
|
+
"@instructure/ui-color-utils": "8.9.1-snapshot.2+7f5faa3df",
|
|
32
|
+
"@instructure/ui-form-field": "8.9.1-snapshot.2+7f5faa3df",
|
|
33
|
+
"@instructure/ui-react-utils": "8.9.1-snapshot.2+7f5faa3df",
|
|
34
|
+
"@instructure/ui-testable": "8.9.1-snapshot.2+7f5faa3df",
|
|
35
|
+
"@instructure/ui-utils": "8.9.1-snapshot.2+7f5faa3df",
|
|
36
|
+
"@instructure/ui-view": "8.9.1-snapshot.2+7f5faa3df",
|
|
37
|
+
"@instructure/uid": "8.9.1-snapshot.2+7f5faa3df",
|
|
37
38
|
"keycode": "^2",
|
|
38
39
|
"prop-types": "^15"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@instructure/
|
|
42
|
-
"@instructure/ui-
|
|
43
|
-
"@instructure/ui-test-
|
|
44
|
-
"@instructure/ui-
|
|
45
|
-
"@instructure/ui-themes": "8.8.1-snapshot.7+90b251d58"
|
|
42
|
+
"@instructure/ui-babel-preset": "8.9.1-snapshot.2+7f5faa3df",
|
|
43
|
+
"@instructure/ui-test-locator": "8.9.1-snapshot.2+7f5faa3df",
|
|
44
|
+
"@instructure/ui-test-utils": "8.9.1-snapshot.2+7f5faa3df",
|
|
45
|
+
"@instructure/ui-themes": "8.9.1-snapshot.2+7f5faa3df"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"react": ">=16.8 <=17"
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"access": "public"
|
|
52
52
|
},
|
|
53
53
|
"sideEffects": false,
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "7f5faa3df83667636304e0901ef1008d98dffc9a"
|
|
55
55
|
}
|
package/src/FileDrop/index.tsx
CHANGED
|
@@ -23,9 +23,9 @@
|
|
|
23
23
|
*/
|
|
24
24
|
/** @jsx jsx */
|
|
25
25
|
import { Component } from 'react'
|
|
26
|
-
import PropTypes from 'prop-types'
|
|
27
26
|
import keycode from 'keycode'
|
|
28
|
-
|
|
27
|
+
|
|
28
|
+
import { FormFieldMessages } from '@instructure/ui-form-field'
|
|
29
29
|
import { View } from '@instructure/ui-view'
|
|
30
30
|
import { uid } from '@instructure/uid'
|
|
31
31
|
import { testable } from '@instructure/ui-testable'
|
|
@@ -35,12 +35,16 @@ import {
|
|
|
35
35
|
getInteraction
|
|
36
36
|
} from '@instructure/ui-react-utils'
|
|
37
37
|
import { isEdge } from '@instructure/ui-utils'
|
|
38
|
+
|
|
38
39
|
import { accepts, getAcceptList } from './utils/accepts'
|
|
39
40
|
import { getEventFiles } from './utils/getEventFiles'
|
|
40
|
-
|
|
41
|
+
|
|
42
|
+
import { withStyle, jsx } from '@instructure/emotion'
|
|
41
43
|
import generateStyle from './styles'
|
|
42
44
|
import generateComponentTheme from './theme'
|
|
43
|
-
|
|
45
|
+
|
|
46
|
+
import { propTypes, allowedProps } from './props'
|
|
47
|
+
import type { FileDropProps, FileDropState, FileDropStyleProps } from './props'
|
|
44
48
|
|
|
45
49
|
function keyEventIsClickButton(e: any) {
|
|
46
50
|
return e.keyCode === keycode.codes.space || e.keyCode === keycode.codes.enter
|
|
@@ -68,116 +72,8 @@ category: components
|
|
|
68
72
|
class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
69
73
|
static readonly componentId = 'FileDrop'
|
|
70
74
|
|
|
71
|
-
static propTypes =
|
|
72
|
-
|
|
73
|
-
* The id of the input (to link it to its label for a11y)
|
|
74
|
-
*/
|
|
75
|
-
id: PropTypes.string,
|
|
76
|
-
/**
|
|
77
|
-
* The content of FileDrop; can be a component or React node.
|
|
78
|
-
* Components receive `isDragAccepted` and `isDragRejected` as props.
|
|
79
|
-
*/
|
|
80
|
-
renderLabel: PropTypes.oneOfType([PropTypes.func, PropTypes.node])
|
|
81
|
-
.isRequired,
|
|
82
|
-
/**
|
|
83
|
-
* The mime media type/s or file extension/s allowed to be dropped inside
|
|
84
|
-
*/
|
|
85
|
-
accept: PropTypes.oneOfType([
|
|
86
|
-
PropTypes.string,
|
|
87
|
-
PropTypes.arrayOf(PropTypes.string)
|
|
88
|
-
]),
|
|
89
|
-
/**
|
|
90
|
-
* object with shape: `{
|
|
91
|
-
* text: PropTypes.string,
|
|
92
|
-
* type: PropTypes.oneOf(['error', 'hint', 'success', 'screenreader-only'])
|
|
93
|
-
* }`
|
|
94
|
-
*/
|
|
95
|
-
messages: PropTypes.arrayOf(FormPropTypes.message),
|
|
96
|
-
/**
|
|
97
|
-
* Called when clicking on drop area to select files to upload
|
|
98
|
-
*/
|
|
99
|
-
onClick: PropTypes.func,
|
|
100
|
-
/**
|
|
101
|
-
* Called when dropping files or when file dialog window exits successfully
|
|
102
|
-
*/
|
|
103
|
-
onDrop: PropTypes.func,
|
|
104
|
-
/**
|
|
105
|
-
* Called when dropping allowed files
|
|
106
|
-
*/
|
|
107
|
-
onDropAccepted: PropTypes.func,
|
|
108
|
-
/**
|
|
109
|
-
* Called when dropping rejected files
|
|
110
|
-
*/
|
|
111
|
-
onDropRejected: PropTypes.func,
|
|
112
|
-
/**
|
|
113
|
-
* Called when dragging files
|
|
114
|
-
* and passing through FileDrop's content for the first time
|
|
115
|
-
*/
|
|
116
|
-
onDragEnter: PropTypes.func,
|
|
117
|
-
/**
|
|
118
|
-
* Called when dragging files and passing through FileDrop's content
|
|
119
|
-
*/
|
|
120
|
-
onDragOver: PropTypes.func,
|
|
121
|
-
/**
|
|
122
|
-
* Called when dragging files and leaving FileDrop's content
|
|
123
|
-
*/
|
|
124
|
-
onDragLeave: PropTypes.func,
|
|
125
|
-
/**
|
|
126
|
-
* Flag to use window.URL.createObjectURL for each dropped file and pass it through file.preview
|
|
127
|
-
*/
|
|
128
|
-
shouldEnablePreview: PropTypes.bool,
|
|
129
|
-
/**
|
|
130
|
-
* Flag to allow multiple files to drop at once
|
|
131
|
-
*/
|
|
132
|
-
shouldAllowMultiple: PropTypes.bool,
|
|
133
|
-
/**
|
|
134
|
-
* Flag to allow upload of the same file more than once
|
|
135
|
-
*/
|
|
136
|
-
shouldAllowRepeats: PropTypes.bool,
|
|
137
|
-
/**
|
|
138
|
-
* the maximum file size allowed
|
|
139
|
-
*/
|
|
140
|
-
maxSize: PropTypes.number,
|
|
141
|
-
/**
|
|
142
|
-
* the minimum file size allowed
|
|
143
|
-
*/
|
|
144
|
-
minSize: PropTypes.number,
|
|
145
|
-
/**
|
|
146
|
-
* Specifies if interaction with the input is enabled, disabled, or readonly.
|
|
147
|
-
*/
|
|
148
|
-
interaction: PropTypes.oneOf(['enabled', 'disabled', 'readonly']),
|
|
149
|
-
/**
|
|
150
|
-
* Set the CSS `display` property on FileInput's outermost element
|
|
151
|
-
*/
|
|
152
|
-
display: PropTypes.oneOf(['block', 'inline-block']),
|
|
153
|
-
/**
|
|
154
|
-
* Set the CSS `height` property on FileInput's outermost element
|
|
155
|
-
*/
|
|
156
|
-
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
157
|
-
/**
|
|
158
|
-
* Set the CSS `width` property on FileInput's outermost element
|
|
159
|
-
*/
|
|
160
|
-
width: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
161
|
-
/**
|
|
162
|
-
* Set the CSS `maxWidth` property on FileInput's outermost element
|
|
163
|
-
*/
|
|
164
|
-
maxWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
165
|
-
/**
|
|
166
|
-
* Set the CSS `minWidth` property on FileInput's outermost element
|
|
167
|
-
*/
|
|
168
|
-
minWidth: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
|
|
169
|
-
/**
|
|
170
|
-
* Valid values are 0, none, auto, xxx-small, xx-small, x-small, small,
|
|
171
|
-
* medium, large, x-large, xx-large. Apply these values via familiar
|
|
172
|
-
* CSS-like shorthand. For example: margin="small auto large".
|
|
173
|
-
*/
|
|
174
|
-
margin: ThemeablePropTypes.spacing,
|
|
175
|
-
// eslint-disable-next-line react/require-default-props
|
|
176
|
-
makeStyles: PropTypes.func,
|
|
177
|
-
// eslint-disable-next-line react/require-default-props
|
|
178
|
-
styles: PropTypes.object
|
|
179
|
-
}
|
|
180
|
-
|
|
75
|
+
static propTypes = propTypes
|
|
76
|
+
static allowedProps = allowedProps
|
|
181
77
|
static defaultProps = {
|
|
182
78
|
// @ts-expect-error ts-migrate(6133) FIXME: 'e' is declared but its value is never read.
|
|
183
79
|
onClick: function (e: any) {},
|
|
@@ -199,29 +95,25 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
199
95
|
maxSize: Infinity,
|
|
200
96
|
minSize: 0,
|
|
201
97
|
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
202
|
-
interaction: undefined,
|
|
203
98
|
messages: [],
|
|
204
|
-
|
|
205
|
-
accept: undefined,
|
|
206
|
-
display: 'block',
|
|
207
|
-
height: undefined,
|
|
208
|
-
width: undefined,
|
|
209
|
-
minWidth: undefined,
|
|
210
|
-
maxWidth: undefined,
|
|
211
|
-
margin: undefined
|
|
99
|
+
display: 'block'
|
|
212
100
|
}
|
|
101
|
+
|
|
213
102
|
constructor(props: FileDropProps) {
|
|
214
103
|
super(props)
|
|
215
104
|
// @ts-expect-error ts-migrate(2322) FIXME: Type 'string' is not assignable to type 'null'.
|
|
216
105
|
this.defaultId = uid('FileDrop')
|
|
217
106
|
;(this as any).messagesId = uid('FileDrop-messages')
|
|
218
107
|
}
|
|
108
|
+
|
|
219
109
|
componentDidMount() {
|
|
220
110
|
;(this.props as any).makeStyles(this.makeStyleProps())
|
|
221
111
|
}
|
|
112
|
+
|
|
222
113
|
componentDidUpdate() {
|
|
223
114
|
;(this.props as any).makeStyles(this.makeStyleProps())
|
|
224
115
|
}
|
|
116
|
+
|
|
225
117
|
makeStyleProps = (): FileDropStyleProps => {
|
|
226
118
|
return {
|
|
227
119
|
functionallyDisabled: this.functionallyDisabled,
|
|
@@ -230,26 +122,32 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
230
122
|
dragAccepted: this.state.isDragAccepted
|
|
231
123
|
}
|
|
232
124
|
}
|
|
125
|
+
|
|
233
126
|
state: FileDropState = {
|
|
234
127
|
isDragAccepted: false,
|
|
235
128
|
isDragRejected: false,
|
|
236
129
|
isFocused: false,
|
|
237
130
|
isFileBrowserDisplayed: false
|
|
238
131
|
}
|
|
132
|
+
|
|
239
133
|
enterCounter = 0
|
|
240
134
|
fileInputEl = null
|
|
241
135
|
defaultId = null
|
|
136
|
+
|
|
242
137
|
get functionallyDisabled() {
|
|
243
138
|
return this.interaction === 'disabled' || this.interaction === 'readonly'
|
|
244
139
|
}
|
|
140
|
+
|
|
245
141
|
get hasMessages() {
|
|
246
142
|
return (
|
|
247
143
|
(this.props as any).messages && (this.props as any).messages.length > 0
|
|
248
144
|
)
|
|
249
145
|
}
|
|
146
|
+
|
|
250
147
|
get interaction() {
|
|
251
148
|
return getInteraction({ props: this.props })
|
|
252
149
|
}
|
|
150
|
+
|
|
253
151
|
get invalid() {
|
|
254
152
|
return (
|
|
255
153
|
this.hasMessages &&
|
|
@@ -258,6 +156,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
258
156
|
}) >= 0
|
|
259
157
|
)
|
|
260
158
|
}
|
|
159
|
+
|
|
261
160
|
getDataTransferItems(e: any, shouldEnablePreview: any) {
|
|
262
161
|
let list = Array.from(getEventFiles(e, this.fileInputEl))
|
|
263
162
|
if (list.length > 1) {
|
|
@@ -270,6 +169,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
270
169
|
}
|
|
271
170
|
return list
|
|
272
171
|
}
|
|
172
|
+
|
|
273
173
|
handleDragEnter = (e: any) => {
|
|
274
174
|
e.preventDefault()
|
|
275
175
|
// Count the dropzone and any children that are entered.
|
|
@@ -286,6 +186,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
286
186
|
})
|
|
287
187
|
;(this.props as any).onDragEnter(e)
|
|
288
188
|
}
|
|
189
|
+
|
|
289
190
|
handleDragOver = (e: any) => {
|
|
290
191
|
e.preventDefault()
|
|
291
192
|
e.stopPropagation()
|
|
@@ -298,6 +199,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
298
199
|
;(this.props as any).onDragOver(e)
|
|
299
200
|
return false
|
|
300
201
|
}
|
|
202
|
+
|
|
301
203
|
handleDragLeave = (e: any) => {
|
|
302
204
|
e.preventDefault()
|
|
303
205
|
this.enterCounter -= 1
|
|
@@ -311,6 +213,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
311
213
|
})
|
|
312
214
|
;(this.props as any).onDragLeave(e)
|
|
313
215
|
}
|
|
216
|
+
|
|
314
217
|
parseFiles(fileList: any) {
|
|
315
218
|
const accepted: any = []
|
|
316
219
|
const rejected: any = []
|
|
@@ -323,6 +226,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
323
226
|
})
|
|
324
227
|
return [accepted, rejected]
|
|
325
228
|
}
|
|
229
|
+
|
|
326
230
|
handleChange = (e: any) => {
|
|
327
231
|
const {
|
|
328
232
|
onDrop,
|
|
@@ -350,22 +254,27 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
350
254
|
isFileBrowserDisplayed: false
|
|
351
255
|
})
|
|
352
256
|
}
|
|
257
|
+
|
|
353
258
|
fileAccepted = (file: any) => {
|
|
354
259
|
return accepts(file, (this.props as any).accept)
|
|
355
260
|
}
|
|
261
|
+
|
|
356
262
|
fileMatchSize(file: any) {
|
|
357
263
|
return (
|
|
358
264
|
file.size <= (this.props as any).maxSize &&
|
|
359
265
|
file.size >= (this.props as any).minSize
|
|
360
266
|
)
|
|
361
267
|
}
|
|
268
|
+
|
|
362
269
|
allFilesAccepted(files: any) {
|
|
363
270
|
return files.every(this.fileAccepted)
|
|
364
271
|
}
|
|
272
|
+
|
|
365
273
|
acceptStr() {
|
|
366
274
|
const { accept } = this.props
|
|
367
275
|
return accept ? getAcceptList(accept).join(',') : null
|
|
368
276
|
}
|
|
277
|
+
|
|
369
278
|
renderLabel() {
|
|
370
279
|
const { renderLabel } = this.props
|
|
371
280
|
return callRenderProp(renderLabel, {
|
|
@@ -374,21 +283,25 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
374
283
|
interaction: this.interaction
|
|
375
284
|
})
|
|
376
285
|
}
|
|
286
|
+
|
|
377
287
|
handleRef = (el: any) => {
|
|
378
288
|
this.fileInputEl = el
|
|
379
289
|
}
|
|
290
|
+
|
|
380
291
|
handleBlur = () => {
|
|
381
292
|
this.setState({
|
|
382
293
|
isFocused: false,
|
|
383
294
|
isFileBrowserDisplayed: false
|
|
384
295
|
})
|
|
385
296
|
}
|
|
297
|
+
|
|
386
298
|
handleFocus = () => {
|
|
387
299
|
this.setState({
|
|
388
300
|
isFocused: true,
|
|
389
301
|
isFileBrowserDisplayed: false
|
|
390
302
|
})
|
|
391
303
|
}
|
|
304
|
+
|
|
392
305
|
handleClick = (e: any) => {
|
|
393
306
|
// @ts-expect-error ts-migrate(2531) FIXME: Object is possibly 'null'.
|
|
394
307
|
if (this.fileInputEl.value && (this.props as any).shouldAllowRepeats) {
|
|
@@ -403,6 +316,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
403
316
|
isFileBrowserDisplayed: true
|
|
404
317
|
})
|
|
405
318
|
}
|
|
319
|
+
|
|
406
320
|
handleKeyDown = (e: any) => {
|
|
407
321
|
if (this.state.isFocused && keyEventIsClickButton(e)) {
|
|
408
322
|
if ((this.props as any).shouldAllowRepeats) {
|
|
@@ -420,6 +334,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
420
334
|
}
|
|
421
335
|
}
|
|
422
336
|
}
|
|
337
|
+
|
|
423
338
|
handleKeyUp = (e: any) => {
|
|
424
339
|
// This is to handle the case where ESC is pressed inside a Dialog so that
|
|
425
340
|
// closing the file browser dialog doesn't also close the Dialog.
|
|
@@ -431,6 +346,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
431
346
|
})
|
|
432
347
|
}
|
|
433
348
|
}
|
|
349
|
+
|
|
434
350
|
render() {
|
|
435
351
|
const {
|
|
436
352
|
display,
|
|
@@ -446,6 +362,7 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
446
362
|
const id = (this.props as any).id || this.defaultId
|
|
447
363
|
const focusColor =
|
|
448
364
|
this.state.isDragRejected || this.invalid ? 'danger' : undefined
|
|
365
|
+
|
|
449
366
|
return (
|
|
450
367
|
<View
|
|
451
368
|
display={display}
|
|
@@ -509,5 +426,6 @@ class FileDrop extends Component<FileDropProps, FileDropState> {
|
|
|
509
426
|
)
|
|
510
427
|
}
|
|
511
428
|
}
|
|
429
|
+
|
|
512
430
|
export default FileDrop
|
|
513
431
|
export { FileDrop }
|