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