Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uppy/core

Package Overview
Dependencies
Maintainers
5
Versions
142
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uppy/core - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

671

lib/index.js

@@ -1,21 +0,30 @@

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Translator = require('@uppy/utils/lib/Translator');
var Translator = require('@uppy/utils/lib/Translator');
var ee = require('namespace-emitter');
var cuid = require('cuid');
// const throttle = require('lodash.throttle')
var cuid = require('cuid'); // const throttle = require('lodash.throttle')
var prettyBytes = require('prettier-bytes');
var match = require('mime-match');
var DefaultStore = require('@uppy/store-default');
var getFileType = require('@uppy/utils/lib/getFileType');
var getFileNameAndExtension = require('@uppy/utils/lib/getFileNameAndExtension');
var generateFileID = require('@uppy/utils/lib/generateFileID');
var getTimeStamp = require('@uppy/utils/lib/getTimeStamp');
var supportsUploadProgress = require('./supportsUploadProgress');
var Plugin = require('./Plugin'); // Exported from here.

@@ -29,3 +38,6 @@

var Uppy = function () {
var Uppy =
/*#__PURE__*/
function () {
/**

@@ -38,4 +50,2 @@ * Instantiate Uppy

_classCallCheck(this, Uppy);
this.defaultLocale = {

@@ -74,6 +84,6 @@ strings: {

authenticateWith: 'Connect to %{pluginName}'
}
} // set default options
// set default options
};var defaultOptions = {
};
var defaultOptions = {
id: 'uppy',

@@ -96,17 +106,14 @@ autoProceed: false,

},
store: DefaultStore()
store: DefaultStore() // Merge default options with the ones set by user
// Merge default options with the ones set by user
};this.opts = _extends({}, defaultOptions, opts);
this.opts.restrictions = _extends({}, defaultOptions.restrictions, this.opts.restrictions);
};
this.opts = _extends({}, defaultOptions, opts);
this.opts.restrictions = _extends({}, defaultOptions.restrictions, this.opts.restrictions); // i18n
// i18n
this.translator = new Translator([this.defaultLocale, this.opts.locale]);
this.locale = this.translator.locale;
this.i18n = this.translator.translate.bind(this.translator);
this.i18nArray = this.translator.translateArray.bind(this.translator);
this.i18nArray = this.translator.translateArray.bind(this.translator); // Container for different types of plugins
// Container for different types of plugins
this.plugins = {};
this.getState = this.getState.bind(this);

@@ -125,3 +132,2 @@ this.getPlugin = this.getPlugin.bind(this);

this.resetProgress = this.resetProgress.bind(this);
this.pauseAll = this.pauseAll.bind(this);

@@ -133,3 +139,2 @@ this.resumeAll = this.resumeAll.bind(this);

this.upload = this.upload.bind(this);
this.emitter = ee();

@@ -140,7 +145,5 @@ this.on = this.on.bind(this);

this.emit = this.emitter.emit.bind(this.emitter);
this.preProcessors = [];
this.uploaders = [];
this.postProcessors = [];
this.store = this.opts.store;

@@ -165,10 +168,9 @@ this.setState({

});
this._storeUnsubscribe = this.store.subscribe(function (prevState, nextState, patch) {
_this.emit('state-update', prevState, nextState, patch);
_this.updateAll(nextState);
});
}); // for debugging and testing
// this.updateNum = 0
// for debugging and testing
// this.updateNum = 0
if (this.opts.debug && typeof window !== 'undefined') {

@@ -182,3 +184,5 @@ window['uppyLog'] = '';

Uppy.prototype.on = function on(event, callback) {
var _proto = Uppy.prototype;
_proto.on = function on(event, callback) {
this.emitter.on(event, callback);

@@ -188,7 +192,6 @@ return this;

Uppy.prototype.off = function off(event, callback) {
_proto.off = function off(event, callback) {
this.emitter.off(event, callback);
return this;
};
}
/**

@@ -199,10 +202,9 @@ * Iterate on all plugins and run `update` on them.

*/
;
Uppy.prototype.updateAll = function updateAll(state) {
_proto.updateAll = function updateAll(state) {
this.iteratePlugins(function (plugin) {
plugin.update(state);
});
};
}
/**

@@ -213,8 +215,7 @@ * Updates state with a patch

*/
;
Uppy.prototype.setState = function setState(patch) {
_proto.setState = function setState(patch) {
this.store.setState(patch);
};
}
/**

@@ -224,21 +225,20 @@ * Returns current state.

*/
;
Uppy.prototype.getState = function getState() {
_proto.getState = function getState() {
return this.store.getState();
};
}
/**
* Back compat for when uppy.state is used instead of uppy.getState().
*/
;
/**
* Shorthand to set state for a specific file.
*/
Uppy.prototype.setFileState = function setFileState(fileID, state) {
_proto.setFileState = function setFileState(fileID, state) {
var _extends2;
if (!this.getState().files[fileID]) {
throw new Error('Can\u2019t set state for ' + fileID + ' (the file could have been removed)');
throw new Error("Can\u2019t set state for " + fileID + " (the file could have been removed)");
}

@@ -251,3 +251,3 @@

Uppy.prototype.resetProgress = function resetProgress() {
_proto.resetProgress = function resetProgress() {
var defaultProgress = {

@@ -257,27 +257,29 @@ percentage: 0,

uploadComplete: false,
uploadStarted: false
uploadStarted: null
};
var files = _extends({}, this.getState().files);
var updatedFiles = {};
Object.keys(files).forEach(function (fileID) {
var updatedFile = _extends({}, files[fileID]);
updatedFile.progress = _extends({}, updatedFile.progress, defaultProgress);
updatedFiles[fileID] = updatedFile;
});
this.setState({
files: updatedFiles,
totalProgress: 0
});
}); // TODO Document on the website
// TODO Document on the website
this.emit('reset-progress');
};
Uppy.prototype.addPreProcessor = function addPreProcessor(fn) {
_proto.addPreProcessor = function addPreProcessor(fn) {
this.preProcessors.push(fn);
};
Uppy.prototype.removePreProcessor = function removePreProcessor(fn) {
_proto.removePreProcessor = function removePreProcessor(fn) {
var i = this.preProcessors.indexOf(fn);
if (i !== -1) {

@@ -288,8 +290,9 @@ this.preProcessors.splice(i, 1);

Uppy.prototype.addPostProcessor = function addPostProcessor(fn) {
_proto.addPostProcessor = function addPostProcessor(fn) {
this.postProcessors.push(fn);
};
Uppy.prototype.removePostProcessor = function removePostProcessor(fn) {
_proto.removePostProcessor = function removePostProcessor(fn) {
var i = this.postProcessors.indexOf(fn);
if (i !== -1) {

@@ -300,8 +303,9 @@ this.postProcessors.splice(i, 1);

Uppy.prototype.addUploader = function addUploader(fn) {
_proto.addUploader = function addUploader(fn) {
this.uploaders.push(fn);
};
Uppy.prototype.removeUploader = function removeUploader(fn) {
_proto.removeUploader = function removeUploader(fn) {
var i = this.uploaders.indexOf(fn);
if (i !== -1) {

@@ -312,4 +316,5 @@ this.uploaders.splice(i, 1);

Uppy.prototype.setMeta = function setMeta(data) {
_proto.setMeta = function setMeta(data) {
var updatedMeta = _extends({}, this.getState().meta, data);
var updatedFiles = _extends({}, this.getState().files);

@@ -322,6 +327,4 @@

});
this.log('Adding metadata:');
this.log(data);
this.setState({

@@ -333,4 +336,5 @@ meta: updatedMeta,

Uppy.prototype.setFileMeta = function setFileMeta(fileID, data) {
_proto.setFileMeta = function setFileMeta(fileID, data) {
var updatedFiles = _extends({}, this.getState().files);
if (!updatedFiles[fileID]) {

@@ -340,9 +344,12 @@ this.log('Was trying to set metadata for a file that’s not with us anymore: ', fileID);

}
var newMeta = _extends({}, updatedFiles[fileID].meta, data);
updatedFiles[fileID] = _extends({}, updatedFiles[fileID], {
meta: newMeta
});
this.setState({ files: updatedFiles });
};
this.setState({
files: updatedFiles
});
}
/**

@@ -353,22 +360,20 @@ * Get a file object.

*/
;
Uppy.prototype.getFile = function getFile(fileID) {
_proto.getFile = function getFile(fileID) {
return this.getState().files[fileID];
};
}
/**
* Get all files in an array.
*/
;
_proto.getFiles = function getFiles() {
var _this$getState = this.getState(),
files = _this$getState.files;
Uppy.prototype.getFiles = function getFiles() {
var _getState = this.getState(),
files = _getState.files;
return Object.keys(files).map(function (fileID) {
return files[fileID];
});
};
}
/**

@@ -379,12 +384,13 @@ * Check if minNumberOfFiles restriction is reached before uploading.

*/
;
Uppy.prototype._checkMinNumberOfFiles = function _checkMinNumberOfFiles(files) {
_proto._checkMinNumberOfFiles = function _checkMinNumberOfFiles(files) {
var minNumberOfFiles = this.opts.restrictions.minNumberOfFiles;
if (Object.keys(files).length < minNumberOfFiles) {
throw new Error('' + this.i18n('youHaveToAtLeastSelectX', { smart_count: minNumberOfFiles }));
throw new Error("" + this.i18n('youHaveToAtLeastSelectX', {
smart_count: minNumberOfFiles
}));
}
};
}
/**

@@ -397,14 +403,15 @@ * Check if file passes a set of restrictions set in options: maxFileSize,

*/
;
_proto._checkRestrictions = function _checkRestrictions(file) {
var _this$opts$restrictio = this.opts.restrictions,
maxFileSize = _this$opts$restrictio.maxFileSize,
maxNumberOfFiles = _this$opts$restrictio.maxNumberOfFiles,
allowedFileTypes = _this$opts$restrictio.allowedFileTypes;
Uppy.prototype._checkRestrictions = function _checkRestrictions(file) {
var _opts$restrictions = this.opts.restrictions,
maxFileSize = _opts$restrictions.maxFileSize,
maxNumberOfFiles = _opts$restrictions.maxNumberOfFiles,
allowedFileTypes = _opts$restrictions.allowedFileTypes;
if (maxNumberOfFiles) {
if (Object.keys(this.getState().files).length + 1 > maxNumberOfFiles) {
throw new Error('' + this.i18n('youCanOnlyUploadX', { smart_count: maxNumberOfFiles }));
throw new Error("" + this.i18n('youCanOnlyUploadX', {
smart_count: maxNumberOfFiles
}));
}

@@ -416,3 +423,2 @@ }

// if (!file.type) return false
// is this is a mime-type

@@ -422,8 +428,9 @@ if (type.indexOf('/') > -1) {

return match(file.type, type);
}
} // otherwise this is likely an extension
// otherwise this is likely an extension
if (type[0] === '.') {
return file.extension.toLowerCase() === type.substr(1).toLowerCase();
}
return false;

@@ -434,14 +441,15 @@ });

var allowedFileTypesString = allowedFileTypes.join(', ');
throw new Error(this.i18n('youCanOnlyUploadFileTypes', { types: allowedFileTypesString }));
throw new Error(this.i18n('youCanOnlyUploadFileTypes', {
types: allowedFileTypesString
}));
}
}
} // We can't check maxFileSize if the size is unknown.
// We can't check maxFileSize if the size is unknown.
if (maxFileSize && file.data.size != null) {
if (file.data.size > maxFileSize) {
throw new Error(this.i18n('exceedsSize') + ' ' + prettyBytes(maxFileSize));
throw new Error(this.i18n('exceedsSize') + " " + prettyBytes(maxFileSize));
}
}
};
}
/**

@@ -454,16 +462,19 @@ * Add a new file to `state.files`. This will run `onBeforeFileAdded`,

*/
;
Uppy.prototype.addFile = function addFile(file) {
_proto.addFile = function addFile(file) {
var _this2 = this,
_extends3;
var _getState2 = this.getState(),
files = _getState2.files,
allowNewUpload = _getState2.allowNewUpload;
var _this$getState2 = this.getState(),
files = _this$getState2.files,
allowNewUpload = _this$getState2.allowNewUpload;
var onError = function onError(msg) {
var err = (typeof msg === 'undefined' ? 'undefined' : _typeof(msg)) === 'object' ? msg : new Error(msg);
var err = typeof msg === 'object' ? msg : new Error(msg);
_this2.log(err.message);
_this2.info(err.message, 'error', 5000);
throw err;

@@ -483,3 +494,3 @@ };

if ((typeof onBeforeFileAddedResult === 'undefined' ? 'undefined' : _typeof(onBeforeFileAddedResult)) === 'object' && onBeforeFileAddedResult) {
if (typeof onBeforeFileAddedResult === 'object' && onBeforeFileAddedResult) {
// warning after the change in 0.24

@@ -489,2 +500,3 @@ if (onBeforeFileAddedResult.then) {

}
file = onBeforeFileAddedResult;

@@ -494,3 +506,4 @@ }

var fileType = getFileType(file);
var fileName = void 0;
var fileName;
if (file.name) {

@@ -503,12 +516,10 @@ fileName = file.name;

}
var fileExtension = getFileNameAndExtension(fileName).extension;
var isRemote = file.isRemote || false;
var fileID = generateFileID(file);
var meta = file.meta || {};
meta.name = fileName;
meta.type = fileType;
meta.type = fileType; // `null` means the size is unknown.
// `null` means the size is unknown.
var size = isFinite(file.data.size) ? file.data.size : null;

@@ -528,3 +539,3 @@ var newFile = {

uploadComplete: false,
uploadStarted: false
uploadStarted: null
},

@@ -547,5 +558,4 @@ size: size,

});
this.emit('file-added', newFile);
this.log('Added file: ' + fileName + ', ' + fileID + ', mime type: ' + fileType);
this.log("Added file: " + fileName + ", " + fileID + ", mime type: " + fileType);

@@ -555,2 +565,3 @@ if (this.opts.autoProceed && !this.scheduledAutoProceed) {

_this2.scheduledAutoProceed = null;
_this2.upload().catch(function (err) {

@@ -563,15 +574,16 @@ console.error(err.stack || err.message || err);

Uppy.prototype.removeFile = function removeFile(fileID) {
_proto.removeFile = function removeFile(fileID) {
var _this3 = this;
var _getState3 = this.getState(),
files = _getState3.files,
currentUploads = _getState3.currentUploads;
var _this$getState3 = this.getState(),
files = _this$getState3.files,
currentUploads = _this$getState3.currentUploads;
var updatedFiles = _extends({}, files);
var removedFile = updatedFiles[fileID];
delete updatedFiles[fileID];
delete updatedFiles[fileID]; // Remove this file from its `currentUpload`.
// Remove this file from its `currentUpload`.
var updatedUploads = _extends({}, currentUploads);
var removeUploads = [];

@@ -581,4 +593,4 @@ Object.keys(updatedUploads).forEach(function (uploadID) {

return uploadFileID !== fileID;
});
// Remove the upload if no files are associated with it anymore.
}); // Remove the upload if no files are associated with it anymore.
if (newFileIDs.length === 0) {

@@ -593,3 +605,2 @@ removeUploads.push(uploadID);

});
this.setState({

@@ -599,3 +610,2 @@ currentUploads: updatedUploads,

});
removeUploads.forEach(function (uploadID) {

@@ -606,7 +616,8 @@ _this3._removeUpload(uploadID);

this._calculateTotalProgress();
this.emit('file-removed', removedFile);
this.log('File removed: ' + removedFile.id);
this.log("File removed: " + removedFile.id);
};
Uppy.prototype.pauseResume = function pauseResume(fileID) {
_proto.pauseResume = function pauseResume(fileID) {
if (!this.getState().capabilities.resumableUploads || this.getFile(fileID).uploadComplete) {

@@ -618,18 +629,15 @@ return;

var isPaused = !wasPaused;
this.setFileState(fileID, {
isPaused: isPaused
});
this.emit('upload-pause', fileID, isPaused);
return isPaused;
};
Uppy.prototype.pauseAll = function pauseAll() {
_proto.pauseAll = function pauseAll() {
var updatedFiles = _extends({}, this.getState().files);
var inProgressUpdatedFiles = Object.keys(updatedFiles).filter(function (file) {
return !updatedFiles[file].progress.uploadComplete && updatedFiles[file].progress.uploadStarted;
});
inProgressUpdatedFiles.forEach(function (file) {

@@ -639,15 +647,17 @@ var updatedFile = _extends({}, updatedFiles[file], {

});
updatedFiles[file] = updatedFile;
});
this.setState({ files: updatedFiles });
this.setState({
files: updatedFiles
});
this.emit('pause-all');
};
Uppy.prototype.resumeAll = function resumeAll() {
_proto.resumeAll = function resumeAll() {
var updatedFiles = _extends({}, this.getState().files);
var inProgressUpdatedFiles = Object.keys(updatedFiles).filter(function (file) {
return !updatedFiles[file].progress.uploadComplete && updatedFiles[file].progress.uploadStarted;
});
inProgressUpdatedFiles.forEach(function (file) {

@@ -658,15 +668,17 @@ var updatedFile = _extends({}, updatedFiles[file], {

});
updatedFiles[file] = updatedFile;
});
this.setState({ files: updatedFiles });
this.setState({
files: updatedFiles
});
this.emit('resume-all');
};
Uppy.prototype.retryAll = function retryAll() {
_proto.retryAll = function retryAll() {
var updatedFiles = _extends({}, this.getState().files);
var filesToRetry = Object.keys(updatedFiles).filter(function (file) {
return updatedFiles[file].error;
});
filesToRetry.forEach(function (file) {

@@ -677,2 +689,3 @@ var updatedFile = _extends({}, updatedFiles[file], {

});
updatedFiles[file] = updatedFile;

@@ -684,14 +697,13 @@ });

});
this.emit('retry-all', filesToRetry);
var uploadID = this._createUpload(filesToRetry);
return this._runUpload(uploadID);
};
Uppy.prototype.cancelAll = function cancelAll() {
_proto.cancelAll = function cancelAll() {
var _this4 = this;
this.emit('cancel-all');
var files = Object.keys(this.getState().files);

@@ -701,3 +713,2 @@ files.forEach(function (fileID) {

});
this.setState({

@@ -710,5 +721,10 @@ allowNewUpload: true,

Uppy.prototype.retryUpload = function retryUpload(fileID) {
_proto.retryUpload = function retryUpload(fileID) {
var updatedFiles = _extends({}, this.getState().files);
var updatedFile = _extends({}, updatedFiles[fileID], { error: null, isPaused: false });
var updatedFile = _extends({}, updatedFiles[fileID], {
error: null,
isPaused: false
});
updatedFiles[fileID] = updatedFile;

@@ -718,20 +734,20 @@ this.setState({

});
this.emit('upload-retry', fileID);
var uploadID = this._createUpload([fileID]);
return this._runUpload(uploadID);
};
Uppy.prototype.reset = function reset() {
_proto.reset = function reset() {
this.cancelAll();
};
Uppy.prototype._calculateProgress = function _calculateProgress(file, data) {
_proto._calculateProgress = function _calculateProgress(file, data) {
if (!this.getFile(file.id)) {
this.log('Not setting progress for a file that has been removed: ' + file.id);
this.log("Not setting progress for a file that has been removed: " + file.id);
return;
}
} // bytesTotal may be null or zero; in that case we can't divide by it
// bytesTotal may be null or zero; in that case we can't divide by it
var canHavePercentage = isFinite(data.bytesTotal) && data.bytesTotal > 0;

@@ -742,4 +758,3 @@ this.setFileState(file.id, {

bytesTotal: data.bytesTotal,
percentage: canHavePercentage
// TODO(goto-bus-stop) flooring this should probably be the choice of the UI?
percentage: canHavePercentage // TODO(goto-bus-stop) flooring this should probably be the choice of the UI?
// we get more accurate calculations if we don't round this at all.

@@ -753,7 +768,6 @@ ? Math.floor(data.bytesUploaded / data.bytesTotal * 100) : 0

Uppy.prototype._calculateTotalProgress = function _calculateTotalProgress() {
_proto._calculateTotalProgress = function _calculateTotalProgress() {
// calculate total progress, using the number of files currently uploading,
// multiplied by 100 and the summ of individual progress of each file
var files = this.getFiles();
var inProgress = files.filter(function (file) {

@@ -765,3 +779,5 @@ return file.progress.uploadStarted;

this.emit('progress', 0);
this.setState({ totalProgress: 0 });
this.setState({
totalProgress: 0
});
return;

@@ -782,4 +798,8 @@ }

}, 0);
var _totalProgress = Math.round(currentProgress / progressMax * 100);
this.setState({ totalProgress: _totalProgress });
this.setState({
totalProgress: _totalProgress
});
return;

@@ -793,3 +813,2 @@ }

totalSize += averageSize * unsizedFiles.length;
var uploadedSize = 0;

@@ -802,7 +821,5 @@ sizedFiles.forEach(function (file) {

});
var totalProgress = totalSize === 0 ? 0 : Math.round(uploadedSize / totalSize * 100); // hot fix, because:
// uploadedSize ended up larger than totalSize, resulting in 1325% total
var totalProgress = totalSize === 0 ? 0 : Math.round(uploadedSize / totalSize * 100);
// hot fix, because:
// uploadedSize ended up larger than totalSize, resulting in 1325% total
if (totalProgress > 100) {

@@ -812,6 +829,7 @@ totalProgress = 100;

this.setState({ totalProgress: totalProgress });
this.setState({
totalProgress: totalProgress
});
this.emit('progress', totalProgress);
};
}
/**

@@ -821,11 +839,12 @@ * Registers listeners for all global actions, like:

*/
;
Uppy.prototype._addListeners = function _addListeners() {
_proto._addListeners = function _addListeners() {
var _this5 = this;
this.on('error', function (error) {
_this5.setState({ error: error.message });
_this5.setState({
error: error.message
});
});
this.on('upload-error', function (file, error, response) {

@@ -837,20 +856,31 @@ _this5.setFileState(file.id, {

_this5.setState({ error: error.message });
_this5.setState({
error: error.message
});
var message = _this5.i18n('failedToUpload', { file: file.name });
if ((typeof error === 'undefined' ? 'undefined' : _typeof(error)) === 'object' && error.message) {
message = { message: message, details: error.message };
var message = _this5.i18n('failedToUpload', {
file: file.name
});
if (typeof error === 'object' && error.message) {
message = {
message: message,
details: error.message
};
}
_this5.info(message, 'error', 5000);
});
this.on('upload', function () {
_this5.setState({ error: null });
_this5.setState({
error: null
});
});
this.on('upload-started', function (file, upload) {
if (!_this5.getFile(file.id)) {
_this5.log('Not setting progress for a file that has been removed: ' + file.id);
_this5.log("Not setting progress for a file that has been removed: " + file.id);
return;
}
_this5.setFileState(file.id, {

@@ -865,5 +895,3 @@ progress: {

});
});
// upload progress events can occur frequently, especially when you have a good
}); // upload progress events can occur frequently, especially when you have a good
// connection to the remote server. Therefore, we are throtteling them to

@@ -875,5 +903,5 @@ // prevent accessive function calls.

this.on('upload-progress', this._calculateProgress);
this.on('upload-success', function (file, uploadResp) {
var currentProgress = _this5.getFile(file.id).progress;
_this5.setFileState(file.id, {

@@ -892,8 +920,9 @@ progress: _extends({}, currentProgress, {

});
this.on('preprocess-progress', function (file, progress) {
if (!_this5.getFile(file.id)) {
_this5.log('Not setting progress for a file that has been removed: ' + file.id);
_this5.log("Not setting progress for a file that has been removed: " + file.id);
return;
}
_this5.setFileState(file.id, {

@@ -905,9 +934,11 @@ progress: _extends({}, _this5.getFile(file.id).progress, {

});
this.on('preprocess-complete', function (file) {
if (!_this5.getFile(file.id)) {
_this5.log('Not setting progress for a file that has been removed: ' + file.id);
_this5.log("Not setting progress for a file that has been removed: " + file.id);
return;
}
var files = _extends({}, _this5.getState().files);
files[file.id] = _extends({}, files[file.id], {

@@ -918,10 +949,13 @@ progress: _extends({}, files[file.id].progress)

_this5.setState({ files: files });
_this5.setState({
files: files
});
});
this.on('postprocess-progress', function (file, progress) {
if (!_this5.getFile(file.id)) {
_this5.log('Not setting progress for a file that has been removed: ' + file.id);
_this5.log("Not setting progress for a file that has been removed: " + file.id);
return;
}
_this5.setFileState(file.id, {

@@ -933,26 +967,27 @@ progress: _extends({}, _this5.getState().files[file.id].progress, {

});
this.on('postprocess-complete', function (file) {
if (!_this5.getFile(file.id)) {
_this5.log('Not setting progress for a file that has been removed: ' + file.id);
_this5.log("Not setting progress for a file that has been removed: " + file.id);
return;
}
var files = _extends({}, _this5.getState().files);
files[file.id] = _extends({}, files[file.id], {
progress: _extends({}, files[file.id].progress)
});
delete files[file.id].progress.postprocess;
// TODO should we set some kind of `fullyComplete` property on the file object
delete files[file.id].progress.postprocess; // TODO should we set some kind of `fullyComplete` property on the file object
// so it's easier to see that the file is upload…fully complete…rather than
// what we have to do now (`uploadComplete && !postprocess`)
_this5.setState({ files: files });
_this5.setState({
files: files
});
});
this.on('restored', function () {
// Files may have changed--ensure progress is still accurate.
_this5._calculateTotalProgress();
});
}); // show informer if offline
// show informer if offline
if (typeof window !== 'undefined' && window.addEventListener) {

@@ -971,4 +1006,5 @@ window.addEventListener('online', function () {

Uppy.prototype.updateOnlineStatus = function updateOnlineStatus() {
_proto.updateOnlineStatus = function updateOnlineStatus() {
var online = typeof window.navigator.onLine !== 'undefined' ? window.navigator.onLine : true;
if (!online) {

@@ -980,2 +1016,3 @@ this.emit('is-offline');

this.emit('is-online');
if (this.wasOffline) {

@@ -989,6 +1026,5 @@ this.emit('back-online');

Uppy.prototype.getID = function getID() {
_proto.getID = function getID() {
return this.opts.id;
};
}
/**

@@ -1001,11 +1037,11 @@ * Registers a plugin with Core.

*/
;
Uppy.prototype.use = function use(Plugin, opts) {
_proto.use = function use(Plugin, opts) {
if (typeof Plugin !== 'function') {
var msg = 'Expected a plugin class, but got ' + (Plugin === null ? 'null' : typeof Plugin === 'undefined' ? 'undefined' : _typeof(Plugin)) + '.' + ' Please verify that the plugin was imported and spelled correctly.';
var msg = "Expected a plugin class, but got " + (Plugin === null ? 'null' : typeof Plugin) + "." + ' Please verify that the plugin was imported and spelled correctly.';
throw new TypeError(msg);
}
} // Instantiate
// Instantiate
var plugin = new Plugin(this, opts);

@@ -1024,4 +1060,6 @@ var pluginId = plugin.id;

var existsPluginAlready = this.getPlugin(pluginId);
if (existsPluginAlready) {
var _msg = 'Already found a plugin named \'' + existsPluginAlready.id + '\'. ' + ('Tried to use: \'' + pluginId + '\'.\n') + 'Uppy plugins must have unique \'id\' options. See https://uppy.io/docs/plugins/#id.';
var _msg = "Already found a plugin named '" + existsPluginAlready.id + "'. " + ("Tried to use: '" + pluginId + "'.\n") + "Uppy plugins must have unique 'id' options. See https://uppy.io/docs/plugins/#id.";
throw new Error(_msg);

@@ -1032,6 +1070,4 @@ }

plugin.install();
return this;
};
}
/**

@@ -1043,5 +1079,5 @@ * Find one Plugin by name.

*/
;
Uppy.prototype.getPlugin = function getPlugin(id) {
_proto.getPlugin = function getPlugin(id) {
var foundPlugin = null;

@@ -1055,4 +1091,3 @@ this.iteratePlugins(function (plugin) {

return foundPlugin;
};
}
/**

@@ -1063,5 +1098,5 @@ * Iterate through all `use`d plugins.

*/
;
Uppy.prototype.iteratePlugins = function iteratePlugins(method) {
_proto.iteratePlugins = function iteratePlugins(method) {
var _this6 = this;

@@ -1072,4 +1107,3 @@

});
};
}
/**

@@ -1080,6 +1114,6 @@ * Uninstall and remove a plugin.

*/
;
Uppy.prototype.removePlugin = function removePlugin(instance) {
this.log('Removing plugin ' + instance.id);
_proto.removePlugin = function removePlugin(instance) {
this.log("Removing plugin " + instance.id);
this.emit('plugin-remove', instance);

@@ -1093,2 +1127,3 @@

var index = list.indexOf(instance);
if (index !== -1) {

@@ -1102,14 +1137,12 @@ list.splice(index, 1);

this.setState(updatedState);
};
}
/**
* Uninstall all plugins and close down this Uppy instance.
*/
;
Uppy.prototype.close = function close() {
_proto.close = function close() {
var _this7 = this;
this.log('Closing Uppy instance ' + this.opts.id + ': removing all files and uninstalling plugins');
this.log("Closing Uppy instance " + this.opts.id + ": removing all files and uninstalling plugins");
this.reset();

@@ -1122,4 +1155,3 @@

});
};
}
/**

@@ -1133,9 +1165,14 @@ * Set info message in `state.info`, so that UI plugins like `Informer`

*/
;
Uppy.prototype.info = function info(message) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'info';
var duration = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 3000;
_proto.info = function info(message, type, duration) {
if (type === void 0) {
type = 'info';
}
var isComplexMessage = (typeof message === 'undefined' ? 'undefined' : _typeof(message)) === 'object';
if (duration === void 0) {
duration = 3000;
}
var isComplexMessage = typeof message === 'object';
this.setState({

@@ -1149,19 +1186,19 @@ info: {

});
this.emit('info-visible');
clearTimeout(this.infoTimeoutID);
clearTimeout(this.infoTimeoutID);
if (duration === 0) {
this.infoTimeoutID = undefined;
return;
}
} // hide the informer after `duration` milliseconds
// hide the informer after `duration` milliseconds
this.infoTimeoutID = setTimeout(this.hideInfo, duration);
};
Uppy.prototype.hideInfo = function hideInfo() {
_proto.hideInfo = function hideInfo() {
var newInfo = _extends({}, this.getState().info, {
isHidden: true
});
this.setState({

@@ -1171,4 +1208,3 @@ info: newInfo

this.emit('info-hidden');
};
}
/**

@@ -1180,5 +1216,5 @@ * Logs stuff to console, only if `debug` is set to true. Silent in production.

*/
;
Uppy.prototype.log = function log(message, type) {
_proto.log = function log(message, type) {
if (!this.opts.debug) {

@@ -1188,3 +1224,3 @@ return;

var prefix = '[Uppy] [' + getTimeStamp() + ']';
var prefix = "[Uppy] [" + getTimeStamp() + "]";

@@ -1202,24 +1238,23 @@ if (type === 'error') {

console.log(prefix, message);
};
}
/**
* Obsolete, event listeners are now added in the constructor.
*/
;
Uppy.prototype.run = function run() {
_proto.run = function run() {
this.log('Calling run() is no longer necessary.', 'warning');
return this;
};
}
/**
* Restore an upload by its ID.
*/
;
_proto.restore = function restore(uploadID) {
this.log("Core: attempting to restore upload \"" + uploadID + "\"");
Uppy.prototype.restore = function restore(uploadID) {
this.log('Core: attempting to restore upload "' + uploadID + '"');
if (!this.getState().currentUploads[uploadID]) {
this._removeUpload(uploadID);
return Promise.reject(new Error('Nonexistent upload'));

@@ -1229,4 +1264,3 @@ }

return this._runUpload(uploadID);
};
}
/**

@@ -1238,10 +1272,10 @@ * Create an upload for a bunch of files.

*/
;
Uppy.prototype._createUpload = function _createUpload(fileIDs) {
_proto._createUpload = function _createUpload(fileIDs) {
var _extends4;
var _getState4 = this.getState(),
allowNewUpload = _getState4.allowNewUpload,
currentUploads = _getState4.currentUploads;
var _this$getState4 = this.getState(),
allowNewUpload = _this$getState4.allowNewUpload,
currentUploads = _this$getState4.currentUploads;

@@ -1253,3 +1287,2 @@ if (!allowNewUpload) {

var uploadID = cuid();
this.emit('upload', {

@@ -1259,6 +1292,4 @@ id: uploadID,

});
this.setState({
allowNewUpload: this.opts.allowMultipleUploads !== false,
currentUploads: _extends({}, currentUploads, (_extends4 = {}, _extends4[uploadID] = {

@@ -1270,13 +1301,11 @@ fileIDs: fileIDs,

});
return uploadID;
};
Uppy.prototype._getUpload = function _getUpload(uploadID) {
var _getState5 = this.getState(),
currentUploads = _getState5.currentUploads;
_proto._getUpload = function _getUpload(uploadID) {
var _this$getState5 = this.getState(),
currentUploads = _this$getState5.currentUploads;
return currentUploads[uploadID];
};
}
/**

@@ -1288,20 +1317,22 @@ * Add data to an upload's result object.

*/
;
Uppy.prototype.addResultData = function addResultData(uploadID, data) {
_proto.addResultData = function addResultData(uploadID, data) {
var _extends5;
if (!this._getUpload(uploadID)) {
this.log('Not setting result for an upload that has been removed: ' + uploadID);
this.log("Not setting result for an upload that has been removed: " + uploadID);
return;
}
var currentUploads = this.getState().currentUploads;
var currentUpload = _extends({}, currentUploads[uploadID], {
result: _extends({}, currentUploads[uploadID].result, data)
});
this.setState({
currentUploads: _extends({}, currentUploads, (_extends5 = {}, _extends5[uploadID] = currentUpload, _extends5))
});
};
}
/**

@@ -1312,13 +1343,12 @@ * Remove an upload, eg. if it has been canceled or completed.

*/
;
_proto._removeUpload = function _removeUpload(uploadID) {
var currentUploads = _extends({}, this.getState().currentUploads);
Uppy.prototype._removeUpload = function _removeUpload(uploadID) {
var currentUploads = _extends({}, this.getState().currentUploads);
delete currentUploads[uploadID];
this.setState({
currentUploads: currentUploads
});
};
}
/**

@@ -1329,5 +1359,5 @@ * Run an upload. This picks up where it left off in case the upload is being restored.

*/
;
Uppy.prototype._runUpload = function _runUpload(uploadID) {
_proto._runUpload = function _runUpload(uploadID) {
var _this8 = this;

@@ -1337,3 +1367,2 @@

var restoreStep = uploadData.step;
var steps = [].concat(this.preProcessors, this.uploaders, this.postProcessors);

@@ -1350,4 +1379,4 @@ var lastStep = Promise.resolve();

var _getState6 = _this8.getState(),
currentUploads = _getState6.currentUploads;
var _this8$getState = _this8.getState(),
currentUploads = _this8$getState.currentUploads;

@@ -1357,8 +1386,9 @@ var currentUpload = _extends({}, currentUploads[uploadID], {

});
_this8.setState({
currentUploads: _extends({}, currentUploads, (_extends6 = {}, _extends6[uploadID] = currentUpload, _extends6))
});
}); // TODO give this the `currentUpload` object as its only parameter maybe?
// Otherwise when more metadata may be added to the upload this would keep getting more parameters
// TODO give this the `currentUpload` object as its only parameter maybe?
// Otherwise when more metadata may be added to the upload this would keep getting more parameters
return fn(currentUpload.fileIDs, uploadID);

@@ -1368,17 +1398,17 @@ }).then(function (result) {

});
});
}); // Not returning the `catch`ed promise, because we still want to return a rejected
// promise from this method if the upload failed.
// Not returning the `catch`ed promise, because we still want to return a rejected
// promise from this method if the upload failed.
lastStep.catch(function (err) {
_this8.emit('error', err, uploadID);
_this8._removeUpload(uploadID);
});
return lastStep.then(function () {
// Set result data.
var _getState7 = _this8.getState(),
currentUploads = _getState7.currentUploads;
var _this8$getState2 = _this8.getState(),
currentUploads = _this8$getState2.currentUploads;
var currentUpload = currentUploads[uploadID];
if (!currentUpload) {

@@ -1397,3 +1427,8 @@ return;

});
_this8.addResultData(uploadID, { successful: successful, failed: failed, uploadID: uploadID });
_this8.addResultData(uploadID, {
successful: successful,
failed: failed,
uploadID: uploadID
});
}).then(function () {

@@ -1404,4 +1439,4 @@ // Emit completion events.

// to an outdated object without the `.result` property.
var _getState8 = _this8.getState(),
currentUploads = _getState8.currentUploads;
var _this8$getState3 = _this8.getState(),
currentUploads = _this8$getState3.currentUploads;

@@ -1411,4 +1446,6 @@ if (!currentUploads[uploadID]) {

}
var currentUpload = currentUploads[uploadID];
var result = currentUpload.result;
_this8.emit('complete', result);

@@ -1421,8 +1458,8 @@

if (result == null) {
_this8.log('Not setting result for an upload that has been removed: ' + uploadID);
_this8.log("Not setting result for an upload that has been removed: " + uploadID);
}
return result;
});
};
}
/**

@@ -1433,5 +1470,5 @@ * Start an upload for all the files that are not currently being uploaded.

*/
;
Uppy.prototype.upload = function upload() {
_proto.upload = function upload() {
var _this9 = this;

@@ -1450,3 +1487,3 @@

if (onBeforeUploadResult && (typeof onBeforeUploadResult === 'undefined' ? 'undefined' : _typeof(onBeforeUploadResult)) === 'object') {
if (onBeforeUploadResult && typeof onBeforeUploadResult === 'object') {
// warning after the change in 0.24

@@ -1463,5 +1500,4 @@ if (onBeforeUploadResult.then) {

}).then(function () {
var _getState9 = _this9.getState(),
currentUploads = _getState9.currentUploads;
// get a list of files that are currently assigned to uploads
var _this9$getState = _this9.getState(),
currentUploads = _this9$getState.currentUploads; // get a list of files that are currently assigned to uploads

@@ -1472,7 +1508,7 @@

}, []);
var waitingFileIDs = [];
Object.keys(files).forEach(function (fileID) {
var file = _this9.getFile(fileID);
// if the file hasn't started uploading and hasn't already been assigned to an upload..
var file = _this9.getFile(fileID); // if the file hasn't started uploading and hasn't already been assigned to an upload..
if (!file.progress.uploadStarted && currentlyUploadingFiles.indexOf(fileID) === -1) {

@@ -1484,9 +1520,16 @@ waitingFileIDs.push(file.id);

var uploadID = _this9._createUpload(waitingFileIDs);
return _this9._runUpload(uploadID);
}).catch(function (err) {
var message = (typeof err === 'undefined' ? 'undefined' : _typeof(err)) === 'object' ? err.message : err;
var details = (typeof err === 'undefined' ? 'undefined' : _typeof(err)) === 'object' ? err.details : null;
_this9.log(message + ' ' + details);
_this9.info({ message: message, details: details }, 'error', 4000);
return Promise.reject((typeof err === 'undefined' ? 'undefined' : _typeof(err)) === 'object' ? err : new Error(err));
var message = typeof err === 'object' ? err.message : err;
var details = typeof err === 'object' ? err.details : null;
_this9.log(message + " " + details);
_this9.info({
message: message,
details: details
}, 'error', 4000);
return Promise.reject(typeof err === 'object' ? err : new Error(err));
});

@@ -1496,3 +1539,3 @@ };

_createClass(Uppy, [{
key: 'state',
key: "state",
get: function get() {

@@ -1506,8 +1549,10 @@ return this.getState();

Uppy.VERSION = "1.1.0";
module.exports = function (opts) {
return new Uppy(opts);
};
}; // Expose class constructor.
// Expose class constructor.
module.exports.Uppy = Uppy;
module.exports.Plugin = Plugin;

@@ -1,13 +0,11 @@

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var preact = require('preact');
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var preact = require('preact');
var findDOMElement = require('@uppy/utils/lib/findDOMElement');
/**
* Defer a frequent call to the microtask queue.
*/
function debounce(fn) {

@@ -17,3 +15,3 @@ var calling = null;

return function () {
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];

@@ -23,16 +21,17 @@ }

latestArgs = args;
if (!calling) {
calling = Promise.resolve().then(function () {
calling = null;
// At this point `args` may be different from the most
calling = null; // At this point `args` may be different from the most
// recent state, if multiple calls happened since this task
// was queued. So we use the `latestArgs`, which definitely
// is the most recent call.
return fn.apply(undefined, latestArgs);
return fn.apply(void 0, latestArgs);
});
}
return calling;
};
}
/**

@@ -47,9 +46,10 @@ * Boilerplate that all Plugins share - and should not be used

*/
module.exports = function () {
module.exports =
/*#__PURE__*/
function () {
function Plugin(uppy, opts) {
_classCallCheck(this, Plugin);
this.uppy = uppy;
this.opts = opts || {};
this.update = this.update.bind(this);

@@ -61,14 +61,16 @@ this.mount = this.mount.bind(this);

Plugin.prototype.getPluginState = function getPluginState() {
var _uppy$getState = this.uppy.getState(),
plugins = _uppy$getState.plugins;
var _proto = Plugin.prototype;
_proto.getPluginState = function getPluginState() {
var _this$uppy$getState = this.uppy.getState(),
plugins = _this$uppy$getState.plugins;
return plugins[this.id] || {};
};
Plugin.prototype.setPluginState = function setPluginState(update) {
_proto.setPluginState = function setPluginState(update) {
var _extends2;
var _uppy$getState2 = this.uppy.getState(),
plugins = _uppy$getState2.plugins;
var _this$uppy$getState2 = this.uppy.getState(),
plugins = _this$uppy$getState2.plugins;

@@ -80,3 +82,3 @@ this.uppy.setState({

Plugin.prototype.update = function update(state) {
_proto.update = function update(state) {
if (typeof this.el === 'undefined') {

@@ -89,4 +91,3 @@ return;

}
};
}
/**

@@ -98,6 +99,5 @@ * Called when plugin is mounted, whether in DOM or into another plugin.

*/
;
Plugin.prototype.onMount = function onMount() {};
_proto.onMount = function onMount() {}
/**

@@ -111,15 +111,13 @@ * Check if supplied `target` is a DOM element or an `object`.

*/
;
Plugin.prototype.mount = function mount(target, plugin) {
_proto.mount = function mount(target, plugin) {
var _this = this;
var callerPluginName = plugin.id;
var targetElement = findDOMElement(target);
if (targetElement) {
this.isTargetDOMEl = true;
this.isTargetDOMEl = true; // API for plugins that require a synchronous rerender.
// API for plugins that require a synchronous rerender.
this.rerender = function (state) {

@@ -132,7 +130,6 @@ // plugin could be removed, but this.rerender is debounced below,

};
this._updateUI = debounce(this.rerender);
this.uppy.log("Installing " + callerPluginName + " to a DOM element"); // clear everything inside the target container
this.uppy.log('Installing ' + callerPluginName + ' to a DOM element');
// clear everything inside the target container
if (this.opts.replaceTargetContent) {

@@ -143,3 +140,2 @@ targetElement.innerHTML = '';

this.el = preact.render(this.render(this.uppy.getState()), targetElement);
this.onMount();

@@ -149,4 +145,5 @@ return this.el;

var targetPlugin = void 0;
if ((typeof target === 'undefined' ? 'undefined' : _typeof(target)) === 'object' && target instanceof Plugin) {
var targetPlugin;
if (typeof target === 'object' && target instanceof Plugin) {
// Targeting a plugin *instance*

@@ -156,4 +153,4 @@ targetPlugin = target;

// Targeting a plugin type
var Target = target;
// Find the target plugin instance.
var Target = target; // Find the target plugin instance.
this.uppy.iteratePlugins(function (plugin) {

@@ -168,6 +165,5 @@ if (plugin instanceof Target) {

if (targetPlugin) {
this.uppy.log('Installing ' + callerPluginName + ' to ' + targetPlugin.id);
this.uppy.log("Installing " + callerPluginName + " to " + targetPlugin.id);
this.parent = targetPlugin;
this.el = targetPlugin.addTarget(plugin);
this.onMount();

@@ -177,15 +173,15 @@ return this.el;

this.uppy.log('Not installing ' + callerPluginName);
throw new Error('Invalid target option given to ' + callerPluginName + '. Please make sure that the element \n exists on the page, or that the plugin you are targeting has been installed. Check that the <script> tag initializing Uppy \n comes at the bottom of the page, before the closing </body> tag (see https://github.com/transloadit/uppy/issues/1042).');
this.uppy.log("Not installing " + callerPluginName);
throw new Error("Invalid target option given to " + callerPluginName + ". Please make sure that the element \n exists on the page, or that the plugin you are targeting has been installed. Check that the <script> tag initializing Uppy \n comes at the bottom of the page, before the closing </body> tag (see https://github.com/transloadit/uppy/issues/1042).");
};
Plugin.prototype.render = function render(state) {
_proto.render = function render(state) {
throw new Error('Extend the render method to add your plugin to a DOM element');
};
Plugin.prototype.addTarget = function addTarget(plugin) {
_proto.addTarget = function addTarget(plugin) {
throw new Error('Extend the addTarget method to add your plugin to another plugin\'s target');
};
Plugin.prototype.unmount = function unmount() {
_proto.unmount = function unmount() {
if (this.isTargetDOMEl && this.el && this.el.parentNode) {

@@ -196,5 +192,5 @@ this.el.parentNode.removeChild(this.el);

Plugin.prototype.install = function install() {};
_proto.install = function install() {};
Plugin.prototype.uninstall = function uninstall() {
_proto.uninstall = function uninstall() {
this.unmount();

@@ -201,0 +197,0 @@ };

@@ -8,9 +8,8 @@ // Edge 15.x does not fire 'progress' events on uploads.

userAgent = typeof navigator !== 'undefined' ? navigator.userAgent : null;
}
// Assume it works because basically everything supports progress events.
} // Assume it works because basically everything supports progress events.
if (!userAgent) return true;
var m = /Edge\/(\d+\.\d+)/.exec(userAgent);
if (!m) return true;
var edgeVersion = m[1];

@@ -23,19 +22,18 @@

major = parseInt(major, 10);
minor = parseInt(minor, 10);
// Worked before:
minor = parseInt(minor, 10); // Worked before:
// Edge 40.15063.0.0
// Microsoft EdgeHTML 15.15063
if (major < 15 || major === 15 && minor < 15063) {
return true;
}
} // Fixed in:
// Microsoft EdgeHTML 18.18218
// Fixed in:
// Microsoft EdgeHTML 18.18218
if (major > 18 || major === 18 && minor >= 18218) {
return true;
}
} // other versions don't work.
// other versions don't work.
return false;
};
{
"name": "@uppy/core",
"description": "Core module for the extensible JavaScript file upload widget with support for drag&drop, resumable uploads, previews, restrictions, file processing/encoding, remote providers like Instagram, Dropbox, Google Drive, S3 and more :dog:",
"version": "1.0.2",
"version": "1.1.0",
"license": "MIT",

@@ -23,4 +23,4 @@ "main": "lib/index.js",

"dependencies": {
"@uppy/store-default": "0.28.3",
"@uppy/utils": "1.0.2",
"@uppy/store-default": "1.1.0",
"@uppy/utils": "1.1.0",
"cuid": "^2.1.1",

@@ -33,3 +33,3 @@ "lodash.throttle": "^4.1.1",

},
"gitHead": "5c9e1a836df858254657a59ab8bd4b90035cf8b4"
"gitHead": "28d235fe2fb57d87a399c20883fd6590aa49f4f4"
}

@@ -21,2 +21,4 @@ const Translator = require('@uppy/utils/lib/Translator')

class Uppy {
static VERSION = require('../package.json').version
/**

@@ -225,3 +227,3 @@ * Instantiate Uppy

uploadComplete: false,
uploadStarted: false
uploadStarted: null
}

@@ -307,3 +309,3 @@ const files = Object.assign({}, this.getState().files)

})
this.setState({files: updatedFiles})
this.setState({ files: updatedFiles })
}

@@ -334,3 +336,3 @@

_checkMinNumberOfFiles (files) {
const {minNumberOfFiles} = this.opts.restrictions
const { minNumberOfFiles } = this.opts.restrictions
if (Object.keys(files).length < minNumberOfFiles) {

@@ -349,3 +351,3 @@ throw new Error(`${this.i18n('youHaveToAtLeastSelectX', { smart_count: minNumberOfFiles })}`)

_checkRestrictions (file) {
const {maxFileSize, maxNumberOfFiles, allowedFileTypes} = this.opts.restrictions
const { maxFileSize, maxNumberOfFiles, allowedFileTypes } = this.opts.restrictions

@@ -458,3 +460,3 @@ if (maxNumberOfFiles) {

uploadComplete: false,
uploadStarted: false
uploadStarted: null
},

@@ -560,3 +562,3 @@ size: size,

})
this.setState({files: updatedFiles})
this.setState({ files: updatedFiles })

@@ -580,3 +582,3 @@ this.emit('pause-all')

})
this.setState({files: updatedFiles})
this.setState({ files: updatedFiles })

@@ -583,0 +585,0 @@ this.emit('resume-all')

@@ -415,3 +415,3 @@ const fs = require('fs')

uploadComplete: false,
uploadStarted: false,
uploadStarted: null,
preprocess: { mode: 'determinate', message: 'something', value: 0 }

@@ -443,3 +443,3 @@ })

uploadComplete: false,
uploadStarted: false
uploadStarted: null
})

@@ -524,3 +524,3 @@ })

uploadComplete: false,
uploadStarted: false,
uploadStarted: null,
postprocess: { mode: 'determinate', message: 'something', value: 0 }

@@ -552,3 +552,3 @@ })

uploadComplete: false,
uploadStarted: false
uploadStarted: null
})

@@ -626,3 +626,3 @@ })

uploadComplete: false,
uploadStarted: false
uploadStarted: null
},

@@ -999,3 +999,3 @@ remote: '',

uploadComplete: false,
uploadStarted: false
uploadStarted: null
})

@@ -1012,3 +1012,3 @@

uploadComplete: false,
uploadStarted: false
uploadStarted: null
})

@@ -1156,3 +1156,3 @@ })

uploadComplete: false,
uploadStarted: false
uploadStarted: null
})

@@ -1164,3 +1164,3 @@ expect(core.getFile(file2.id).progress).toEqual({

uploadComplete: false,
uploadStarted: false
uploadStarted: null
})

@@ -1315,3 +1315,8 @@ expect(core.getState().totalProgress).toEqual(0)

core.emit('upload-error', core.getFile('fileId'), new Error('this is the error'))
expect(core.getState().info).toEqual({'message': 'Failed to upload filename', 'details': 'this is the error', 'isHidden': false, 'type': 'error'})
expect(core.getState().info).toEqual({
message: 'Failed to upload filename',
details: 'this is the error',
isHidden: false,
type: 'error'
})
})

@@ -1318,0 +1323,0 @@

import Uppy = require('../');
import DefaultStore = require('@uppy/store-default');

@@ -14,1 +15,15 @@ {

}
{
const store = DefaultStore();
const uppy = Uppy({ store });
}
{
const uppy = Uppy()
// this doesn't exist but type checking works anyway :)
const f = uppy.getFile('virtual')
if (f && f.progress && f.progress.uploadStarted === null) {
f.progress.uploadStarted = Date.now()
}
}

@@ -0,2 +1,8 @@

import UppyUtils = require('@uppy/utils');
declare module Uppy {
// These are defined in @uppy/utils instead of core so it can be used there without creating import cycles
export type UppyFile<TMeta extends IndexedObject<any> = {}> = UppyUtils.UppyFile<TMeta>;
export type Store = UppyUtils.Store;
interface IndexedObject<T> {

@@ -6,30 +12,2 @@ [key: string]: T;

}
interface UppyFile<TMeta extends IndexedObject<any> = {}> {
data: Blob | File;
extension: string;
id: string;
isPaused?: boolean;
isRemote: boolean;
meta: {
name: string;
type?: string;
} & TMeta;
name: string;
preview?: string;
progress?: {
uploadStarted: number;
uploadComplete: boolean;
percentage: number;
bytesUploaded: number;
bytesTotal: number;
};
remote?: {
host: string;
url: string;
body?: object;
};
size: number;
source?: string;
type?: string;
}

@@ -69,8 +47,2 @@ interface UploadedUppyFile<TMeta extends IndexedObject<any> = {}> extends UppyFile<TMeta> {

interface Store {
getState(): object;
setState(patch: object): void;
subscribe(listener: any): () => void;
}
interface LocaleStrings {

@@ -77,0 +49,0 @@ [key: string]: string | LocaleStrings;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc