@instructure/ui-file-drop 11.6.0 → 11.6.1-snapshot-129
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 +41 -296
- package/es/FileDrop/{index.js → v1/index.js} +3 -3
- package/es/FileDrop/v2/index.js +371 -0
- package/es/FileDrop/v2/props.js +26 -0
- package/es/FileDrop/v2/styles.js +111 -0
- package/es/FileDrop/v2/utils/accepts.js +51 -0
- package/es/FileDrop/v2/utils/getEventFiles.js +41 -0
- package/es/{index.js → exports/a.js} +1 -1
- package/{src/index.ts → es/exports/b.js} +1 -3
- package/lib/FileDrop/v1/index.js +379 -0
- package/lib/FileDrop/{index.js → v2/index.js} +9 -9
- package/lib/FileDrop/v2/props.js +31 -0
- package/lib/FileDrop/v2/styles.js +117 -0
- package/lib/FileDrop/v2/utils/accepts.js +58 -0
- package/lib/FileDrop/v2/utils/getEventFiles.js +47 -0
- package/lib/{index.js → exports/a.js} +2 -2
- package/lib/exports/b.js +12 -0
- package/package.json +42 -20
- package/src/FileDrop/{index.tsx → v1/index.tsx} +4 -4
- package/src/FileDrop/{props.ts → v1/props.ts} +1 -1
- package/src/FileDrop/{styles.ts → v1/styles.ts} +2 -6
- package/src/FileDrop/v2/README.md +177 -0
- package/src/FileDrop/v2/index.tsx +419 -0
- package/src/FileDrop/v2/props.ts +211 -0
- package/src/FileDrop/v2/styles.ts +140 -0
- package/src/FileDrop/v2/utils/accepts.ts +54 -0
- package/src/FileDrop/v2/utils/getEventFiles.ts +47 -0
- package/src/exports/a.ts +26 -0
- package/src/exports/b.ts +26 -0
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/FileDrop/{index.d.ts → v1/index.d.ts} +1 -1
- package/types/FileDrop/v1/index.d.ts.map +1 -0
- package/types/FileDrop/{props.d.ts → v1/props.d.ts} +1 -1
- package/types/FileDrop/v1/props.d.ts.map +1 -0
- package/types/FileDrop/v1/styles.d.ts.map +1 -0
- package/types/FileDrop/v1/theme.d.ts.map +1 -0
- package/types/FileDrop/v1/utils/accepts.d.ts.map +1 -0
- package/types/FileDrop/v1/utils/getEventFiles.d.ts.map +1 -0
- package/types/FileDrop/v2/index.d.ts +89 -0
- package/types/FileDrop/v2/index.d.ts.map +1 -0
- package/types/FileDrop/v2/props.d.ts +134 -0
- package/types/FileDrop/v2/props.d.ts.map +1 -0
- package/types/FileDrop/v2/styles.d.ts +17 -0
- package/types/FileDrop/v2/styles.d.ts.map +1 -0
- package/types/FileDrop/v2/utils/accepts.d.ts +5 -0
- package/types/FileDrop/v2/utils/accepts.d.ts.map +1 -0
- package/types/FileDrop/v2/utils/getEventFiles.d.ts +5 -0
- package/types/FileDrop/v2/utils/getEventFiles.d.ts.map +1 -0
- package/types/exports/a.d.ts +3 -0
- package/types/exports/a.d.ts.map +1 -0
- package/types/exports/b.d.ts +3 -0
- package/types/exports/b.d.ts.map +1 -0
- package/types/FileDrop/index.d.ts.map +0 -1
- package/types/FileDrop/props.d.ts.map +0 -1
- package/types/FileDrop/styles.d.ts.map +0 -1
- package/types/FileDrop/theme.d.ts.map +0 -1
- package/types/FileDrop/utils/accepts.d.ts.map +0 -1
- package/types/FileDrop/utils/getEventFiles.d.ts.map +0 -1
- package/types/index.d.ts +0 -3
- package/types/index.d.ts.map +0 -1
- /package/es/FileDrop/{props.js → v1/props.js} +0 -0
- /package/es/FileDrop/{styles.js → v1/styles.js} +0 -0
- /package/es/FileDrop/{theme.js → v1/theme.js} +0 -0
- /package/es/FileDrop/{utils → v1/utils}/accepts.js +0 -0
- /package/es/FileDrop/{utils → v1/utils}/getEventFiles.js +0 -0
- /package/lib/FileDrop/{props.js → v1/props.js} +0 -0
- /package/lib/FileDrop/{styles.js → v1/styles.js} +0 -0
- /package/lib/FileDrop/{theme.js → v1/theme.js} +0 -0
- /package/lib/FileDrop/{utils → v1/utils}/accepts.js +0 -0
- /package/lib/FileDrop/{utils → v1/utils}/getEventFiles.js +0 -0
- /package/src/FileDrop/{README.md → v1/README.md} +0 -0
- /package/src/FileDrop/{theme.ts → v1/theme.ts} +0 -0
- /package/src/FileDrop/{utils → v1/utils}/accepts.ts +0 -0
- /package/src/FileDrop/{utils → v1/utils}/getEventFiles.ts +0 -0
- /package/types/FileDrop/{styles.d.ts → v1/styles.d.ts} +0 -0
- /package/types/FileDrop/{theme.d.ts → v1/theme.d.ts} +0 -0
- /package/types/FileDrop/{utils → v1/utils}/accepts.d.ts +0 -0
- /package/types/FileDrop/{utils → v1/utils}/getEventFiles.d.ts +0 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
const _excluded = ["display", "height", "width", "minWidth", "maxWidth", "margin", "onDropAccepted", "onDropRejected", "styles"];
|
|
4
|
+
var _dec, _dec2, _class, _FileDrop;
|
|
5
|
+
/*
|
|
6
|
+
* The MIT License (MIT)
|
|
7
|
+
*
|
|
8
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
9
|
+
*
|
|
10
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
* in the Software without restriction, including without limitation the rights
|
|
13
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
* furnished to do so, subject to the following conditions:
|
|
16
|
+
*
|
|
17
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
* copies or substantial portions of the Software.
|
|
19
|
+
*
|
|
20
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
* SOFTWARE.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
import { Component } from 'react';
|
|
30
|
+
import keycode from 'keycode';
|
|
31
|
+
import { FormFieldMessages } from '@instructure/ui-form-field/latest';
|
|
32
|
+
import { View } from '@instructure/ui-view/latest';
|
|
33
|
+
import { callRenderProp, passthroughProps, getInteraction, withDeterministicId } from '@instructure/ui-react-utils';
|
|
34
|
+
import { accepts, getAcceptList } from "./utils/accepts.js";
|
|
35
|
+
import { getEventFiles } from "./utils/getEventFiles.js";
|
|
36
|
+
import { withStyle } from '@instructure/emotion';
|
|
37
|
+
import generateStyle from "./styles.js";
|
|
38
|
+
import { allowedProps } from "./props.js";
|
|
39
|
+
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
40
|
+
function keyEventIsClickButton(e) {
|
|
41
|
+
return e.keyCode === keycode.codes.space || e.keyCode === keycode.codes.enter;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
---
|
|
46
|
+
category: components
|
|
47
|
+
---
|
|
48
|
+
**/
|
|
49
|
+
let FileDrop = (_dec = withDeterministicId(), _dec2 = withStyle(generateStyle), _dec(_class = _dec2(_class = (_FileDrop = class FileDrop extends Component {
|
|
50
|
+
constructor(props) {
|
|
51
|
+
super(props);
|
|
52
|
+
this.makeStyleProps = () => {
|
|
53
|
+
return {
|
|
54
|
+
...this.props,
|
|
55
|
+
functionallyDisabled: this.functionallyDisabled,
|
|
56
|
+
visuallyDisabled: this.interaction === 'disabled',
|
|
57
|
+
dragRejected: this.state.isDragRejected || this.invalid,
|
|
58
|
+
dragAccepted: this.state.isDragAccepted
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
this.state = {
|
|
62
|
+
isDragAccepted: false,
|
|
63
|
+
isDragRejected: false,
|
|
64
|
+
isFocused: false,
|
|
65
|
+
isFileBrowserDisplayed: false
|
|
66
|
+
};
|
|
67
|
+
this.enterCounter = 0;
|
|
68
|
+
this.fileInputEl = void 0;
|
|
69
|
+
this.defaultId = null;
|
|
70
|
+
this.messagesId = '';
|
|
71
|
+
this.ref = null;
|
|
72
|
+
this.handleElementRef = el => {
|
|
73
|
+
this.ref = el;
|
|
74
|
+
};
|
|
75
|
+
this.handleDragEnter = e => {
|
|
76
|
+
var _this$props$onDragEnt, _this$props;
|
|
77
|
+
e.preventDefault();
|
|
78
|
+
// Count the dropzone and any children that are entered.
|
|
79
|
+
this.enterCounter += 1;
|
|
80
|
+
// Don't trigger onDragEnter for each children after the first one
|
|
81
|
+
if (this.enterCounter > 1) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const allFilesAccepted = this.allFilesAccepted(this.getDataTransferItems(e));
|
|
85
|
+
this.setState({
|
|
86
|
+
isDragAccepted: allFilesAccepted,
|
|
87
|
+
isDragRejected: !allFilesAccepted
|
|
88
|
+
});
|
|
89
|
+
(_this$props$onDragEnt = (_this$props = this.props).onDragEnter) === null || _this$props$onDragEnt === void 0 ? void 0 : _this$props$onDragEnt.call(_this$props, e);
|
|
90
|
+
};
|
|
91
|
+
this.handleDragOver = e => {
|
|
92
|
+
var _this$props$onDragOve, _this$props2;
|
|
93
|
+
e.preventDefault();
|
|
94
|
+
e.stopPropagation();
|
|
95
|
+
try {
|
|
96
|
+
const event = e;
|
|
97
|
+
event.dataTransfer.dropEffect = 'copy';
|
|
98
|
+
} catch (err) {
|
|
99
|
+
// continue regardless of error
|
|
100
|
+
}
|
|
101
|
+
(_this$props$onDragOve = (_this$props2 = this.props).onDragOver) === null || _this$props$onDragOve === void 0 ? void 0 : _this$props$onDragOve.call(_this$props2, e);
|
|
102
|
+
return false;
|
|
103
|
+
};
|
|
104
|
+
this.handleDragLeave = e => {
|
|
105
|
+
var _this$props$onDragLea, _this$props3;
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
this.enterCounter -= 1;
|
|
108
|
+
// Only deactivate once the dropzone and all children was left
|
|
109
|
+
if (this.enterCounter > 0) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.setState({
|
|
113
|
+
isDragAccepted: false,
|
|
114
|
+
isDragRejected: false
|
|
115
|
+
});
|
|
116
|
+
(_this$props$onDragLea = (_this$props3 = this.props).onDragLeave) === null || _this$props$onDragLea === void 0 ? void 0 : _this$props$onDragLea.call(_this$props3, e);
|
|
117
|
+
};
|
|
118
|
+
this.handleChange = e => {
|
|
119
|
+
const _this$props4 = this.props,
|
|
120
|
+
onDrop = _this$props4.onDrop,
|
|
121
|
+
onDropAccepted = _this$props4.onDropAccepted,
|
|
122
|
+
onDropRejected = _this$props4.onDropRejected,
|
|
123
|
+
shouldEnablePreview = _this$props4.shouldEnablePreview;
|
|
124
|
+
const fileList = this.getDataTransferItems(e, shouldEnablePreview);
|
|
125
|
+
const _this$parseFiles = this.parseFiles(fileList),
|
|
126
|
+
_this$parseFiles2 = _slicedToArray(_this$parseFiles, 2),
|
|
127
|
+
accepted = _this$parseFiles2[0],
|
|
128
|
+
rejected = _this$parseFiles2[1];
|
|
129
|
+
e.preventDefault();
|
|
130
|
+
this.enterCounter = 0;
|
|
131
|
+
// When dropping a file the browser does not populate the input's
|
|
132
|
+
// 'files' property, so we need to do it manually. This will also populate
|
|
133
|
+
// the input's 'value' prop, which contains the first file's path
|
|
134
|
+
if (accepted.length > 0 && 'dataTransfer' in e) {
|
|
135
|
+
this.fileInputEl.files = e.dataTransfer.files;
|
|
136
|
+
}
|
|
137
|
+
onDrop && onDrop(accepted, rejected, e);
|
|
138
|
+
if (rejected.length > 0 && onDropRejected) {
|
|
139
|
+
onDropRejected(rejected, e);
|
|
140
|
+
}
|
|
141
|
+
if (accepted.length > 0 && onDropAccepted) {
|
|
142
|
+
onDropAccepted(accepted, e);
|
|
143
|
+
}
|
|
144
|
+
this.setState({
|
|
145
|
+
isDragAccepted: false,
|
|
146
|
+
isDragRejected: false,
|
|
147
|
+
isFileBrowserDisplayed: false
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
this.fileAccepted = file => {
|
|
151
|
+
if (this.props.accept) return accepts(file, this.props.accept);else return true;
|
|
152
|
+
};
|
|
153
|
+
this.handleRef = el => {
|
|
154
|
+
this.fileInputEl = el;
|
|
155
|
+
if (typeof this.props.inputRef === 'function') {
|
|
156
|
+
this.props.inputRef(el);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
this.handleBlur = () => {
|
|
160
|
+
this.setState({
|
|
161
|
+
isFocused: false,
|
|
162
|
+
isFileBrowserDisplayed: false
|
|
163
|
+
});
|
|
164
|
+
};
|
|
165
|
+
this.handleFocus = () => {
|
|
166
|
+
this.setState({
|
|
167
|
+
isFocused: true,
|
|
168
|
+
isFileBrowserDisplayed: false
|
|
169
|
+
});
|
|
170
|
+
};
|
|
171
|
+
this.handleClick = e => {
|
|
172
|
+
var _this$fileInputEl;
|
|
173
|
+
if (this.fileInputEl.value && this.props.shouldAllowRepeats) {
|
|
174
|
+
this.fileInputEl.value = null;
|
|
175
|
+
}
|
|
176
|
+
// focus the input (because FF won't)
|
|
177
|
+
(_this$fileInputEl = this.fileInputEl) === null || _this$fileInputEl === void 0 ? void 0 : _this$fileInputEl.focus();
|
|
178
|
+
this.props.onClick(e);
|
|
179
|
+
this.setState({
|
|
180
|
+
isFileBrowserDisplayed: true
|
|
181
|
+
});
|
|
182
|
+
};
|
|
183
|
+
this.handleKeyDown = e => {
|
|
184
|
+
if (this.state.isFocused && keyEventIsClickButton(e)) {
|
|
185
|
+
if (this.props.shouldAllowRepeats) {
|
|
186
|
+
this.fileInputEl.value = null;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
this.handleKeyUp = e => {
|
|
191
|
+
// This is to handle the case where ESC is pressed inside a Dialog so that
|
|
192
|
+
// closing the file browser dialog doesn't also close the Dialog.
|
|
193
|
+
if (e.keyCode === keycode.codes.esc && this.state.isFileBrowserDisplayed) {
|
|
194
|
+
e.stopPropagation();
|
|
195
|
+
e.nativeEvent.stopImmediatePropagation();
|
|
196
|
+
this.setState({
|
|
197
|
+
isFileBrowserDisplayed: false
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
this.defaultId = props.deterministicId();
|
|
202
|
+
this.messagesId = props.deterministicId('FileDrop-messages');
|
|
203
|
+
}
|
|
204
|
+
componentDidMount() {
|
|
205
|
+
var _this$props$makeStyle, _this$props5;
|
|
206
|
+
(_this$props$makeStyle = (_this$props5 = this.props).makeStyles) === null || _this$props$makeStyle === void 0 ? void 0 : _this$props$makeStyle.call(_this$props5, this.makeStyleProps());
|
|
207
|
+
}
|
|
208
|
+
componentDidUpdate() {
|
|
209
|
+
var _this$props$makeStyle2, _this$props6;
|
|
210
|
+
(_this$props$makeStyle2 = (_this$props6 = this.props).makeStyles) === null || _this$props$makeStyle2 === void 0 ? void 0 : _this$props$makeStyle2.call(_this$props6, this.makeStyleProps());
|
|
211
|
+
}
|
|
212
|
+
convertToFile(fileLikeItem) {
|
|
213
|
+
if (fileLikeItem instanceof DataTransferItem) return fileLikeItem.getAsFile();else return fileLikeItem;
|
|
214
|
+
}
|
|
215
|
+
get functionallyDisabled() {
|
|
216
|
+
return this.interaction === 'disabled' || this.interaction === 'readonly';
|
|
217
|
+
}
|
|
218
|
+
get interaction() {
|
|
219
|
+
return getInteraction({
|
|
220
|
+
props: this.props
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
get hasMessages() {
|
|
224
|
+
return this.props.messages ? this.props.messages.length > 0 : false;
|
|
225
|
+
}
|
|
226
|
+
get invalid() {
|
|
227
|
+
if (this.hasMessages) {
|
|
228
|
+
return this.props.messages.findIndex(message => {
|
|
229
|
+
return message.type === 'error' || message.type === 'newError';
|
|
230
|
+
}) >= 0;
|
|
231
|
+
}
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
getDataTransferItems(e, shouldEnablePreview) {
|
|
235
|
+
let list = [];
|
|
236
|
+
Array.from(getEventFiles(e, this.fileInputEl)).forEach(file => {
|
|
237
|
+
const fileObj = this.convertToFile(file);
|
|
238
|
+
if (fileObj) list.push(fileObj);
|
|
239
|
+
});
|
|
240
|
+
if (list.length > 1) {
|
|
241
|
+
list = this.props.shouldAllowMultiple ? list : [list[0]];
|
|
242
|
+
}
|
|
243
|
+
if (shouldEnablePreview) {
|
|
244
|
+
return list.map(file => Object.assign(file, {
|
|
245
|
+
preview: window.URL.createObjectURL(file)
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
return list;
|
|
249
|
+
}
|
|
250
|
+
parseFiles(fileList) {
|
|
251
|
+
const accepted = [];
|
|
252
|
+
const rejected = [];
|
|
253
|
+
fileList.forEach(file => {
|
|
254
|
+
const fileObj = this.convertToFile(file);
|
|
255
|
+
if (fileObj && this.fileAccepted(fileObj) && this.fileMatchSize(fileObj)) {
|
|
256
|
+
accepted.push(file);
|
|
257
|
+
} else {
|
|
258
|
+
rejected.push(file);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
return [accepted, rejected];
|
|
262
|
+
}
|
|
263
|
+
fileMatchSize(file) {
|
|
264
|
+
return file.size <= this.props.maxSize && file.size >= this.props.minSize;
|
|
265
|
+
}
|
|
266
|
+
allFilesAccepted(files) {
|
|
267
|
+
return files.every(this.fileAccepted);
|
|
268
|
+
}
|
|
269
|
+
acceptStr() {
|
|
270
|
+
const accept = this.props.accept;
|
|
271
|
+
return accept ? getAcceptList(accept).join(',') : void 0;
|
|
272
|
+
}
|
|
273
|
+
renderLabel() {
|
|
274
|
+
const renderLabel = this.props.renderLabel;
|
|
275
|
+
return callRenderProp(renderLabel, {
|
|
276
|
+
isDragAccepted: this.state.isDragAccepted,
|
|
277
|
+
isDragRejected: this.state.isDragRejected,
|
|
278
|
+
interaction: this.interaction
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
render() {
|
|
282
|
+
var _this$props$styles, _styles$fileDropLayou, _this$props$styles2, _this$props$styles3, _this$props$styles4;
|
|
283
|
+
const _this$props7 = this.props,
|
|
284
|
+
display = _this$props7.display,
|
|
285
|
+
height = _this$props7.height,
|
|
286
|
+
width = _this$props7.width,
|
|
287
|
+
minWidth = _this$props7.minWidth,
|
|
288
|
+
maxWidth = _this$props7.maxWidth,
|
|
289
|
+
margin = _this$props7.margin,
|
|
290
|
+
onDropAccepted = _this$props7.onDropAccepted,
|
|
291
|
+
onDropRejected = _this$props7.onDropRejected,
|
|
292
|
+
styles = _this$props7.styles,
|
|
293
|
+
props = _objectWithoutProperties(_this$props7, _excluded);
|
|
294
|
+
const id = this.props.id || this.defaultId;
|
|
295
|
+
const focusColor = this.state.isDragRejected || this.invalid ? 'danger' : void 0;
|
|
296
|
+
return _jsxs(View, {
|
|
297
|
+
display: display,
|
|
298
|
+
position: "relative" // contain visually hidden file input element
|
|
299
|
+
,
|
|
300
|
+
width: width,
|
|
301
|
+
minWidth: minWidth,
|
|
302
|
+
maxWidth: maxWidth,
|
|
303
|
+
margin: margin,
|
|
304
|
+
height: height,
|
|
305
|
+
elementRef: this.handleElementRef,
|
|
306
|
+
"data-cid": "FileDrop",
|
|
307
|
+
children: [_jsx("label", {
|
|
308
|
+
css: (_this$props$styles = this.props.styles) === null || _this$props$styles === void 0 ? void 0 : _this$props$styles.fileDropLabel,
|
|
309
|
+
htmlFor: id,
|
|
310
|
+
onDragEnter: this.handleDragEnter,
|
|
311
|
+
onDragOver: this.handleDragOver,
|
|
312
|
+
onDragLeave: this.handleDragLeave,
|
|
313
|
+
onDrop: this.handleChange,
|
|
314
|
+
children: _jsx(View, {
|
|
315
|
+
borderRadius: String(styles === null || styles === void 0 ? void 0 : (_styles$fileDropLayou = styles.fileDropLayout) === null || _styles$fileDropLayou === void 0 ? void 0 : _styles$fileDropLayou.borderRadius),
|
|
316
|
+
display: "block",
|
|
317
|
+
position: "relative",
|
|
318
|
+
withFocusOutline: this.state.isFocused,
|
|
319
|
+
focusColor: focusColor,
|
|
320
|
+
height: height,
|
|
321
|
+
children: _jsx("span", {
|
|
322
|
+
css: (_this$props$styles2 = this.props.styles) === null || _this$props$styles2 === void 0 ? void 0 : _this$props$styles2.fileDropLabelContent,
|
|
323
|
+
children: _jsx("span", {
|
|
324
|
+
css: (_this$props$styles3 = this.props.styles) === null || _this$props$styles3 === void 0 ? void 0 : _this$props$styles3.fileDropLayout,
|
|
325
|
+
children: _jsx(View, {
|
|
326
|
+
height: height,
|
|
327
|
+
children: this.renderLabel()
|
|
328
|
+
})
|
|
329
|
+
})
|
|
330
|
+
})
|
|
331
|
+
})
|
|
332
|
+
}), _jsx("input", {
|
|
333
|
+
...passthroughProps(props),
|
|
334
|
+
onClick: this.handleClick,
|
|
335
|
+
type: "file",
|
|
336
|
+
css: (_this$props$styles4 = this.props.styles) === null || _this$props$styles4 === void 0 ? void 0 : _this$props$styles4.fileDropInput,
|
|
337
|
+
id: id,
|
|
338
|
+
ref: this.handleRef,
|
|
339
|
+
onFocus: this.handleFocus,
|
|
340
|
+
onBlur: this.handleBlur,
|
|
341
|
+
onKeyDown: this.handleKeyDown,
|
|
342
|
+
onKeyUp: this.handleKeyUp,
|
|
343
|
+
multiple: this.props.shouldAllowMultiple,
|
|
344
|
+
accept: this.acceptStr(),
|
|
345
|
+
onChange: this.handleChange,
|
|
346
|
+
"aria-describedby": this.hasMessages ? this.messagesId : void 0,
|
|
347
|
+
"aria-invalid": this.invalid,
|
|
348
|
+
disabled: this.functionallyDisabled
|
|
349
|
+
}), this.hasMessages ? _jsx(View, {
|
|
350
|
+
display: "block",
|
|
351
|
+
margin: "small 0 0",
|
|
352
|
+
children: _jsx(FormFieldMessages, {
|
|
353
|
+
id: this.messagesId,
|
|
354
|
+
messages: this.props.messages
|
|
355
|
+
})
|
|
356
|
+
}) : null]
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
}, _FileDrop.displayName = "FileDrop", _FileDrop.componentId = 'FileDrop', _FileDrop.allowedProps = allowedProps, _FileDrop.defaultProps = {
|
|
360
|
+
onClick: function (_e) {},
|
|
361
|
+
shouldEnablePreview: false,
|
|
362
|
+
shouldAllowMultiple: false,
|
|
363
|
+
shouldAllowRepeats: true,
|
|
364
|
+
maxSize: Infinity,
|
|
365
|
+
minSize: 0,
|
|
366
|
+
// Leave interaction default undefined so that `disabled` and `readOnly` can also be supplied
|
|
367
|
+
messages: [],
|
|
368
|
+
display: 'block'
|
|
369
|
+
}, _FileDrop)) || _class) || _class);
|
|
370
|
+
export default FileDrop;
|
|
371
|
+
export { FileDrop };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
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', 'inputRef'];
|
|
26
|
+
export { allowedProps };
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* ---
|
|
27
|
+
* private: true
|
|
28
|
+
* ---
|
|
29
|
+
* Generates the style object from the theme and provided additional information
|
|
30
|
+
* @param {Object} componentTheme The theme variable object.
|
|
31
|
+
* @param {Object} params the props and state of the component, the style is applied to
|
|
32
|
+
* @param {Object} sharedTokens Shared tokens from the theme
|
|
33
|
+
* @return {Object} The final style object, which will be used in the component
|
|
34
|
+
*/
|
|
35
|
+
const generateStyle = (componentTheme, params, _sharedTokens) => {
|
|
36
|
+
const height = params.height,
|
|
37
|
+
functionallyDisabled = params.functionallyDisabled,
|
|
38
|
+
visuallyDisabled = params.visuallyDisabled,
|
|
39
|
+
dragRejected = params.dragRejected,
|
|
40
|
+
dragAccepted = params.dragAccepted;
|
|
41
|
+
const dragAcceptedStyle = dragAccepted ? {
|
|
42
|
+
borderColor: componentTheme.acceptedColor
|
|
43
|
+
} : {};
|
|
44
|
+
const dragRejectedStyle = dragRejected ? {
|
|
45
|
+
borderColor: componentTheme.rejectedColor
|
|
46
|
+
} : {};
|
|
47
|
+
const functionallyDisabledStyle = functionallyDisabled ? {
|
|
48
|
+
cursor: 'not-allowed',
|
|
49
|
+
pointerEvents: 'none'
|
|
50
|
+
} : {};
|
|
51
|
+
const visuallyDisabledStyle = visuallyDisabled ? {
|
|
52
|
+
opacity: 0.5
|
|
53
|
+
} : {};
|
|
54
|
+
|
|
55
|
+
// Force the content to fill the space set with the 'height' React prop
|
|
56
|
+
const heightStyle = height ? {
|
|
57
|
+
height: '100%'
|
|
58
|
+
} : {};
|
|
59
|
+
|
|
60
|
+
// border color precedence: normal hover < dragRejected OR dragAccepted
|
|
61
|
+
const hoverBorderColor = !dragAccepted && !dragRejected ? {
|
|
62
|
+
borderColor: componentTheme.hoverBorderColor
|
|
63
|
+
} : {};
|
|
64
|
+
return {
|
|
65
|
+
fileDropLabel: {
|
|
66
|
+
label: 'fileDrop__label',
|
|
67
|
+
display: 'block',
|
|
68
|
+
boxSizing: 'border-box',
|
|
69
|
+
position: 'relative',
|
|
70
|
+
...heightStyle,
|
|
71
|
+
...functionallyDisabledStyle,
|
|
72
|
+
...visuallyDisabledStyle
|
|
73
|
+
},
|
|
74
|
+
fileDropInput: {
|
|
75
|
+
label: 'fileDrop__input',
|
|
76
|
+
width: '0.0625rem',
|
|
77
|
+
height: '0.0625rem',
|
|
78
|
+
margin: '-0.0625rem',
|
|
79
|
+
padding: 0,
|
|
80
|
+
position: 'absolute',
|
|
81
|
+
overflow: 'hidden',
|
|
82
|
+
clip: 'rect(0 0 0 0)',
|
|
83
|
+
border: 0
|
|
84
|
+
},
|
|
85
|
+
fileDropLabelContent: {
|
|
86
|
+
label: 'fileDrop__labelContent',
|
|
87
|
+
display: 'block',
|
|
88
|
+
backgroundColor: componentTheme.backgroundColor,
|
|
89
|
+
boxSizing: 'border-box',
|
|
90
|
+
zIndex: 1,
|
|
91
|
+
textAlign: 'center',
|
|
92
|
+
borderRadius: componentTheme.borderRadius,
|
|
93
|
+
border: `${componentTheme.borderWidth} ${componentTheme.borderStyle} ${componentTheme.borderColor}`,
|
|
94
|
+
cursor: 'pointer',
|
|
95
|
+
'&:hover': {
|
|
96
|
+
...hoverBorderColor
|
|
97
|
+
},
|
|
98
|
+
...heightStyle,
|
|
99
|
+
...dragAcceptedStyle,
|
|
100
|
+
...dragRejectedStyle
|
|
101
|
+
},
|
|
102
|
+
fileDropLayout: {
|
|
103
|
+
label: 'fileDrop__layout',
|
|
104
|
+
display: 'block',
|
|
105
|
+
overflow: 'hidden',
|
|
106
|
+
borderRadius: componentTheme.borderRadius,
|
|
107
|
+
...heightStyle
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export default generateStyle;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function accepts(file, acceptProp) {
|
|
26
|
+
if (file && acceptProp && file.type !== 'application/x-moz-file') {
|
|
27
|
+
const acceptList = getAcceptList(acceptProp);
|
|
28
|
+
const mimeType = file.type || '';
|
|
29
|
+
const baseMimeType = mimeType.replace(/\/.*$/, '');
|
|
30
|
+
return acceptList.some(type => {
|
|
31
|
+
if (type.charAt(0) === '.') {
|
|
32
|
+
// type is an extension like .pdf
|
|
33
|
+
if (!file.name) {
|
|
34
|
+
return mimeType.endsWith(type.slice(1));
|
|
35
|
+
}
|
|
36
|
+
return file.name.toLowerCase().endsWith(type.toLowerCase());
|
|
37
|
+
} else if (/\/\*$/.test(type)) {
|
|
38
|
+
// type is something like a image/* mime type
|
|
39
|
+
return baseMimeType === type.replace(/\/.*$/, '');
|
|
40
|
+
}
|
|
41
|
+
return mimeType === type;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
function getAcceptList(accept) {
|
|
47
|
+
const list = Array.isArray(accept) ? accept : accept.split(',');
|
|
48
|
+
return list.map(a => a.trim().replace(/^\w+$/, '.$&'));
|
|
49
|
+
}
|
|
50
|
+
export default accepts;
|
|
51
|
+
export { accepts, getAcceptList };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* The MIT License (MIT)
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2015 - present Instructure, Inc.
|
|
5
|
+
*
|
|
6
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
* of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
* in the Software without restriction, including without limitation the rights
|
|
9
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
* copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
* furnished to do so, subject to the following conditions:
|
|
12
|
+
*
|
|
13
|
+
* The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
* copies or substantial portions of the Software.
|
|
15
|
+
*
|
|
16
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
* SOFTWARE.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
function getEventFiles(event, inputEl) {
|
|
26
|
+
if ('dataTransfer' in event) {
|
|
27
|
+
const dt = event.dataTransfer;
|
|
28
|
+
if (dt) {
|
|
29
|
+
if (dt.files && dt.files.length) {
|
|
30
|
+
return dt.files;
|
|
31
|
+
} else if (dt.items && dt.items.length) {
|
|
32
|
+
return dt.items;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
} else if (inputEl && inputEl.files) {
|
|
36
|
+
return inputEl.files;
|
|
37
|
+
}
|
|
38
|
+
return [];
|
|
39
|
+
}
|
|
40
|
+
export default getEventFiles;
|
|
41
|
+
export { getEventFiles };
|