-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfileupload.umd.js
493 lines (486 loc) · 17.7 KB
/
fileupload.umd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
require('../source/modules/smart.fileupload');
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
(factory((global.fileupload = {}),global.React));
}(this, (function (exports,React) { 'use strict';
React = React && React.hasOwnProperty('default') ? React['default'] : React;
const Smart = window.Smart;
/**
FileUpload provides an easy and integrated way for users to upload multiple files.
*/
class FileUpload extends React.Component {
constructor(props) {
super(props);
this.componentRef = React.createRef();
}
// Gets the id of the React component.
get id() {
if (!this._id) {
this._id = 'FileUpload' + Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return this._id;
}
/** Sets or gets the file types that can be submitted to the server via the element. This property corresponds to the 'accept' attribute of the hidden file input which is submitted to the URL specified by the uploadUrl property.
* Property type: string | null
*/
get accept() {
return this.nativeElement ? this.nativeElement.accept : undefined;
}
set accept(value) {
if (this.nativeElement) {
this.nativeElement.accept = value;
}
}
/** Sets or gets the animation mode. Animation is disabled when the property is set to 'none'
* Property type: Animation | string
*/
get animation() {
return this.nativeElement ? this.nativeElement.animation : undefined;
}
set animation(value) {
if (this.nativeElement) {
this.nativeElement.animation = value;
}
}
/** Appends the list with selected files to a new custom container specified by the user. If the value of the property is a string it must represent a valid id of an HTML element inside the DOM that will be used as the new container for the uploaded files list.
* Property type: string
*/
get appendTo() {
return this.nativeElement ? this.nativeElement.appendTo : undefined;
}
set appendTo(value) {
if (this.nativeElement) {
this.nativeElement.appendTo = value;
}
}
/** Sets or gets whether files will be automatically uploaded after selection.
* Property type: boolean
*/
get autoUpload() {
return this.nativeElement ? this.nativeElement.autoUpload : undefined;
}
set autoUpload(value) {
if (this.nativeElement) {
this.nativeElement.autoUpload = value;
}
}
/** Allows to upload a directory. Files in all subfolders will be uploaded also. This option is supported only in Firefox and Chrome.
* Property type: boolean
*/
get directory() {
return this.nativeElement ? this.nativeElement.directory : undefined;
}
set directory(value) {
if (this.nativeElement) {
this.nativeElement.directory = value;
}
}
/** Enables or disables the element.
* Property type: boolean
*/
get disabled() {
return this.nativeElement ? this.nativeElement.disabled : undefined;
}
set disabled(value) {
if (this.nativeElement) {
this.nativeElement.disabled = value;
}
}
/** Defines a custom container that will be used as the new drop zone for file uploads. The dropped files will be added in the fileUpload's list. If 'dropZone' property set to true, the default drop zone inside the element will be used instead. If set to certain id of an HTML element inside the DOM then it will be used as the drop zone.
* Property type: any
*/
get dropZone() {
return this.nativeElement ? this.nativeElement.dropZone : undefined;
}
set dropZone(value) {
if (this.nativeElement) {
this.nativeElement.dropZone = value;
}
}
/** Hides the footer element and it's contents (Upload All, Pause All and Close All buttons).
* Property type: boolean
*/
get hideFooter() {
return this.nativeElement ? this.nativeElement.hideFooter : undefined;
}
set hideFooter(value) {
if (this.nativeElement) {
this.nativeElement.hideFooter = value;
}
}
/** Applies a custom template to the file items that represent the uploaded files.
* Property type: any
*/
get itemTemplate() {
return this.nativeElement ? this.nativeElement.itemTemplate : undefined;
}
set itemTemplate(value) {
if (this.nativeElement) {
this.nativeElement.itemTemplate = value;
}
}
/** Sets or gets the language. Used in conjunction with the property messages.
* Property type: string
*/
get locale() {
return this.nativeElement ? this.nativeElement.locale : undefined;
}
set locale(value) {
if (this.nativeElement) {
this.nativeElement.locale = value;
}
}
/** Callback used to customize the format of the messages that are returned from the Localization Module.
* Property type: any
*/
get localizeFormatFunction() {
return this.nativeElement ? this.nativeElement.localizeFormatFunction : undefined;
}
set localizeFormatFunction(value) {
if (this.nativeElement) {
this.nativeElement.localizeFormatFunction = value;
}
}
/** Sets the various text values used in the widget. Useful for localization. The localization object has the following fields: browse, pauseFile, cancelFile, uploadFile, pauseAll, cancelAll, uploadAll. It's recommended these messages to be set before element's initialization.
* Property type: any
*/
get messages() {
return this.nativeElement ? this.nativeElement.messages : undefined;
}
set messages(value) {
if (this.nativeElement) {
this.nativeElement.messages = value;
}
}
/** Sets or gets whether multiple item uploads are allowed.
* Property type: boolean
*/
get multiple() {
return this.nativeElement ? this.nativeElement.multiple : undefined;
}
set multiple(value) {
if (this.nativeElement) {
this.nativeElement.multiple = value;
}
}
/** Sets or gets the name attribute of the hidden file input which is submitted to the URL specified by the uploadUrl property.
* Property type: string
*/
get name() {
return this.nativeElement ? this.nativeElement.name : undefined;
}
set name(value) {
if (this.nativeElement) {
this.nativeElement.name = value;
}
}
/** If the element is readonly, users cannot interact with it.
* Property type: boolean
*/
get readonly() {
return this.nativeElement ? this.nativeElement.readonly : undefined;
}
set readonly(value) {
if (this.nativeElement) {
this.nativeElement.readonly = value;
}
}
/** Callback that can used to handle various server responses and error codes.
* Property type: any
*/
get responseHandler() {
return this.nativeElement ? this.nativeElement.responseHandler : undefined;
}
set responseHandler(value) {
if (this.nativeElement) {
this.nativeElement.responseHandler = value;
}
}
/** Sets or gets the value indicating whether the element is aligned to support locales using right-to-left fonts.
* Property type: boolean
*/
get rightToLeft() {
return this.nativeElement ? this.nativeElement.rightToLeft : undefined;
}
set rightToLeft(value) {
if (this.nativeElement) {
this.nativeElement.rightToLeft = value;
}
}
/** Callback function, used to change the headers of the file upload's XHR request.
* Property type: any
*/
get setHeaders() {
return this.nativeElement ? this.nativeElement.setHeaders : undefined;
}
set setHeaders(value) {
if (this.nativeElement) {
this.nativeElement.setHeaders = value;
}
}
/** Displays a progress bar at the bottom of each uploaded item to show the progress of the uploading process.
* Property type: boolean
*/
get showProgress() {
return this.nativeElement ? this.nativeElement.showProgress : undefined;
}
set showProgress(value) {
if (this.nativeElement) {
this.nativeElement.showProgress = value;
}
}
/** Determines the theme. Theme defines the look of the element
* Property type: string
*/
get theme() {
return this.nativeElement ? this.nativeElement.theme : undefined;
}
set theme(value) {
if (this.nativeElement) {
this.nativeElement.theme = value;
}
}
/** Sets or gets the upload URL. This property corresponds to the upload form's action attribute. For example, the uploadUrl property can point to a PHP file, which handles the upload operation on the server-side.
* Property type: string
*/
get uploadUrl() {
return this.nativeElement ? this.nativeElement.uploadUrl : undefined;
}
set uploadUrl(value) {
if (this.nativeElement) {
this.nativeElement.uploadUrl = value;
}
}
/** If is set to true, the element cannot be focused.
* Property type: boolean
*/
get unfocusable() {
return this.nativeElement ? this.nativeElement.unfocusable : undefined;
}
set unfocusable(value) {
if (this.nativeElement) {
this.nativeElement.unfocusable = value;
}
}
/** Sets or gets the remove URL. This property corresponds to the form's action attribute. For example, the removeUrl property can point to a PHP file, which handles the remove operation on the server-side.
* Property type: string
*/
get removeUrl() {
return this.nativeElement ? this.nativeElement.removeUrl : undefined;
}
set removeUrl(value) {
if (this.nativeElement) {
this.nativeElement.removeUrl = value;
}
}
/** Gets the file upload value.
* Property type: any
*/
get value() {
return this.nativeElement ? this.nativeElement.value : undefined;
}
set value(value) {
if (this.nativeElement) {
this.nativeElement.value = value;
}
}
/** Callback used to validate the files immediatelly after their selection. Retuns a boolean value. If the returned value is false, the file is removed from list and a 'validationError is fired.
* Property type: any
*/
get validateFile() {
return this.nativeElement ? this.nativeElement.validateFile : undefined;
}
set validateFile(value) {
if (this.nativeElement) {
this.nativeElement.validateFile = value;
}
}
// Gets the properties of the React component.
get properties() {
return ["accept", "animation", "appendTo", "autoUpload", "directory", "disabled", "dropZone", "hideFooter", "itemTemplate", "locale", "localizeFormatFunction", "messages", "multiple", "name", "readonly", "responseHandler", "rightToLeft", "setHeaders", "showProgress", "theme", "uploadUrl", "unfocusable", "removeUrl", "value", "validateFile"];
}
// Gets the events of the React component.
get eventListeners() {
return ["onFileSelected", "onUploadCanceled", "onUploadCompleted", "onUploadError", "onUploadPaused", "onUploadStarted", "onValidationError", "onCreate", "onReady"];
}
/** Opens a popup to browse for a file.
*/
browse() {
if (this.nativeElement.isRendered) {
this.nativeElement.browse();
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.browse();
});
}
}
/** Cancels all selected files. The files are removed from the list and their uploading is prevented.
*/
cancelAll() {
if (this.nativeElement.isRendered) {
this.nativeElement.cancelAll();
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.cancelAll();
});
}
}
/** Cancels a selected file. The file is removed from the file list and it's uploading is prevented.
* @param {number} index. Index of the file which will be canceled.
*/
cancelFile(index) {
if (this.nativeElement.isRendered) {
this.nativeElement.cancelFile(index);
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.cancelFile(index);
});
}
}
/** Pauses the uploading of all files. File upload is prevented but the files remain in the file list.
*/
pauseAll() {
if (this.nativeElement.isRendered) {
this.nativeElement.pauseAll();
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.pauseAll();
});
}
}
/** Pauses upload of a file with particular index. File upload is prevented but file ramains in the file list.
* @param {number} id. Index of the file which will be paused.
*/
pauseFile(id) {
if (this.nativeElement.isRendered) {
this.nativeElement.pauseFile(id);
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.pauseFile(id);
});
}
}
/** Uploads all selected files.
*/
uploadAll() {
if (this.nativeElement.isRendered) {
this.nativeElement.uploadAll();
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.uploadAll();
});
}
}
/** Uploads a selected file.
* @param {number} id. Index of the file which will be uploaded.
*/
uploadFile(id) {
if (this.nativeElement.isRendered) {
this.nativeElement.uploadFile(id);
}
else {
this.nativeElement.whenRendered(() => {
this.nativeElement.uploadFile(id);
});
}
}
componentDidRender(initialize) {
const that = this;
const props = {};
const events = {};
let styles = null;
for (let prop in that.props) {
if (prop === 'children') {
continue;
}
if (prop === 'style') {
styles = that.props[prop];
continue;
}
if (prop.startsWith('on') && that.properties.indexOf(prop) === -1) {
events[prop] = that.props[prop];
continue;
}
props[prop] = that.props[prop];
}
if (initialize) {
that.nativeElement = this.componentRef.current;
}
for (let prop in props) {
if (prop === 'class' || prop === 'className') {
const classNames = props[prop].trim().split(' ');
for (let className in classNames) {
if (!that.nativeElement.classList.contains(classNames[className]) && classNames[className] !== "") {
that.nativeElement.classList.add(classNames[className]);
}
}
continue;
}
if (props[prop] !== that.nativeElement[prop]) {
const normalizeProp = (str) => {
return str.replace(/-([a-z])/g, function (g) {
return g[1].toUpperCase();
});
};
if (prop === 'hover' || prop === 'active' || prop === 'focus' || prop === 'selected') {
that.nativeElement.setAttribute(prop, '');
}
const normalizedProp = normalizeProp(prop);
that.nativeElement[normalizedProp] = props[prop];
}
}
for (let eventName in events) {
that[eventName] = events[eventName];
that.nativeElement[eventName.toLowerCase()] = events[eventName];
}
if (initialize) {
Smart.Render();
if (that.onCreate) {
that.onCreate();
}
that.nativeElement.whenRendered(() => {
if (that.onReady) {
that.onReady();
}
});
}
// setup styles.
if (styles) {
for (let styleName in styles) {
that.nativeElement.style[styleName] = styles[styleName];
}
}
}
componentDidMount() {
this.componentDidRender(true);
}
componentDidUpdate() {
this.componentDidRender(false);
}
componentWillUnmount() {
const that = this;
if (!that.nativeElement) {
return;
}
that.nativeElement.whenRenderedCallbacks = [];
for (let i = 0; i < that.eventListeners.length; i++) {
const eventName = that.eventListeners[i];
that.nativeElement.removeEventListener(eventName.substring(2).toLowerCase(), that[eventName]);
}
}
render() {
return (React.createElement("smart-file-upload", { ref: this.componentRef }, this.props.children));
}
}
exports.Smart = Smart;
exports.FileUpload = FileUpload;
exports.default = FileUpload;
Object.defineProperty(exports, '__esModule', { value: true });
})));