@instructure/ui-file-drop 11.7.8 → 11.7.9-pr-snapshot-1792147648392
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 +13 -0
- package/es/FileDrop/v1/index.js +290 -352
- package/es/FileDrop/v1/props.js +27 -26
- package/es/FileDrop/v1/styles.js +68 -113
- package/es/FileDrop/v1/theme.js +23 -56
- package/es/FileDrop/v1/utils/accepts.js +20 -46
- package/es/FileDrop/v1/utils/getEventFiles.js +13 -37
- package/es/FileDrop/v2/index.js +291 -353
- package/es/FileDrop/v2/props.js +27 -26
- package/es/FileDrop/v2/styles.js +68 -112
- package/es/FileDrop/v2/utils/accepts.js +20 -46
- package/es/FileDrop/v2/utils/getEventFiles.js +13 -37
- package/es/exports/a.js +1 -25
- package/es/exports/b.js +1 -25
- package/package.json +15 -21
- package/tsconfig.build.json +0 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/lib/FileDrop/v1/index.js +0 -387
- package/lib/FileDrop/v1/props.js +0 -31
- package/lib/FileDrop/v1/styles.js +0 -120
- package/lib/FileDrop/v1/theme.js +0 -63
- package/lib/FileDrop/v1/utils/accepts.js +0 -58
- package/lib/FileDrop/v1/utils/getEventFiles.js +0 -47
- package/lib/FileDrop/v2/index.js +0 -387
- package/lib/FileDrop/v2/props.js +0 -31
- package/lib/FileDrop/v2/styles.js +0 -119
- package/lib/FileDrop/v2/utils/accepts.js +0 -58
- package/lib/FileDrop/v2/utils/getEventFiles.js +0 -47
- package/lib/exports/a.js +0 -12
- package/lib/exports/b.js +0 -12
- package/lib/package.json +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,19 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [11.7.9-pr-snapshot-1792147648392](https://github.com/instructure/instructure-ui/compare/v11.7.8...v11.7.9-pr-snapshot-1792147648392) (2026-10-16)
|
|
7
|
+
|
|
8
|
+
### Build System
|
|
9
|
+
|
|
10
|
+
* **many:** replace babel with swc ([7e36c54](https://github.com/instructure/instructure-ui/commit/7e36c54d240b4fa483801c03ab18e7f860f561e2))
|
|
11
|
+
|
|
12
|
+
### BREAKING CHANGES
|
|
13
|
+
|
|
14
|
+
* **many:** `@instructure/ui-babel-preset` and
|
|
15
|
+
`@instructure/browserslist-config-instui` are removed and will no longer be
|
|
16
|
+
published. Packages depend on `@swc/helpers` instead of `@babel/runtime`.
|
|
17
|
+
|
|
18
|
+
|
|
6
19
|
## [11.7.8](https://github.com/instructure/instructure-ui/compare/v11.7.7...v11.7.8) (2026-10-02)
|
|
7
20
|
|
|
8
21
|
**Note:** Version bump only for package @instructure/ui-file-drop
|
package/es/FileDrop/v1/index.js
CHANGED
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* The MIT License (MIT)
|
|
4
|
-
*
|
|
5
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
6
|
-
*
|
|
7
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
9
|
-
* in the Software without restriction, including without limitation the rights
|
|
10
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
12
|
-
* furnished to do so, subject to the following conditions:
|
|
13
|
-
*
|
|
14
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
15
|
-
* copies or substantial portions of the Software.
|
|
16
|
-
*
|
|
17
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
-
* SOFTWARE.
|
|
24
|
-
*/
|
|
25
|
-
|
|
1
|
+
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
26
3
|
import { Component } from 'react';
|
|
27
4
|
import keycode from 'keycode';
|
|
28
5
|
import { FormFieldMessages } from '@instructure/ui-form-field/v11_6';
|
|
@@ -34,346 +11,307 @@ import { withStyle } from '@instructure/emotion';
|
|
|
34
11
|
import generateStyle from './styles.js';
|
|
35
12
|
import generateComponentTheme from './theme.js';
|
|
36
13
|
import { allowedProps } from './props.js';
|
|
37
|
-
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
38
14
|
function keyEventIsClickButton(e) {
|
|
39
|
-
|
|
15
|
+
return e.keyCode === keycode.codes.space || e.keyCode === keycode.codes.enter;
|
|
40
16
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
category: components
|
|
45
|
-
---
|
|
46
|
-
**/
|
|
47
|
-
let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec(_class = _dec2(_class = class FileDrop extends Component {
|
|
48
|
-
static displayName = 'FileDrop';
|
|
49
|
-
static componentId = 'FileDrop';
|
|
50
|
-
static allowedProps = allowedProps;
|
|
51
|
-
static defaultProps = {
|
|
52
|
-
onClick: function (_e) {},
|
|
53
|
-
shouldEnablePreview: false,
|
|
54
|
-
shouldAllowMultiple: false,
|
|
55
|
-
shouldAllowRepeats: true,
|
|
56
|
-
maxSize: Infinity,
|
|
57
|
-
minSize: 0,
|
|
58
|
-
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
59
|
-
messages: [],
|
|
60
|
-
display: 'block'
|
|
61
|
-
};
|
|
62
|
-
constructor(props) {
|
|
63
|
-
super(props);
|
|
64
|
-
this.defaultId = props.deterministicId();
|
|
65
|
-
this.messagesId = props.deterministicId('FileDrop-messages');
|
|
66
|
-
}
|
|
67
|
-
componentDidMount() {
|
|
68
|
-
this.props.makeStyles?.(this.makeStyleProps());
|
|
69
|
-
}
|
|
70
|
-
componentDidUpdate() {
|
|
71
|
-
this.props.makeStyles?.(this.makeStyleProps());
|
|
72
|
-
}
|
|
73
|
-
componentWillUnmount() {
|
|
74
|
-
// Release any preview blob URLs we minted; otherwise the browser pins
|
|
75
|
-
// each File in memory until the document goes away.
|
|
76
|
-
this._objectUrls.forEach(url => window.URL.revokeObjectURL(url));
|
|
77
|
-
this._objectUrls = [];
|
|
78
|
-
}
|
|
79
|
-
_objectUrls = [];
|
|
80
|
-
convertToFile(fileLikeItem) {
|
|
81
|
-
if (fileLikeItem instanceof DataTransferItem) return fileLikeItem.getAsFile();else return fileLikeItem;
|
|
82
|
-
}
|
|
83
|
-
makeStyleProps = () => {
|
|
84
|
-
return {
|
|
85
|
-
functionallyDisabled: this.functionallyDisabled,
|
|
86
|
-
visuallyDisabled: this.interaction === 'disabled',
|
|
87
|
-
dragRejected: this.state.isDragRejected || this.invalid,
|
|
88
|
-
dragAccepted: this.state.isDragAccepted
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
state = {
|
|
92
|
-
isDragAccepted: false,
|
|
93
|
-
isDragRejected: false,
|
|
94
|
-
isFocused: false,
|
|
95
|
-
isFileBrowserDisplayed: false
|
|
96
|
-
};
|
|
97
|
-
enterCounter = 0;
|
|
98
|
-
fileInputEl;
|
|
99
|
-
defaultId = null;
|
|
100
|
-
messagesId = '';
|
|
101
|
-
ref = null;
|
|
102
|
-
handleElementRef = el => {
|
|
103
|
-
this.ref = el;
|
|
104
|
-
};
|
|
105
|
-
get functionallyDisabled() {
|
|
106
|
-
return this.interaction === 'disabled' || this.interaction === 'readonly';
|
|
107
|
-
}
|
|
108
|
-
get interaction() {
|
|
109
|
-
return getInteraction({
|
|
110
|
-
props: this.props
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
get hasMessages() {
|
|
114
|
-
return this.props.messages ? this.props.messages.length > 0 : false;
|
|
115
|
-
}
|
|
116
|
-
get invalid() {
|
|
117
|
-
if (this.hasMessages) {
|
|
118
|
-
return this.props.messages.findIndex(message => {
|
|
119
|
-
return message.type === 'error' || message.type === 'newError';
|
|
120
|
-
}) >= 0;
|
|
17
|
+
class FileDrop extends Component {
|
|
18
|
+
static{
|
|
19
|
+
this.displayName = 'FileDrop';
|
|
121
20
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
getDataTransferItems(e, shouldEnablePreview) {
|
|
125
|
-
let list = [];
|
|
126
|
-
Array.from(getEventFiles(e, this.fileInputEl)).forEach(file => {
|
|
127
|
-
const fileObj = this.convertToFile(file);
|
|
128
|
-
if (fileObj) list.push(fileObj);
|
|
129
|
-
});
|
|
130
|
-
if (list.length > 1) {
|
|
131
|
-
list = this.props.shouldAllowMultiple ? list : [list[0]];
|
|
21
|
+
static{
|
|
22
|
+
this.componentId = 'FileDrop';
|
|
132
23
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
24
|
+
static{
|
|
25
|
+
this.allowedProps = allowedProps;
|
|
26
|
+
}
|
|
27
|
+
static{
|
|
28
|
+
this.defaultProps = {
|
|
29
|
+
onClick: function(_e) {},
|
|
30
|
+
shouldEnablePreview: false,
|
|
31
|
+
shouldAllowMultiple: false,
|
|
32
|
+
shouldAllowRepeats: true,
|
|
33
|
+
maxSize: Infinity,
|
|
34
|
+
minSize: 0,
|
|
35
|
+
messages: [],
|
|
36
|
+
display: 'block'
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
constructor(props){
|
|
40
|
+
super(props), this._objectUrls = [], this.makeStyleProps = ()=>{
|
|
41
|
+
return {
|
|
42
|
+
functionallyDisabled: this.functionallyDisabled,
|
|
43
|
+
visuallyDisabled: this.interaction === 'disabled',
|
|
44
|
+
dragRejected: this.state.isDragRejected || this.invalid,
|
|
45
|
+
dragAccepted: this.state.isDragAccepted
|
|
46
|
+
};
|
|
47
|
+
}, this.state = {
|
|
48
|
+
isDragAccepted: false,
|
|
49
|
+
isDragRejected: false,
|
|
50
|
+
isFocused: false,
|
|
51
|
+
isFileBrowserDisplayed: false
|
|
52
|
+
}, this.enterCounter = 0, this.defaultId = null, this.messagesId = '', this.ref = null, this.handleElementRef = (el)=>{
|
|
53
|
+
this.ref = el;
|
|
54
|
+
}, this.handleDragEnter = (e)=>{
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
this.enterCounter += 1;
|
|
57
|
+
if (this.enterCounter > 1) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const allFilesAccepted = this.allFilesAccepted(this.getDataTransferItems(e));
|
|
61
|
+
this.setState({
|
|
62
|
+
isDragAccepted: allFilesAccepted,
|
|
63
|
+
isDragRejected: !allFilesAccepted
|
|
64
|
+
});
|
|
65
|
+
this.props.onDragEnter?.(e);
|
|
66
|
+
}, this.handleDragOver = (e)=>{
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
e.stopPropagation();
|
|
69
|
+
try {
|
|
70
|
+
const event = e;
|
|
71
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
72
|
+
} catch (err) {}
|
|
73
|
+
this.props.onDragOver?.(e);
|
|
74
|
+
return false;
|
|
75
|
+
}, this.handleDragLeave = (e)=>{
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
this.enterCounter -= 1;
|
|
78
|
+
if (this.enterCounter > 0) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
this.setState({
|
|
82
|
+
isDragAccepted: false,
|
|
83
|
+
isDragRejected: false
|
|
84
|
+
});
|
|
85
|
+
this.props.onDragLeave?.(e);
|
|
86
|
+
}, this.handleChange = (e)=>{
|
|
87
|
+
const { onDrop, onDropAccepted, onDropRejected, shouldEnablePreview } = this.props;
|
|
88
|
+
const fileList = this.getDataTransferItems(e, shouldEnablePreview);
|
|
89
|
+
const [accepted, rejected] = this.parseFiles(fileList);
|
|
90
|
+
e.preventDefault();
|
|
91
|
+
this.enterCounter = 0;
|
|
92
|
+
if (accepted.length > 0 && 'dataTransfer' in e) {
|
|
93
|
+
this.fileInputEl.files = e.dataTransfer.files;
|
|
94
|
+
}
|
|
95
|
+
onDrop && onDrop(accepted, rejected, e);
|
|
96
|
+
if (rejected.length > 0 && onDropRejected) {
|
|
97
|
+
onDropRejected(rejected, e);
|
|
98
|
+
}
|
|
99
|
+
if (accepted.length > 0 && onDropAccepted) {
|
|
100
|
+
onDropAccepted(accepted, e);
|
|
101
|
+
}
|
|
102
|
+
this.setState({
|
|
103
|
+
isDragAccepted: false,
|
|
104
|
+
isDragRejected: false,
|
|
105
|
+
isFileBrowserDisplayed: false
|
|
106
|
+
});
|
|
107
|
+
}, this.fileAccepted = (file)=>{
|
|
108
|
+
if (this.props.accept) return accepts(file, this.props.accept);
|
|
109
|
+
else return true;
|
|
110
|
+
}, this.handleRef = (el)=>{
|
|
111
|
+
this.fileInputEl = el;
|
|
112
|
+
if (typeof this.props.inputRef === 'function') {
|
|
113
|
+
this.props.inputRef(el);
|
|
114
|
+
}
|
|
115
|
+
}, this.handleBlur = ()=>{
|
|
116
|
+
this.setState({
|
|
117
|
+
isFocused: false,
|
|
118
|
+
isFileBrowserDisplayed: false
|
|
119
|
+
});
|
|
120
|
+
}, this.handleFocus = ()=>{
|
|
121
|
+
this.setState({
|
|
122
|
+
isFocused: true,
|
|
123
|
+
isFileBrowserDisplayed: false
|
|
124
|
+
});
|
|
125
|
+
}, this.handleClick = (e)=>{
|
|
126
|
+
if (this.fileInputEl.value && this.props.shouldAllowRepeats) {
|
|
127
|
+
this.fileInputEl.value = null;
|
|
128
|
+
}
|
|
129
|
+
this.fileInputEl?.focus();
|
|
130
|
+
this.props.onClick(e);
|
|
131
|
+
this.setState({
|
|
132
|
+
isFileBrowserDisplayed: true
|
|
133
|
+
});
|
|
134
|
+
}, this.handleKeyDown = (e)=>{
|
|
135
|
+
if (this.state.isFocused && keyEventIsClickButton(e)) {
|
|
136
|
+
if (this.props.shouldAllowRepeats) {
|
|
137
|
+
this.fileInputEl.value = null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}, this.handleKeyUp = (e)=>{
|
|
141
|
+
if (e.keyCode === keycode.codes.esc && this.state.isFileBrowserDisplayed) {
|
|
142
|
+
e.stopPropagation();
|
|
143
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
144
|
+
this.setState({
|
|
145
|
+
isFileBrowserDisplayed: false
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
this.defaultId = props.deterministicId();
|
|
150
|
+
this.messagesId = props.deterministicId('FileDrop-messages');
|
|
151
|
+
}
|
|
152
|
+
componentDidMount() {
|
|
153
|
+
this.props.makeStyles?.(this.makeStyleProps());
|
|
154
|
+
}
|
|
155
|
+
componentDidUpdate() {
|
|
156
|
+
this.props.makeStyles?.(this.makeStyleProps());
|
|
157
|
+
}
|
|
158
|
+
componentWillUnmount() {
|
|
159
|
+
this._objectUrls.forEach((url)=>window.URL.revokeObjectURL(url));
|
|
160
|
+
this._objectUrls = [];
|
|
141
161
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
e.preventDefault();
|
|
146
|
-
// Count the dropzone and any children that are entered.
|
|
147
|
-
this.enterCounter += 1;
|
|
148
|
-
// Don't trigger onDragEnter for each children after the first one
|
|
149
|
-
if (this.enterCounter > 1) {
|
|
150
|
-
return;
|
|
162
|
+
convertToFile(fileLikeItem) {
|
|
163
|
+
if (fileLikeItem instanceof DataTransferItem) return fileLikeItem.getAsFile();
|
|
164
|
+
else return fileLikeItem;
|
|
151
165
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
isDragAccepted: allFilesAccepted,
|
|
155
|
-
isDragRejected: !allFilesAccepted
|
|
156
|
-
});
|
|
157
|
-
this.props.onDragEnter?.(e);
|
|
158
|
-
};
|
|
159
|
-
handleDragOver = e => {
|
|
160
|
-
e.preventDefault();
|
|
161
|
-
e.stopPropagation();
|
|
162
|
-
try {
|
|
163
|
-
const event = e;
|
|
164
|
-
event.dataTransfer.dropEffect = 'copy';
|
|
165
|
-
} catch (err) {
|
|
166
|
-
// continue regardless of error
|
|
166
|
+
get functionallyDisabled() {
|
|
167
|
+
return this.interaction === 'disabled' || this.interaction === 'readonly';
|
|
167
168
|
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
if (this.enterCounter > 0) {
|
|
176
|
-
return;
|
|
169
|
+
get interaction() {
|
|
170
|
+
return getInteraction({
|
|
171
|
+
props: this.props
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
get hasMessages() {
|
|
175
|
+
return this.props.messages ? this.props.messages.length > 0 : false;
|
|
177
176
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.enterCounter = 0;
|
|
208
|
-
// When dropping a file the browser does not populate the input's
|
|
209
|
-
// 'files' property, so we need to do it manually. This will also populate
|
|
210
|
-
// the input's 'value' prop, which contains the first file's path
|
|
211
|
-
if (accepted.length > 0 && 'dataTransfer' in e) {
|
|
212
|
-
this.fileInputEl.files = e.dataTransfer.files;
|
|
177
|
+
get invalid() {
|
|
178
|
+
if (this.hasMessages) {
|
|
179
|
+
return this.props.messages.findIndex((message)=>{
|
|
180
|
+
return message.type === 'error' || message.type === 'newError';
|
|
181
|
+
}) >= 0;
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
getDataTransferItems(e, shouldEnablePreview) {
|
|
186
|
+
let list = [];
|
|
187
|
+
Array.from(getEventFiles(e, this.fileInputEl)).forEach((file)=>{
|
|
188
|
+
const fileObj = this.convertToFile(file);
|
|
189
|
+
if (fileObj) list.push(fileObj);
|
|
190
|
+
});
|
|
191
|
+
if (list.length > 1) {
|
|
192
|
+
list = this.props.shouldAllowMultiple ? list : [
|
|
193
|
+
list[0]
|
|
194
|
+
];
|
|
195
|
+
}
|
|
196
|
+
if (shouldEnablePreview) {
|
|
197
|
+
return list.map((file)=>{
|
|
198
|
+
const preview = window.URL.createObjectURL(file);
|
|
199
|
+
this._objectUrls.push(preview);
|
|
200
|
+
return Object.assign(file, {
|
|
201
|
+
preview
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
return list;
|
|
213
206
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
207
|
+
parseFiles(fileList) {
|
|
208
|
+
const accepted = [];
|
|
209
|
+
const rejected = [];
|
|
210
|
+
fileList.forEach((file)=>{
|
|
211
|
+
const fileObj = this.convertToFile(file);
|
|
212
|
+
if (fileObj && this.fileAccepted(fileObj) && this.fileMatchSize(fileObj)) {
|
|
213
|
+
accepted.push(file);
|
|
214
|
+
} else {
|
|
215
|
+
rejected.push(file);
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
return [
|
|
219
|
+
accepted,
|
|
220
|
+
rejected
|
|
221
|
+
];
|
|
217
222
|
}
|
|
218
|
-
|
|
219
|
-
|
|
223
|
+
fileMatchSize(file) {
|
|
224
|
+
return file.size <= this.props.maxSize && file.size >= this.props.minSize;
|
|
220
225
|
}
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
isDragRejected: false,
|
|
224
|
-
isFileBrowserDisplayed: false
|
|
225
|
-
});
|
|
226
|
-
};
|
|
227
|
-
fileAccepted = file => {
|
|
228
|
-
if (this.props.accept) return accepts(file, this.props.accept);else return true;
|
|
229
|
-
};
|
|
230
|
-
fileMatchSize(file) {
|
|
231
|
-
return file.size <= this.props.maxSize && file.size >= this.props.minSize;
|
|
232
|
-
}
|
|
233
|
-
allFilesAccepted(files) {
|
|
234
|
-
return files.every(this.fileAccepted);
|
|
235
|
-
}
|
|
236
|
-
acceptStr() {
|
|
237
|
-
const {
|
|
238
|
-
accept
|
|
239
|
-
} = this.props;
|
|
240
|
-
return accept ? getAcceptList(accept).join(',') : undefined;
|
|
241
|
-
}
|
|
242
|
-
renderLabel() {
|
|
243
|
-
const {
|
|
244
|
-
renderLabel
|
|
245
|
-
} = this.props;
|
|
246
|
-
return callRenderProp(renderLabel, {
|
|
247
|
-
isDragAccepted: this.state.isDragAccepted,
|
|
248
|
-
isDragRejected: this.state.isDragRejected,
|
|
249
|
-
interaction: this.interaction
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
handleRef = el => {
|
|
253
|
-
this.fileInputEl = el;
|
|
254
|
-
if (typeof this.props.inputRef === 'function') {
|
|
255
|
-
this.props.inputRef(el);
|
|
226
|
+
allFilesAccepted(files) {
|
|
227
|
+
return files.every(this.fileAccepted);
|
|
256
228
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
isFocused: false,
|
|
261
|
-
isFileBrowserDisplayed: false
|
|
262
|
-
});
|
|
263
|
-
};
|
|
264
|
-
handleFocus = () => {
|
|
265
|
-
this.setState({
|
|
266
|
-
isFocused: true,
|
|
267
|
-
isFileBrowserDisplayed: false
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
handleClick = e => {
|
|
271
|
-
if (this.fileInputEl.value && this.props.shouldAllowRepeats) {
|
|
272
|
-
this.fileInputEl.value = null;
|
|
229
|
+
acceptStr() {
|
|
230
|
+
const { accept } = this.props;
|
|
231
|
+
return accept ? getAcceptList(accept).join(',') : undefined;
|
|
273
232
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
handleKeyDown = e => {
|
|
282
|
-
if (this.state.isFocused && keyEventIsClickButton(e)) {
|
|
283
|
-
if (this.props.shouldAllowRepeats) {
|
|
284
|
-
this.fileInputEl.value = null;
|
|
285
|
-
}
|
|
233
|
+
renderLabel() {
|
|
234
|
+
const { renderLabel } = this.props;
|
|
235
|
+
return callRenderProp(renderLabel, {
|
|
236
|
+
isDragAccepted: this.state.isDragAccepted,
|
|
237
|
+
isDragRejected: this.state.isDragRejected,
|
|
238
|
+
interaction: this.interaction
|
|
239
|
+
});
|
|
286
240
|
}
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
241
|
+
render() {
|
|
242
|
+
const { display, height, width, minWidth, maxWidth, margin, onDropAccepted, onDropRejected, styles, ...props } = this.props;
|
|
243
|
+
const id = this.props.id || this.defaultId;
|
|
244
|
+
const focusColor = this.state.isDragRejected || this.invalid ? 'danger' : undefined;
|
|
245
|
+
return /*#__PURE__*/ _jsxs(View, {
|
|
246
|
+
display: display,
|
|
247
|
+
position: "relative",
|
|
248
|
+
width: width,
|
|
249
|
+
minWidth: minWidth,
|
|
250
|
+
maxWidth: maxWidth,
|
|
251
|
+
margin: margin,
|
|
252
|
+
height: height,
|
|
253
|
+
elementRef: this.handleElementRef,
|
|
254
|
+
"data-cid": "FileDrop",
|
|
255
|
+
children: [
|
|
256
|
+
/*#__PURE__*/ _jsx("label", {
|
|
257
|
+
css: this.props.styles?.fileDropLabel,
|
|
258
|
+
htmlFor: id,
|
|
259
|
+
onDragEnter: this.handleDragEnter,
|
|
260
|
+
onDragOver: this.handleDragOver,
|
|
261
|
+
onDragLeave: this.handleDragLeave,
|
|
262
|
+
onDrop: this.handleChange,
|
|
263
|
+
children: /*#__PURE__*/ _jsx(View, {
|
|
264
|
+
borderRadius: String(styles?.fileDropLayout?.borderRadius),
|
|
265
|
+
display: "block",
|
|
266
|
+
position: "relative",
|
|
267
|
+
withFocusOutline: this.state.isFocused,
|
|
268
|
+
focusColor: focusColor,
|
|
269
|
+
height: height,
|
|
270
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
271
|
+
css: this.props.styles?.fileDropLabelContent,
|
|
272
|
+
children: /*#__PURE__*/ _jsx("span", {
|
|
273
|
+
css: this.props.styles?.fileDropLayout,
|
|
274
|
+
children: /*#__PURE__*/ _jsx(View, {
|
|
275
|
+
height: height,
|
|
276
|
+
children: this.renderLabel()
|
|
277
|
+
})
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
})
|
|
281
|
+
}),
|
|
282
|
+
/*#__PURE__*/ _jsx("input", {
|
|
283
|
+
...passthroughProps(props),
|
|
284
|
+
onClick: this.handleClick,
|
|
285
|
+
type: "file",
|
|
286
|
+
css: this.props.styles?.fileDropInput,
|
|
287
|
+
id: id,
|
|
288
|
+
ref: this.handleRef,
|
|
289
|
+
onFocus: this.handleFocus,
|
|
290
|
+
onBlur: this.handleBlur,
|
|
291
|
+
onKeyDown: this.handleKeyDown,
|
|
292
|
+
onKeyUp: this.handleKeyUp,
|
|
293
|
+
multiple: this.props.shouldAllowMultiple,
|
|
294
|
+
accept: this.acceptStr(),
|
|
295
|
+
onChange: this.handleChange,
|
|
296
|
+
"aria-describedby": this.hasMessages ? this.messagesId : undefined,
|
|
297
|
+
"aria-invalid": this.invalid,
|
|
298
|
+
disabled: this.functionallyDisabled
|
|
299
|
+
}),
|
|
300
|
+
this.hasMessages ? /*#__PURE__*/ _jsx(View, {
|
|
301
|
+
display: "block",
|
|
302
|
+
margin: "small 0 0",
|
|
303
|
+
children: /*#__PURE__*/ _jsx(FormFieldMessages, {
|
|
304
|
+
id: this.messagesId,
|
|
305
|
+
messages: this.props.messages
|
|
306
|
+
})
|
|
307
|
+
}) : null
|
|
308
|
+
]
|
|
309
|
+
});
|
|
297
310
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
width,
|
|
304
|
-
minWidth,
|
|
305
|
-
maxWidth,
|
|
306
|
-
margin,
|
|
307
|
-
onDropAccepted,
|
|
308
|
-
onDropRejected,
|
|
309
|
-
styles,
|
|
310
|
-
...props
|
|
311
|
-
} = this.props;
|
|
312
|
-
const id = this.props.id || this.defaultId;
|
|
313
|
-
const focusColor = this.state.isDragRejected || this.invalid ? 'danger' : undefined;
|
|
314
|
-
return _jsxs(View, {
|
|
315
|
-
display: display,
|
|
316
|
-
position: "relative" // contain visually hidden file input element
|
|
317
|
-
,
|
|
318
|
-
width: width,
|
|
319
|
-
minWidth: minWidth,
|
|
320
|
-
maxWidth: maxWidth,
|
|
321
|
-
margin: margin,
|
|
322
|
-
height: height,
|
|
323
|
-
elementRef: this.handleElementRef,
|
|
324
|
-
"data-cid": "FileDrop",
|
|
325
|
-
children: [_jsx("label", {
|
|
326
|
-
css: this.props.styles?.fileDropLabel,
|
|
327
|
-
htmlFor: id,
|
|
328
|
-
onDragEnter: this.handleDragEnter,
|
|
329
|
-
onDragOver: this.handleDragOver,
|
|
330
|
-
onDragLeave: this.handleDragLeave,
|
|
331
|
-
onDrop: this.handleChange,
|
|
332
|
-
children: _jsx(View, {
|
|
333
|
-
borderRadius: String(styles?.fileDropLayout?.borderRadius),
|
|
334
|
-
display: "block",
|
|
335
|
-
position: "relative",
|
|
336
|
-
withFocusOutline: this.state.isFocused,
|
|
337
|
-
focusColor: focusColor,
|
|
338
|
-
height: height,
|
|
339
|
-
children: _jsx("span", {
|
|
340
|
-
css: this.props.styles?.fileDropLabelContent,
|
|
341
|
-
children: _jsx("span", {
|
|
342
|
-
css: this.props.styles?.fileDropLayout,
|
|
343
|
-
children: _jsx(View, {
|
|
344
|
-
height: height,
|
|
345
|
-
children: this.renderLabel()
|
|
346
|
-
})
|
|
347
|
-
})
|
|
348
|
-
})
|
|
349
|
-
})
|
|
350
|
-
}), _jsx("input", {
|
|
351
|
-
...passthroughProps(props),
|
|
352
|
-
onClick: this.handleClick,
|
|
353
|
-
type: "file",
|
|
354
|
-
css: this.props.styles?.fileDropInput,
|
|
355
|
-
id: id,
|
|
356
|
-
ref: this.handleRef,
|
|
357
|
-
onFocus: this.handleFocus,
|
|
358
|
-
onBlur: this.handleBlur,
|
|
359
|
-
onKeyDown: this.handleKeyDown,
|
|
360
|
-
onKeyUp: this.handleKeyUp,
|
|
361
|
-
multiple: this.props.shouldAllowMultiple,
|
|
362
|
-
accept: this.acceptStr(),
|
|
363
|
-
onChange: this.handleChange,
|
|
364
|
-
"aria-describedby": this.hasMessages ? this.messagesId : undefined,
|
|
365
|
-
"aria-invalid": this.invalid,
|
|
366
|
-
disabled: this.functionallyDisabled
|
|
367
|
-
}), this.hasMessages ? _jsx(View, {
|
|
368
|
-
display: "block",
|
|
369
|
-
margin: "small 0 0",
|
|
370
|
-
children: _jsx(FormFieldMessages, {
|
|
371
|
-
id: this.messagesId,
|
|
372
|
-
messages: this.props.messages
|
|
373
|
-
})
|
|
374
|
-
}) : null]
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
|
-
}) || _class) || _class);
|
|
311
|
+
}
|
|
312
|
+
FileDrop = _ts_decorate([
|
|
313
|
+
withDeterministicId(),
|
|
314
|
+
withStyle(generateStyle, generateComponentTheme)
|
|
315
|
+
], FileDrop);
|
|
378
316
|
export default FileDrop;
|
|
379
|
-
export { FileDrop };
|
|
317
|
+
export { FileDrop };
|