From 2645e2926f39739ed32a2fb0d81df889ca87cd09 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Thu, 1 Feb 2018 01:09:00 -0500 Subject: [PATCH 01/87] Fix Safari image previews by using a slightly different step scaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ¯\_(ツ)_/¯ --- src/plugins/ThumbnailGenerator/index.js | 71 ++++++++++++++++--------- 1 file changed, 45 insertions(+), 26 deletions(-) diff --git a/src/plugins/ThumbnailGenerator/index.js b/src/plugins/ThumbnailGenerator/index.js index eed07fd55..8871d098f 100644 --- a/src/plugins/ThumbnailGenerator/index.js +++ b/src/plugins/ThumbnailGenerator/index.js @@ -63,36 +63,55 @@ module.exports = class ThumbnailGenerator extends Plugin { * Returns a Canvas with the resized image on it. */ resizeImage (image, targetWidth, targetHeight) { - let sourceWidth = image.width - let sourceHeight = image.height + // let sourceWidth = image.width + // let sourceHeight = image.height - if (targetHeight < image.height / 2) { - const steps = Math.floor( - Math.log(image.width / targetWidth) / Math.log(2) - ) - const stepScaled = this.downScaleInSteps(image, steps) - image = stepScaled.image - sourceWidth = stepScaled.sourceWidth - sourceHeight = stepScaled.sourceHeight + // if (targetHeight < image.height / 2) { + // const steps = Math.floor( + // Math.log(image.width / targetWidth) / Math.log(2) + // ) + // const stepScaled = this.downScaleInSteps(image, steps) + // image = stepScaled.image + // sourceWidth = stepScaled.sourceWidth + // sourceHeight = stepScaled.sourceHeight + // } + + var steps = Math.ceil(Math.log2(image.width / targetWidth)) + var sW = targetWidth * Math.pow(2, steps - 1) + var sH = targetHeight * Math.pow(2, steps - 1) + var x = 2 + + while (steps--) { + console.log(sW, sH) + var canvas = document.createElement('canvas') + canvas.width = sW + canvas.height = sH + canvas.getContext('2d').drawImage(image, 0, 0, sW, sH) + image = canvas + + sW = Math.round(sW / x) + sH = Math.round(sH / x) } - const canvas = document.createElement('canvas') - canvas.width = targetWidth - canvas.height = targetHeight + return image - const context = canvas.getContext('2d') - context.drawImage( - image, - 0, - 0, - sourceWidth, - sourceHeight, - 0, - 0, - targetWidth, - targetHeight - ) - return canvas + // const canvas = document.createElement('canvas') + // canvas.width = targetWidth + // canvas.height = targetHeight + + // const context = canvas.getContext('2d') + // context.drawImage( + // image, + // 0, + // 0, + // sourceWidth, + // sourceHeight, + // 0, + // 0, + // targetWidth, + // targetHeight + // ) + // return canvas } /** From 98cca8f98d05ceaeccde550e8afd6492d5ba656e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 11:51:59 +0100 Subject: [PATCH 02/87] transloadit: Add global metadata as `fields` --- src/plugins/Transloadit/index.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 5cbf4a92f..7596f29c6 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -3,14 +3,6 @@ const Plugin = require('../../core/Plugin') const Client = require('./Client') const StatusSocket = require('./Socket') -function defaultGetAssemblyOptions (file, options) { - return { - params: options.params, - signature: options.signature, - fields: options.fields - } -} - /** * Upload files to Transloadit using Tus. */ @@ -37,7 +29,13 @@ module.exports = class Transloadit extends Plugin { signature: null, params: null, fields: {}, - getAssemblyOptions: defaultGetAssemblyOptions, + getAssemblyOptions: (file, options) => ({ + params: options.params, + signature: options.signature, + // Include global metadata as fields by default. + // Works great together with the Form plugin :) + fields: Object.assign({}, this.uppy.getState().meta, options.fields) + }), locale: defaultLocale } From efd03d96bb5529e88748bfd41bb00c3ce87c0ce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 13:02:45 +0100 Subject: [PATCH 03/87] Revert "transloadit: Add global metadata as `fields`" This reverts commit 98cca8f98d05ceaeccde550e8afd6492d5ba656e. --- src/plugins/Transloadit/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 7596f29c6..5cbf4a92f 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -3,6 +3,14 @@ const Plugin = require('../../core/Plugin') const Client = require('./Client') const StatusSocket = require('./Socket') +function defaultGetAssemblyOptions (file, options) { + return { + params: options.params, + signature: options.signature, + fields: options.fields + } +} + /** * Upload files to Transloadit using Tus. */ @@ -29,13 +37,7 @@ module.exports = class Transloadit extends Plugin { signature: null, params: null, fields: {}, - getAssemblyOptions: (file, options) => ({ - params: options.params, - signature: options.signature, - // Include global metadata as fields by default. - // Works great together with the Form plugin :) - fields: Object.assign({}, this.uppy.getState().meta, options.fields) - }), + getAssemblyOptions: defaultGetAssemblyOptions, locale: defaultLocale } From 955f63e30dd299a6cc0d8bf4a323560c210fed1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 13:03:09 +0100 Subject: [PATCH 04/87] transloadit: Pass `fields: true` to add global metadata as fields. --- src/plugins/Transloadit/index.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 5cbf4a92f..54a4f101d 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -87,11 +87,25 @@ module.exports = class Transloadit extends Plugin { getAssemblyOptions (fileIDs) { const options = this.opts + + const normalizeAssemblyOptions = (assemblyOptions) => { + const globalMeta = this.uppy.getState().meta + // Include global metadata as fields. Works great together with the Form plugin :) + if (assemblyOptions.fields === true) { + assemblyOptions.fields = Object.assign({}, globalMeta) + } + if (!assemblyOptions.fields) { + assemblyOptions.fields = {} + } + return assemblyOptions + } + return Promise.all( fileIDs.map((fileID) => { const file = this.uppy.getFile(fileID) const promise = Promise.resolve() .then(() => options.getAssemblyOptions(file, options)) + .then(normalizeAssemblyOptions) return promise.then((assemblyOptions) => { this.validateParams(assemblyOptions.params) From 5537bf4038c468b91e18a32cf7d20142c5cd2c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 14:38:32 +0100 Subject: [PATCH 05/87] core: Consistent addFile rejections --- src/core/Core.js | 88 +++++++++++---------------- src/core/Core.test.js | 10 +-- src/plugins/Transloadit/index.test.js | 2 +- 3 files changed, 42 insertions(+), 58 deletions(-) diff --git a/src/core/Core.js b/src/core/Core.js index 57d34f099..6027f1bee 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -278,10 +278,8 @@ class Uppy { _checkMinNumberOfFiles () { const {minNumberOfFiles} = this.opts.restrictions if (Object.keys(this.getState().files).length < minNumberOfFiles) { - this.info(`${this.i18n('youHaveToAtLeastSelectX', { smart_count: minNumberOfFiles })}`, 'error', 5000) - return false + throw new Error(`${this.i18n('youHaveToAtLeastSelectX', { smart_count: minNumberOfFiles })}`) } - return true } /** @@ -289,7 +287,6 @@ class Uppy { * maxNumberOfFiles and allowedFileTypes. * * @param {object} file object to check - * @return {boolean} * @private */ _checkRestrictions (file) { @@ -297,8 +294,7 @@ class Uppy { if (maxNumberOfFiles) { if (Object.keys(this.getState().files).length + 1 > maxNumberOfFiles) { - this.info(`${this.i18n('youCanOnlyUploadX', { smart_count: maxNumberOfFiles })}`, 'error', 5000) - return false + throw new Error(`${this.i18n('youCanOnlyUploadX', { smart_count: maxNumberOfFiles })}`) } } @@ -310,19 +306,15 @@ class Uppy { if (!isCorrectFileType) { const allowedFileTypesString = allowedFileTypes.join(', ') - this.info(`${this.i18n('youCanOnlyUploadFileTypes')} ${allowedFileTypesString}`, 'error', 5000) - return false + throw new Error(`${this.i18n('youCanOnlyUploadFileTypes')} ${allowedFileTypesString}`) } } if (maxFileSize) { if (file.data.size > maxFileSize) { - this.info(`${this.i18n('exceedsSize')} ${prettyBytes(maxFileSize)}`, 'error', 5000) - return false + throw new Error(`${this.i18n('exceedsSize')} ${prettyBytes(maxFileSize)}`) } } - - return true } /** @@ -333,17 +325,12 @@ class Uppy { * @param {object} file object to add */ addFile (file) { - // Wrap this in a Promise `.then()` handler so errors will reject the Promise - // instead of throwing. - const beforeFileAdded = Promise.resolve() + return Promise.resolve() + // Wrap this in a Promise `.then()` handler so errors will reject the Promise + // instead of throwing. .then(() => this.opts.onBeforeFileAdded(file, this.getState().files)) - - return beforeFileAdded.catch((err) => { - const message = typeof err === 'object' ? err.message : err - this.info(message, 'error', 5000) - return Promise.reject(new Error(`onBeforeFileAdded: ${message}`)) - }).then(() => { - return Utils.getFileType(file).then((fileType) => { + .then(() => Utils.getFileType(file)) + .then((fileType) => { const updatedFiles = Object.assign({}, this.getState().files) let fileName if (file.name) { @@ -382,10 +369,7 @@ class Uppy { preview: file.preview } - const isFileAllowed = this._checkRestrictions(newFile) - if (!isFileAllowed) { - return Promise.reject(new Error('File not allowed')) - } + this._checkRestrictions(newFile) updatedFiles[fileID] = newFile this.setState({files: updatedFiles}) @@ -402,7 +386,11 @@ class Uppy { }, 4) } }) - }) + .catch((err) => { + const message = typeof err === 'object' ? err.message : err + this.info(message, 'error', 5000) + return Promise.reject(typeof err === 'object' ? err : new Error(err)) + }) } removeFile (fileID) { @@ -1090,35 +1078,31 @@ class Uppy { this.log('No uploader type plugins are used', 'warning') } - const isMinNumberOfFilesReached = this._checkMinNumberOfFiles() - if (!isMinNumberOfFilesReached) { - return Promise.reject(new Error('Minimum number of files has not been reached')) - } - - const beforeUpload = Promise.resolve() + return Promise.resolve() .then(() => this.opts.onBeforeUpload(this.getState().files)) + .then(() => this._checkMinNumberOfFiles()) + .then(() => { + const { currentUploads } = this.getState() + // get a list of files that are currently assigned to uploads + const currentlyUploadingFiles = Object.keys(currentUploads).reduce((prev, curr) => prev.concat(currentUploads[curr].fileIDs), []) - return beforeUpload.catch((err) => { - const message = typeof err === 'object' ? err.message : err - this.info(message, 'error', 5000) - return Promise.reject(new Error(`onBeforeUpload: ${message}`)) - }).then(() => { - const { currentUploads } = this.getState() - // get a list of files that are currently assigned to uploads - const currentlyUploadingFiles = Object.keys(currentUploads).reduce((prev, curr) => prev.concat(currentUploads[curr].fileIDs), []) + const waitingFileIDs = [] + Object.keys(this.getState().files).forEach((fileID) => { + const file = this.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)) { + waitingFileIDs.push(file.id) + } + }) - const waitingFileIDs = [] - Object.keys(this.getState().files).forEach((fileID) => { - const file = this.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)) { - waitingFileIDs.push(file.id) - } + const uploadID = this._createUpload(waitingFileIDs) + return this._runUpload(uploadID) + }) + .catch((err) => { + const message = typeof err === 'object' ? err.message : err + this.info(message, 'error', 5000) + return Promise.reject(typeof err === 'object' ? err : new Error(err)) }) - - const uploadID = this._createUpload(waitingFileIDs) - return this._runUpload(uploadID) - }) } } diff --git a/src/core/Core.test.js b/src/core/Core.test.js index 169bfe4f9..bfb534240 100644 --- a/src/core/Core.test.js +++ b/src/core/Core.test.js @@ -610,7 +610,7 @@ describe('src/Core', () => { throw new Error('File was allowed through') }) .catch(e => { - expect(e.message).toEqual('File not allowed') + expect(e.message).toEqual('You can only upload: image/gif') }) }) @@ -625,7 +625,7 @@ describe('src/Core', () => { name: 'foo.jpg', type: 'image/jpeg', data: null - })).rejects.toMatchObject(new Error('onBeforeFileAdded: a plain string')) + })).rejects.toMatchObject(new Error('a plain string')) }) }) @@ -955,7 +955,7 @@ describe('src/Core', () => { name: 'foo2.jpg', type: 'image/jpeg', data: utils.dataURItoFile(sampleImageDataURI, {}) - })).rejects.toMatchObject(new Error('File not allowed')).then(() => { + })).rejects.toMatchObject(new Error('You can only upload 1 file')).then(() => { expect(core.state.info.message).toEqual('You can only upload 1 file') }) }) @@ -975,7 +975,7 @@ describe('src/Core', () => { name: 'foo2.jpg', type: 'image/jpeg', data: utils.dataURItoFile(sampleImageDataURI, {}) - })).rejects.toMatchObject(new Error('File not allowed')).then(() => { + })).rejects.toMatchObject(new Error('You can only upload: image/gif, image/png')).then(() => { expect(core.state.info.message).toEqual('You can only upload: image/gif, image/png') }) }) @@ -993,7 +993,7 @@ describe('src/Core', () => { name: 'foo.jpg', type: 'image/jpeg', data: utils.dataURItoFile(sampleImageDataURI, {}) - })).rejects.toMatchObject(new Error('File not allowed')).then(() => { + })).rejects.toMatchObject(new Error('This file exceeds maximum allowed size of 1.2 KB')).then(() => { expect(core.state.info.message).toEqual('This file exceeds maximum allowed size of 1.2 KB') }) }) diff --git a/src/plugins/Transloadit/index.test.js b/src/plugins/Transloadit/index.test.js index 431bef298..269e75fc6 100644 --- a/src/plugins/Transloadit/index.test.js +++ b/src/plugins/Transloadit/index.test.js @@ -168,6 +168,6 @@ describe('Transloadit', () => { } }) - return expect(uppy.upload()).rejects.toBe('short-circuited') + return expect(uppy.upload()).rejects.toEqual(new Error('short-circuited')) }) }) From 26cafb1afe4e12d095fb5149e7d4cda7cd7c7e2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 14:40:38 +0100 Subject: [PATCH 06/87] core: Prevent unhandled rejection warnings in addFile() --- src/core/Core.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/Core.js b/src/core/Core.js index 6027f1bee..537ac9a38 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -389,7 +389,13 @@ class Uppy { .catch((err) => { const message = typeof err === 'object' ? err.message : err this.info(message, 'error', 5000) - return Promise.reject(typeof err === 'object' ? err : new Error(err)) + const rejected = Promise.reject(typeof err === 'object' ? err : new Error(err)) + // Silence the unhandled rejection; we have already shown it to the user, + // so the consumer may not need to do anything with this result. + // Note that the result is still a rejected Promise, it will just not + // trigger unhandled rejection warnings in the browser console. + rejected.catch(() => {}) + return rejected }) } From 45f0f2d5987e0147a5d4ca6511c2f71f7b8871f7 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Wed, 7 Feb 2018 00:56:58 -0500 Subject: [PATCH 07/87] Add wrapper function for emitter.on that returns uppy instance for easy chaining --- src/core/Core.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/core/Core.js b/src/core/Core.js index 57d34f099..ccbb58146 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -87,7 +87,6 @@ class Uppy { this.upload = this.upload.bind(this) this.emitter = ee() - this.on = this.emitter.on.bind(this.emitter) this.off = this.emitter.off.bind(this.emitter) this.once = this.emitter.once.bind(this.emitter) this.emit = this.emitter.emit.bind(this.emitter) @@ -126,6 +125,11 @@ class Uppy { } } + on (event, callback) { + this.emitter.on(event, callback) + return this + } + /** * Iterate on all plugins and run `update` on them. * Called each time state changes. From 43a1aae5f4bf074529eeefa05746a94d2458b890 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Thu, 8 Feb 2018 21:44:41 +0100 Subject: [PATCH 08/87] transloadit: Accept array of meta field names in `fields` parameter. --- src/plugins/Transloadit/index.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/plugins/Transloadit/index.js b/src/plugins/Transloadit/index.js index 54a4f101d..62ad9e83b 100644 --- a/src/plugins/Transloadit/index.js +++ b/src/plugins/Transloadit/index.js @@ -88,11 +88,13 @@ module.exports = class Transloadit extends Plugin { getAssemblyOptions (fileIDs) { const options = this.opts - const normalizeAssemblyOptions = (assemblyOptions) => { - const globalMeta = this.uppy.getState().meta - // Include global metadata as fields. Works great together with the Form plugin :) - if (assemblyOptions.fields === true) { - assemblyOptions.fields = Object.assign({}, globalMeta) + const normalizeAssemblyOptions = (file, assemblyOptions) => { + if (Array.isArray(assemblyOptions.fields)) { + const fieldNames = assemblyOptions.fields + assemblyOptions.fields = {} + fieldNames.forEach((fieldName) => { + assemblyOptions.fields[fieldName] = file.meta[fieldName] + }) } if (!assemblyOptions.fields) { assemblyOptions.fields = {} @@ -105,7 +107,7 @@ module.exports = class Transloadit extends Plugin { const file = this.uppy.getFile(fileID) const promise = Promise.resolve() .then(() => options.getAssemblyOptions(file, options)) - .then(normalizeAssemblyOptions) + .then((assemblyOptions) => normalizeAssemblyOptions(file, assemblyOptions)) return promise.then((assemblyOptions) => { this.validateParams(assemblyOptions.params) From 4b24537a08ec883afc6868daae7cdf2e338451ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9e=20Kooi?= Date: Mon, 5 Feb 2018 14:58:59 +0100 Subject: [PATCH 09/87] Catch `addFile()` errors in UI plugins Prevents warnings in the console about unhandled rejections. We can safely catch and ignore these errors, because they also show up in the UI already anyway. --- src/core/Core.js | 8 +------- src/plugins/Dashboard/index.js | 6 ++++++ src/plugins/DragDrop/index.js | 4 ++++ src/plugins/Dummy.js | 4 +++- src/plugins/FileInput.js | 2 ++ src/plugins/Provider/view/index.js | 4 +++- src/plugins/Webcam/index.js | 6 ++++-- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/core/Core.js b/src/core/Core.js index 537ac9a38..6027f1bee 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -389,13 +389,7 @@ class Uppy { .catch((err) => { const message = typeof err === 'object' ? err.message : err this.info(message, 'error', 5000) - const rejected = Promise.reject(typeof err === 'object' ? err : new Error(err)) - // Silence the unhandled rejection; we have already shown it to the user, - // so the consumer may not need to do anything with this result. - // Note that the result is still a rejected Promise, it will just not - // trigger unhandled rejection warnings in the browser console. - rejected.catch(() => {}) - return rejected + return Promise.reject(typeof err === 'object' ? err : new Error(err)) }) } diff --git a/src/plugins/Dashboard/index.js b/src/plugins/Dashboard/index.js index 760dce592..c4b84ae5f 100644 --- a/src/plugins/Dashboard/index.js +++ b/src/plugins/Dashboard/index.js @@ -277,6 +277,8 @@ module.exports = class Dashboard extends Plugin { name: file.name, type: file.type, data: blob + }).catch(() => { + // Ignore }) }) } @@ -291,6 +293,8 @@ module.exports = class Dashboard extends Plugin { name: file.name, type: file.type, data: file + }).catch(() => { + // Ignore }) }) } @@ -360,6 +364,8 @@ module.exports = class Dashboard extends Plugin { name: file.name, type: file.type, data: file + }).catch(() => { + // Ignore }) }) } diff --git a/src/plugins/DragDrop/index.js b/src/plugins/DragDrop/index.js index 8b6825e86..d74e97596 100644 --- a/src/plugins/DragDrop/index.js +++ b/src/plugins/DragDrop/index.js @@ -83,6 +83,8 @@ module.exports = class DragDrop extends Plugin { name: file.name, type: file.type, data: file + }).catch(() => { + // Ignore }) }) } @@ -98,6 +100,8 @@ module.exports = class DragDrop extends Plugin { name: file.name, type: file.type, data: file + }).catch(() => { + // Ignore }) }) } diff --git a/src/plugins/Dummy.js b/src/plugins/Dummy.js index 3a1e108fe..bd0d9bbc6 100644 --- a/src/plugins/Dummy.js +++ b/src/plugins/Dummy.js @@ -35,7 +35,9 @@ module.exports = class Dummy extends Plugin { data: blob } this.props.log('Adding fake file blob') - this.props.addFile(file) + this.props.addFile(file).catch(() => { + // Ignore + }) } render (state) { diff --git a/src/plugins/FileInput.js b/src/plugins/FileInput.js index 606cc9846..2ac5eaee3 100644 --- a/src/plugins/FileInput.js +++ b/src/plugins/FileInput.js @@ -51,6 +51,8 @@ module.exports = class FileInput extends Plugin { name: file.name, type: file.type, data: file + }).catch(() => { + // Ignore }) }) } diff --git a/src/plugins/Provider/view/index.js b/src/plugins/Provider/view/index.js index c99c728d4..92117558c 100644 --- a/src/plugins/Provider/view/index.js +++ b/src/plugins/Provider/view/index.js @@ -169,7 +169,9 @@ module.exports = class View { tagFile.preview = this.plugin.getItemThumbnailUrl(file) } this.plugin.uppy.log('Adding remote file') - this.plugin.uppy.addFile(tagFile) + this.plugin.uppy.addFile(tagFile).catch(() => { + // Ignore + }) if (!isCheckbox) { this.donePicking() } diff --git a/src/plugins/Webcam/index.js b/src/plugins/Webcam/index.js index 264223443..e7286b296 100644 --- a/src/plugins/Webcam/index.js +++ b/src/plugins/Webcam/index.js @@ -169,7 +169,7 @@ module.exports = class Webcam extends Plugin { }) return this.getVideo() }) - .then(this.uppy.addFile) + .then((file) => this.uppy.addFile(file)) .then(() => { this.recordingChunks = null this.recorder = null @@ -233,9 +233,11 @@ module.exports = class Webcam extends Plugin { return this.getImage() }).then((tagFile) => { this.captureInProgress = false - this.uppy.addFile(tagFile) const dashboard = this.uppy.getPlugin('Dashboard') if (dashboard) dashboard.hideAllPanels() + return this.uppy.addFile(tagFile).catch(() => { + // Ignore + }) }, (error) => { this.captureInProgress = false throw error From 67bdfe29d2019dcf2576a5c6c758b701898cd142 Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Thu, 8 Feb 2018 23:07:38 -0500 Subject: [PATCH 10/87] add off and bind both --- src/core/Core.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/core/Core.js b/src/core/Core.js index ccbb58146..1e0ef2873 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -87,7 +87,8 @@ class Uppy { this.upload = this.upload.bind(this) this.emitter = ee() - this.off = this.emitter.off.bind(this.emitter) + this.on = this.on.bind(this) + this.off = this.off.bind(this) this.once = this.emitter.once.bind(this.emitter) this.emit = this.emitter.emit.bind(this.emitter) @@ -130,6 +131,11 @@ class Uppy { return this } + off (event, callback) { + this.emitter.off(event, callback) + return this + } + /** * Iterate on all plugins and run `update` on them. * Called each time state changes. From 4b927ff2833cc86b9f9c127e41e0babbe3fe331f Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Fri, 9 Feb 2018 14:42:23 -0500 Subject: [PATCH 11/87] Add Url to Dashboard example --- website/src/examples/dashboard/app.es6 | 5 +++++ website/src/examples/dashboard/app.html | 3 +++ website/themes/uppy/source/css/_page.scss | 1 + 3 files changed, 9 insertions(+) diff --git a/website/src/examples/dashboard/app.es6 b/website/src/examples/dashboard/app.es6 index 72750a497..f1326aedb 100644 --- a/website/src/examples/dashboard/app.es6 +++ b/website/src/examples/dashboard/app.es6 @@ -3,6 +3,7 @@ const Dashboard = require('uppy/lib/plugins/Dashboard') const GoogleDrive = require('uppy/lib/plugins/GoogleDrive') const Dropbox = require('uppy/lib/plugins/Dropbox') const Instagram = require('uppy/lib/plugins/Instagram') +const Url = require('uppy/lib/plugins/Url') const Webcam = require('uppy/lib/plugins/Webcam') const Tus = require('uppy/lib/plugins/Tus') @@ -58,6 +59,10 @@ function uppyInit () { uppy.use(Instagram, { target: Dashboard, host: UPPY_SERVER }) } + if (opts.Url) { + uppy.use(Url, { target: Dashboard, host: UPPY_SERVER }) + } + if (opts.Webcam) { uppy.use(Webcam, { target: Dashboard }) } diff --git a/website/src/examples/dashboard/app.html b/website/src/examples/dashboard/app.html index 810992d59..d532cd64e 100644 --- a/website/src/examples/dashboard/app.html +++ b/website/src/examples/dashboard/app.html @@ -9,6 +9,7 @@ + @@ -27,6 +28,7 @@ GoogleDrive: document.querySelector('#opts-GoogleDrive'), Dropbox: document.querySelector('#opts-Dropbox'), Instagram: document.querySelector('#opts-Instagram'), + Url: document.querySelector('#opts-Url'), autoProceed: document.querySelector('#opts-autoProceed'), restrictions: document.querySelector('#opts-restrictions') } @@ -37,6 +39,7 @@ GoogleDrive: true, Instagram: true, Dropbox: false, + Url: true, autoProceed: false, restrictions: false } diff --git a/website/themes/uppy/source/css/_page.scss b/website/themes/uppy/source/css/_page.scss index 5edcb3c85..3b82530f9 100644 --- a/website/themes/uppy/source/css/_page.scss +++ b/website/themes/uppy/source/css/_page.scss @@ -259,6 +259,7 @@ p { font-weight: 600; + line-height: 1.45; margin-left: 0; } } From af5d5444883305af6558236c60e307ed14712b5d Mon Sep 17 00:00:00 2001 From: Artur Paikin Date: Fri, 9 Feb 2018 14:42:52 -0500 Subject: [PATCH 12/87] Refactor Url a little, add error handling --- src/plugins/Url/UrlUI.js | 3 +-- src/plugins/Url/index.js | 20 ++++++++++++++++---- src/scss/_url.scss | 1 + 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/plugins/Url/UrlUI.js b/src/plugins/Url/UrlUI.js index bfbc85822..da6065361 100644 --- a/src/plugins/Url/UrlUI.js +++ b/src/plugins/Url/UrlUI.js @@ -20,8 +20,7 @@ class UrlUI extends Component { class="uppy-Url-input" type="text" placeholder={this.props.i18n('enterUrlToImport')} - ref={(input) => { this.input = input }} - value="" /> + ref={(input) => { this.input = input }} /> - + + + ``` 2\. Add CSS to ``: ``` html - + ``` 3\. Initialize: diff --git a/website/src/examples/i18n/app.html b/website/src/examples/i18n/app.html index 667ea8187..7922b483b 100644 --- a/website/src/examples/i18n/app.html +++ b/website/src/examples/i18n/app.html @@ -1,11 +1,11 @@ +https://transloadit.edgly.net/releases/uppy/v0.23.0/dist/uppy.min.css -->
+https://transloadit.edgly.net/releases/uppy/v0.23.0/dist/uppy.min.js --> + +