@instructure/ui-file-drop 8.25.1-snapshot-7 → 8.25.1-snapshot-10
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 +1 -1
- package/es/FileDrop/index.js +179 -184
- package/lib/FileDrop/index.js +179 -184
- package/package.json +15 -15
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/FileDrop/FileDropLocator.d.ts +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
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
|
-
## [8.25.1-snapshot-
|
|
6
|
+
## [8.25.1-snapshot-10](https://github.com/instructure/instructure-ui/compare/v8.25.0...v8.25.1-snapshot-10) (2022-06-20)
|
|
7
7
|
|
|
8
8
|
**Note:** Version bump only for package @instructure/ui-file-drop
|
|
9
9
|
|
package/es/FileDrop/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutPr
|
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
3
|
const _excluded = ["display", "height", "width", "minWidth", "maxWidth", "margin", "onDropAccepted", "onDropRejected"];
|
|
4
4
|
|
|
5
|
-
var _dec, _dec2, _dec3, _class
|
|
5
|
+
var _dec, _dec2, _dec3, _class;
|
|
6
6
|
|
|
7
7
|
/*
|
|
8
8
|
* The MIT License (MIT)
|
|
@@ -53,196 +53,68 @@ category: components
|
|
|
53
53
|
**/
|
|
54
54
|
|
|
55
55
|
|
|
56
|
-
let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class =
|
|
56
|
+
let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, generateComponentTheme), _dec3 = testable(), _dec(_class = _dec2(_class = _dec3(_class = class FileDrop extends Component {
|
|
57
|
+
static displayName = "FileDrop";
|
|
58
|
+
static componentId = 'FileDrop';
|
|
59
|
+
static propTypes = propTypes;
|
|
60
|
+
static allowedProps = allowedProps;
|
|
61
|
+
static defaultProps = {
|
|
62
|
+
onClick: function (_e) {},
|
|
63
|
+
shouldEnablePreview: false,
|
|
64
|
+
shouldAllowMultiple: false,
|
|
65
|
+
shouldAllowRepeats: true,
|
|
66
|
+
maxSize: Infinity,
|
|
67
|
+
minSize: 0,
|
|
68
|
+
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
69
|
+
messages: [],
|
|
70
|
+
display: 'block'
|
|
71
|
+
};
|
|
72
|
+
|
|
57
73
|
constructor(props) {
|
|
58
74
|
super(props);
|
|
59
|
-
|
|
60
|
-
this.makeStyleProps = () => {
|
|
61
|
-
return {
|
|
62
|
-
functionallyDisabled: this.functionallyDisabled,
|
|
63
|
-
visuallyDisabled: this.interaction === 'disabled',
|
|
64
|
-
dragRejected: this.state.isDragRejected || this.invalid,
|
|
65
|
-
dragAccepted: this.state.isDragAccepted
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
this.state = {
|
|
70
|
-
isDragAccepted: false,
|
|
71
|
-
isDragRejected: false,
|
|
72
|
-
isFocused: false,
|
|
73
|
-
isFileBrowserDisplayed: false
|
|
74
|
-
};
|
|
75
|
-
this.enterCounter = 0;
|
|
76
|
-
this.fileInputEl = null;
|
|
77
|
-
this.defaultId = null;
|
|
78
|
-
this.messagesId = '';
|
|
79
|
-
this.ref = null;
|
|
80
|
-
|
|
81
|
-
this.handleElementRef = el => {
|
|
82
|
-
this.ref = el;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
this.handleDragEnter = e => {
|
|
86
|
-
var _this$props$onDragEnt, _this$props;
|
|
87
|
-
|
|
88
|
-
e.preventDefault(); // Count the dropzone and any children that are entered.
|
|
89
|
-
|
|
90
|
-
this.enterCounter += 1; // Don't trigger onDragEnter for each children after the first one
|
|
91
|
-
|
|
92
|
-
if (this.enterCounter > 1) {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const allFilesAccepted = this.allFilesAccepted(this.getDataTransferItems(e));
|
|
97
|
-
this.setState({
|
|
98
|
-
isDragAccepted: allFilesAccepted,
|
|
99
|
-
isDragRejected: !allFilesAccepted
|
|
100
|
-
});
|
|
101
|
-
(_this$props$onDragEnt = (_this$props = this.props).onDragEnter) === null || _this$props$onDragEnt === void 0 ? void 0 : _this$props$onDragEnt.call(_this$props, e);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
this.handleDragOver = e => {
|
|
105
|
-
var _this$props$onDragOve, _this$props2;
|
|
106
|
-
|
|
107
|
-
e.preventDefault();
|
|
108
|
-
e.stopPropagation();
|
|
109
|
-
|
|
110
|
-
try {
|
|
111
|
-
const event = e;
|
|
112
|
-
event.dataTransfer.dropEffect = 'copy';
|
|
113
|
-
} catch (err) {// continue regardless of error
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
(_this$props$onDragOve = (_this$props2 = this.props).onDragOver) === null || _this$props$onDragOve === void 0 ? void 0 : _this$props$onDragOve.call(_this$props2, e);
|
|
117
|
-
return false;
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
this.handleDragLeave = e => {
|
|
121
|
-
var _this$props$onDragLea, _this$props3;
|
|
122
|
-
|
|
123
|
-
e.preventDefault();
|
|
124
|
-
this.enterCounter -= 1; // Only deactivate once the dropzone and all children was left
|
|
125
|
-
|
|
126
|
-
if (this.enterCounter > 0) {
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
this.setState({
|
|
131
|
-
isDragAccepted: false,
|
|
132
|
-
isDragRejected: false
|
|
133
|
-
});
|
|
134
|
-
(_this$props$onDragLea = (_this$props3 = this.props).onDragLeave) === null || _this$props$onDragLea === void 0 ? void 0 : _this$props$onDragLea.call(_this$props3, e);
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
this.handleChange = e => {
|
|
138
|
-
const _this$props4 = this.props,
|
|
139
|
-
onDrop = _this$props4.onDrop,
|
|
140
|
-
onDropAccepted = _this$props4.onDropAccepted,
|
|
141
|
-
onDropRejected = _this$props4.onDropRejected,
|
|
142
|
-
shouldEnablePreview = _this$props4.shouldEnablePreview;
|
|
143
|
-
const fileList = this.getDataTransferItems(e, shouldEnablePreview);
|
|
144
|
-
|
|
145
|
-
const _this$parseFiles = this.parseFiles(fileList),
|
|
146
|
-
_this$parseFiles2 = _slicedToArray(_this$parseFiles, 2),
|
|
147
|
-
accepted = _this$parseFiles2[0],
|
|
148
|
-
rejected = _this$parseFiles2[1];
|
|
149
|
-
|
|
150
|
-
e.preventDefault();
|
|
151
|
-
this.enterCounter = 0;
|
|
152
|
-
onDrop && onDrop(accepted, rejected, e);
|
|
153
|
-
|
|
154
|
-
if (rejected.length > 0 && onDropRejected) {
|
|
155
|
-
onDropRejected(rejected, e);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (accepted.length > 0 && onDropAccepted) {
|
|
159
|
-
onDropAccepted(accepted, e);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
this.setState({
|
|
163
|
-
isDragAccepted: false,
|
|
164
|
-
isDragRejected: false,
|
|
165
|
-
isFileBrowserDisplayed: false
|
|
166
|
-
});
|
|
167
|
-
};
|
|
168
|
-
|
|
169
|
-
this.fileAccepted = file => {
|
|
170
|
-
if (this.props.accept) return accepts(file, this.props.accept);else return true;
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
this.handleRef = el => {
|
|
174
|
-
this.fileInputEl = el;
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
this.handleBlur = () => {
|
|
178
|
-
this.setState({
|
|
179
|
-
isFocused: false,
|
|
180
|
-
isFileBrowserDisplayed: false
|
|
181
|
-
});
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
this.handleFocus = () => {
|
|
185
|
-
this.setState({
|
|
186
|
-
isFocused: true,
|
|
187
|
-
isFileBrowserDisplayed: false
|
|
188
|
-
});
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
this.handleClick = e => {
|
|
192
|
-
var _this$fileInputEl;
|
|
193
|
-
|
|
194
|
-
if (this.fileInputEl.value && this.props.shouldAllowRepeats) {
|
|
195
|
-
this.fileInputEl.value = null;
|
|
196
|
-
} // focus the input (because FF won't)
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
(_this$fileInputEl = this.fileInputEl) === null || _this$fileInputEl === void 0 ? void 0 : _this$fileInputEl.focus();
|
|
200
|
-
this.props.onClick(e);
|
|
201
|
-
this.setState({
|
|
202
|
-
isFileBrowserDisplayed: true
|
|
203
|
-
});
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
this.handleKeyDown = e => {
|
|
207
|
-
if (this.state.isFocused && keyEventIsClickButton(e)) {
|
|
208
|
-
if (this.props.shouldAllowRepeats) {
|
|
209
|
-
this.fileInputEl.value = null;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
this.handleKeyUp = e => {
|
|
215
|
-
// This is to handle the case where ESC is pressed inside a Dialog so that
|
|
216
|
-
// closing the file browser dialog doesn't also close the Dialog.
|
|
217
|
-
if (e.keyCode === keycode.codes.esc && this.state.isFileBrowserDisplayed) {
|
|
218
|
-
e.stopPropagation();
|
|
219
|
-
e.nativeEvent.stopImmediatePropagation();
|
|
220
|
-
this.setState({
|
|
221
|
-
isFileBrowserDisplayed: false
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
|
|
226
75
|
this.defaultId = props.deterministicId();
|
|
227
76
|
this.messagesId = props.deterministicId('FileDrop-messages');
|
|
228
77
|
}
|
|
229
78
|
|
|
230
79
|
componentDidMount() {
|
|
231
|
-
var _this$props$makeStyle, _this$
|
|
80
|
+
var _this$props$makeStyle, _this$props;
|
|
232
81
|
|
|
233
|
-
(_this$props$makeStyle = (_this$
|
|
82
|
+
(_this$props$makeStyle = (_this$props = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props, this.makeStyleProps());
|
|
234
83
|
}
|
|
235
84
|
|
|
236
85
|
componentDidUpdate() {
|
|
237
|
-
var _this$props$makeStyle2, _this$
|
|
86
|
+
var _this$props$makeStyle2, _this$props2;
|
|
238
87
|
|
|
239
|
-
(_this$props$makeStyle2 = (_this$
|
|
88
|
+
(_this$props$makeStyle2 = (_this$props2 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props2, this.makeStyleProps());
|
|
240
89
|
}
|
|
241
90
|
|
|
242
91
|
convertToFile(fileLikeItem) {
|
|
243
92
|
if (fileLikeItem instanceof DataTransferItem) return fileLikeItem.getAsFile();else return fileLikeItem;
|
|
244
93
|
}
|
|
245
94
|
|
|
95
|
+
makeStyleProps = () => {
|
|
96
|
+
return {
|
|
97
|
+
functionallyDisabled: this.functionallyDisabled,
|
|
98
|
+
visuallyDisabled: this.interaction === 'disabled',
|
|
99
|
+
dragRejected: this.state.isDragRejected || this.invalid,
|
|
100
|
+
dragAccepted: this.state.isDragAccepted
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
state = {
|
|
104
|
+
isDragAccepted: false,
|
|
105
|
+
isDragRejected: false,
|
|
106
|
+
isFocused: false,
|
|
107
|
+
isFileBrowserDisplayed: false
|
|
108
|
+
};
|
|
109
|
+
enterCounter = 0;
|
|
110
|
+
fileInputEl = null;
|
|
111
|
+
defaultId = null;
|
|
112
|
+
messagesId = '';
|
|
113
|
+
ref = null;
|
|
114
|
+
handleElementRef = el => {
|
|
115
|
+
this.ref = el;
|
|
116
|
+
};
|
|
117
|
+
|
|
246
118
|
get functionallyDisabled() {
|
|
247
119
|
return this.interaction === 'disabled' || this.interaction === 'readonly';
|
|
248
120
|
}
|
|
@@ -283,6 +155,56 @@ let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
283
155
|
return list;
|
|
284
156
|
}
|
|
285
157
|
|
|
158
|
+
handleDragEnter = e => {
|
|
159
|
+
var _this$props$onDragEnt, _this$props3;
|
|
160
|
+
|
|
161
|
+
e.preventDefault(); // Count the dropzone and any children that are entered.
|
|
162
|
+
|
|
163
|
+
this.enterCounter += 1; // Don't trigger onDragEnter for each children after the first one
|
|
164
|
+
|
|
165
|
+
if (this.enterCounter > 1) {
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const allFilesAccepted = this.allFilesAccepted(this.getDataTransferItems(e));
|
|
170
|
+
this.setState({
|
|
171
|
+
isDragAccepted: allFilesAccepted,
|
|
172
|
+
isDragRejected: !allFilesAccepted
|
|
173
|
+
});
|
|
174
|
+
(_this$props$onDragEnt = (_this$props3 = this.props).onDragEnter) === null || _this$props$onDragEnt === void 0 ? void 0 : _this$props$onDragEnt.call(_this$props3, e);
|
|
175
|
+
};
|
|
176
|
+
handleDragOver = e => {
|
|
177
|
+
var _this$props$onDragOve, _this$props4;
|
|
178
|
+
|
|
179
|
+
e.preventDefault();
|
|
180
|
+
e.stopPropagation();
|
|
181
|
+
|
|
182
|
+
try {
|
|
183
|
+
const event = e;
|
|
184
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
185
|
+
} catch (err) {// continue regardless of error
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
(_this$props$onDragOve = (_this$props4 = this.props).onDragOver) === null || _this$props$onDragOve === void 0 ? void 0 : _this$props$onDragOve.call(_this$props4, e);
|
|
189
|
+
return false;
|
|
190
|
+
};
|
|
191
|
+
handleDragLeave = e => {
|
|
192
|
+
var _this$props$onDragLea, _this$props5;
|
|
193
|
+
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
this.enterCounter -= 1; // Only deactivate once the dropzone and all children was left
|
|
196
|
+
|
|
197
|
+
if (this.enterCounter > 0) {
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
this.setState({
|
|
202
|
+
isDragAccepted: false,
|
|
203
|
+
isDragRejected: false
|
|
204
|
+
});
|
|
205
|
+
(_this$props$onDragLea = (_this$props5 = this.props).onDragLeave) === null || _this$props$onDragLea === void 0 ? void 0 : _this$props$onDragLea.call(_this$props5, e);
|
|
206
|
+
};
|
|
207
|
+
|
|
286
208
|
parseFiles(fileList) {
|
|
287
209
|
const accepted = [];
|
|
288
210
|
const rejected = [];
|
|
@@ -298,6 +220,41 @@ let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
298
220
|
return [accepted, rejected];
|
|
299
221
|
}
|
|
300
222
|
|
|
223
|
+
handleChange = e => {
|
|
224
|
+
const _this$props6 = this.props,
|
|
225
|
+
onDrop = _this$props6.onDrop,
|
|
226
|
+
onDropAccepted = _this$props6.onDropAccepted,
|
|
227
|
+
onDropRejected = _this$props6.onDropRejected,
|
|
228
|
+
shouldEnablePreview = _this$props6.shouldEnablePreview;
|
|
229
|
+
const fileList = this.getDataTransferItems(e, shouldEnablePreview);
|
|
230
|
+
|
|
231
|
+
const _this$parseFiles = this.parseFiles(fileList),
|
|
232
|
+
_this$parseFiles2 = _slicedToArray(_this$parseFiles, 2),
|
|
233
|
+
accepted = _this$parseFiles2[0],
|
|
234
|
+
rejected = _this$parseFiles2[1];
|
|
235
|
+
|
|
236
|
+
e.preventDefault();
|
|
237
|
+
this.enterCounter = 0;
|
|
238
|
+
onDrop && onDrop(accepted, rejected, e);
|
|
239
|
+
|
|
240
|
+
if (rejected.length > 0 && onDropRejected) {
|
|
241
|
+
onDropRejected(rejected, e);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (accepted.length > 0 && onDropAccepted) {
|
|
245
|
+
onDropAccepted(accepted, e);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this.setState({
|
|
249
|
+
isDragAccepted: false,
|
|
250
|
+
isDragRejected: false,
|
|
251
|
+
isFileBrowserDisplayed: false
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
fileAccepted = file => {
|
|
255
|
+
if (this.props.accept) return accepts(file, this.props.accept);else return true;
|
|
256
|
+
};
|
|
257
|
+
|
|
301
258
|
fileMatchSize(file) {
|
|
302
259
|
return file.size <= this.props.maxSize && file.size >= this.props.minSize;
|
|
303
260
|
}
|
|
@@ -320,6 +277,54 @@ let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
320
277
|
});
|
|
321
278
|
}
|
|
322
279
|
|
|
280
|
+
handleRef = el => {
|
|
281
|
+
this.fileInputEl = el;
|
|
282
|
+
};
|
|
283
|
+
handleBlur = () => {
|
|
284
|
+
this.setState({
|
|
285
|
+
isFocused: false,
|
|
286
|
+
isFileBrowserDisplayed: false
|
|
287
|
+
});
|
|
288
|
+
};
|
|
289
|
+
handleFocus = () => {
|
|
290
|
+
this.setState({
|
|
291
|
+
isFocused: true,
|
|
292
|
+
isFileBrowserDisplayed: false
|
|
293
|
+
});
|
|
294
|
+
};
|
|
295
|
+
handleClick = e => {
|
|
296
|
+
var _this$fileInputEl;
|
|
297
|
+
|
|
298
|
+
if (this.fileInputEl.value && this.props.shouldAllowRepeats) {
|
|
299
|
+
this.fileInputEl.value = null;
|
|
300
|
+
} // focus the input (because FF won't)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
(_this$fileInputEl = this.fileInputEl) === null || _this$fileInputEl === void 0 ? void 0 : _this$fileInputEl.focus();
|
|
304
|
+
this.props.onClick(e);
|
|
305
|
+
this.setState({
|
|
306
|
+
isFileBrowserDisplayed: true
|
|
307
|
+
});
|
|
308
|
+
};
|
|
309
|
+
handleKeyDown = e => {
|
|
310
|
+
if (this.state.isFocused && keyEventIsClickButton(e)) {
|
|
311
|
+
if (this.props.shouldAllowRepeats) {
|
|
312
|
+
this.fileInputEl.value = null;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
handleKeyUp = e => {
|
|
317
|
+
// This is to handle the case where ESC is pressed inside a Dialog so that
|
|
318
|
+
// closing the file browser dialog doesn't also close the Dialog.
|
|
319
|
+
if (e.keyCode === keycode.codes.esc && this.state.isFileBrowserDisplayed) {
|
|
320
|
+
e.stopPropagation();
|
|
321
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
322
|
+
this.setState({
|
|
323
|
+
isFileBrowserDisplayed: false
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
|
|
323
328
|
render() {
|
|
324
329
|
var _this$props$styles, _this$props$styles2, _this$props$styles3, _this$props$styles4;
|
|
325
330
|
|
|
@@ -390,16 +395,6 @@ let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle, g
|
|
|
390
395
|
})) : null);
|
|
391
396
|
}
|
|
392
397
|
|
|
393
|
-
}
|
|
394
|
-
onClick: function (_e) {},
|
|
395
|
-
shouldEnablePreview: false,
|
|
396
|
-
shouldAllowMultiple: false,
|
|
397
|
-
shouldAllowRepeats: true,
|
|
398
|
-
maxSize: Infinity,
|
|
399
|
-
minSize: 0,
|
|
400
|
-
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
401
|
-
messages: [],
|
|
402
|
-
display: 'block'
|
|
403
|
-
}, _class2)) || _class) || _class) || _class);
|
|
398
|
+
}) || _class) || _class) || _class);
|
|
404
399
|
export default FileDrop;
|
|
405
400
|
export { FileDrop };
|