@instructure/ui-file-drop 8.25.1-snapshot-10 → 8.25.1-snapshot-13

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